Csound Csound-dev Csound-tekno Search About

[Cs-dev] Question on ksmps on iOS

Date2014-05-11 09:43
Fromlppier
Subject[Cs-dev] Question on ksmps on iOS
Hi, 

The following is the Csound_rendering code in iOS. 
I have a question : no audio is rendered when inNumberFrames = 64 (I'm
required to provide this number of frames for inter-app audio integration
with a DAW app) 

    int slices = inNumberFrames/csoundGetKsmps(cs);   // if inNumberFrames
== 64, ksmps==128, doesn't go into rendering loops

My ksmps is 128. Putting it at 64 would solve the issue for me. 
However, my app stutters sometimes at 64 ksmps. 

What are my options here? Is there any way I can still use ksmps==128 and
yet satisfy the incoming frames requirement of 64? 

Thank you. 

Pier. 

OSStatus  Csound_Render(void *inRefCon,
                        AudioUnitRenderActionFlags *ioActionFlags,
                        const AudioTimeStamp *inTimeStamp,
                        UInt32 dump,
                        UInt32 inNumberFrames,
                        AudioBufferList *ioData)
{
    csdata *cdata = (csdata *) inRefCon;
    int ret = cdata->ret, nchnls = cdata->nchnls;
    float coef = (float) INT_MAX / csoundGet0dBFS(cdata->cs);
    CSOUND *cs = cdata->cs;
    
    int i,j,k;
    int slices = inNumberFrames/csoundGetKsmps(cs);
    int ksmps = csoundGetKsmps(cs);
    MYFLT *spin = csoundGetSpin(cs);
    MYFLT *spout = csoundGetSpout(cs);
    AudioUnitSampleType *buffer;
    
    AudioUnitRender(*cdata->aunit, ioActionFlags, inTimeStamp, 1,
inNumberFrames, ioData);
    
    NSMutableArray* cache = cdata->valuesCache;
    
    for(i=0; i < slices; i++){

		for (int i = 0; i < cache.count; i++) {
			id cachedValue = [cache objectAtIndex:i];
			[cachedValue updateValuesToCsound];
		}
        
		/* performance */
        if(cdata->useAudioInput) {
            for (k = 0; k < nchnls; k++){
                buffer = (AudioUnitSampleType *) ioData->mBuffers[k].mData;
                for(j=0; j < ksmps; j++){
                    spin[j*nchnls+k] =(1./coef)*buffer[j+i*ksmps];
                }
            }
        }
        if(!ret) {
            ret = csoundPerformKsmps(cs);
        } else {
            cdata->running = false;
        }

		for (k = 0; k < nchnls; k++) {
			buffer = (AudioUnitSampleType *) ioData->mBuffers[k].mData;
			if (cdata->shouldMute == false) {
				for(j=0; j < ksmps; j++){
					buffer[j+i*ksmps] = (AudioUnitSampleType)
lrintf(spout[j*nchnls+k]*coef) ;
				}
			} else {
				memset(buffer, 0, sizeof(AudioUnitSampleType) * inNumberFrames);
			}
		}
        

		for (int i = 0; i < cache.count; i++) {
			id cachedValue = [cache objectAtIndex:i];
			[cachedValue updateValuesFromCsound];
		}

    }

	// Write to file.
	if (cdata->shouldRecord) {
		OSStatus err = ExtAudioFileWriteAsync(cdata->file, inNumberFrames,
ioData);
		if (err != noErr) {
			printf("***Error writing to file: %d\n", (int)err);
		}
	}
    
    cdata->ret = ret;
    return 0;
}




--
View this message in context: http://csound.1045644.n5.nabble.com/Question-on-ksmps-on-iOS-tp5735112.html
Sent from the Csound - Dev mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
• 3 signs your SCM is hindering your productivity
• Requirements for releasing software faster
• Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2014-05-11 10:02
FromVictor Lazzarini
SubjectRe: [Cs-dev] Question on ksmps on iOS
It’s possible. You would need to modify the code to buffer the input until spin is full and then
process the audio; the same thing goes to the output, you would need to move
1/2 buffer out every time the callback is run.  You could make that code
a case for when slices < 1.

Of course, it would impose an extra 64 frames of latency between in and out, but that’s
expected since you are processing 128 at a time.
========================
Dr Victor Lazzarini
Senior Lecturer
NUI Maynooth, Ireland
victor dot lazzarini at nuim dot ie




On 11 May 2014, at 09:43, lppier  wrote:

> Hi, 
> 
> The following is the Csound_rendering code in iOS. 
> I have a question : no audio is rendered when inNumberFrames = 64 (I'm
> required to provide this number of frames for inter-app audio integration
> with a DAW app) 
> 
>    int slices = inNumberFrames/csoundGetKsmps(cs);   // if inNumberFrames
> == 64, ksmps==128, doesn't go into rendering loops
> 
> My ksmps is 128. Putting it at 64 would solve the issue for me. 
> However, my app stutters sometimes at 64 ksmps. 
> 
> What are my options here? Is there any way I can still use ksmps==128 and
> yet satisfy the incoming frames requirement of 64? 
> 
> Thank you. 
> 
> Pier. 
> 
> OSStatus  Csound_Render(void *inRefCon,
>                        AudioUnitRenderActionFlags *ioActionFlags,
>                        const AudioTimeStamp *inTimeStamp,
>                        UInt32 dump,
>                        UInt32 inNumberFrames,
>                        AudioBufferList *ioData)
> {
>    csdata *cdata = (csdata *) inRefCon;
>    int ret = cdata->ret, nchnls = cdata->nchnls;
>    float coef = (float) INT_MAX / csoundGet0dBFS(cdata->cs);
>    CSOUND *cs = cdata->cs;
> 
>    int i,j,k;
>    int slices = inNumberFrames/csoundGetKsmps(cs);
>    int ksmps = csoundGetKsmps(cs);
>    MYFLT *spin = csoundGetSpin(cs);
>    MYFLT *spout = csoundGetSpout(cs);
>    AudioUnitSampleType *buffer;
> 
>    AudioUnitRender(*cdata->aunit, ioActionFlags, inTimeStamp, 1,
> inNumberFrames, ioData);
> 
>    NSMutableArray* cache = cdata->valuesCache;
> 
>    for(i=0; i < slices; i++){
> 
> 		for (int i = 0; i < cache.count; i++) {
> 			id cachedValue = [cache objectAtIndex:i];
> 			[cachedValue updateValuesToCsound];
> 		}
> 
> 		/* performance */
>        if(cdata->useAudioInput) {
>            for (k = 0; k < nchnls; k++){
>                buffer = (AudioUnitSampleType *) ioData->mBuffers[k].mData;
>                for(j=0; j < ksmps; j++){
>                    spin[j*nchnls+k] =(1./coef)*buffer[j+i*ksmps];
>                }
>            }
>        }
>        if(!ret) {
>            ret = csoundPerformKsmps(cs);
>        } else {
>            cdata->running = false;
>        }
> 
> 		for (k = 0; k < nchnls; k++) {
> 			buffer = (AudioUnitSampleType *) ioData->mBuffers[k].mData;
> 			if (cdata->shouldMute == false) {
> 				for(j=0; j < ksmps; j++){
> 					buffer[j+i*ksmps] = (AudioUnitSampleType)
> lrintf(spout[j*nchnls+k]*coef) ;
> 				}
> 			} else {
> 				memset(buffer, 0, sizeof(AudioUnitSampleType) * inNumberFrames);
> 			}
> 		}
> 
> 
> 		for (int i = 0; i < cache.count; i++) {
> 			id cachedValue = [cache objectAtIndex:i];
> 			[cachedValue updateValuesFromCsound];
> 		}
> 
>    }
> 
> 	// Write to file.
> 	if (cdata->shouldRecord) {
> 		OSStatus err = ExtAudioFileWriteAsync(cdata->file, inNumberFrames,
> ioData);
> 		if (err != noErr) {
> 			printf("***Error writing to file: %d\n", (int)err);
> 		}
> 	}
> 
>    cdata->ret = ret;
>    return 0;
> }
> 
> 
> 
> 
> --
> View this message in context: http://csound.1045644.n5.nabble.com/Question-on-ksmps-on-iOS-tp5735112.html
> Sent from the Csound - Dev mailing list archive at Nabble.com.
> 
> ------------------------------------------------------------------------------
> Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
> • 3 signs your SCM is hindering your productivity
> • Requirements for releasing software faster
> • Expert tips and advice for migrating your SCM now
> http://p.sf.net/sfu/perforce
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel


------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
• 3 signs your SCM is hindering your productivity
• Requirements for releasing software faster
• Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2014-05-11 12:43
Fromlppier
SubjectRe: [Cs-dev] Question on ksmps on iOS
AttachmentsNone  None  
Ah I think I understand , will give it a try and post back if I get it working, thanks!

Sent from my iPhone

On 11 May, 2014, at 5:03 pm, "Victor Lazzarini [via Csound]" <[hidden email]> wrote:

It’s possible. You would need to modify the code to buffer the input until spin is full and then
process the audio; the same thing goes to the output, you would need to move
1/2 buffer out every time the callback is run.  You could make that code
a case for when slices < 1.

Of course, it would impose an extra 64 frames of latency between in and out, but that’s
expected since you are processing 128 at a time.
========================
Dr Victor Lazzarini
Senior Lecturer
NUI Maynooth, Ireland
victor dot lazzarini at nuim dot ie




On 11 May 2014, at 09:43, lppier <[hidden email]> wrote:

> Hi,
>
> The following is the Csound_rendering code in iOS.
> I have a question : no audio is rendered when inNumberFrames = 64 (I'm
> required to provide this number of frames for inter-app audio integration
> with a DAW app)
>
>    int slices = inNumberFrames/csoundGetKsmps(cs);   // if inNumberFrames
> == 64, ksmps==128, doesn't go into rendering loops
>
> My ksmps is 128. Putting it at 64 would solve the issue for me.
> However, my app stutters sometimes at 64 ksmps.
>
> What are my options here? Is there any way I can still use ksmps==128 and
> yet satisfy the incoming frames requirement of 64?
>
> Thank you.
>
> Pier.
>
> OSStatus  Csound_Render(void *inRefCon,
>                        AudioUnitRenderActionFlags *ioActionFlags,
>                        const AudioTimeStamp *inTimeStamp,
>                        UInt32 dump,
>                        UInt32 inNumberFrames,
>                        AudioBufferList *ioData)
> {
>    csdata *cdata = (csdata *) inRefCon;
>    int ret = cdata->ret, nchnls = cdata->nchnls;
>    float coef = (float) INT_MAX / csoundGet0dBFS(cdata->cs);
>    CSOUND *cs = cdata->cs;
>
>    int i,j,k;
>    int slices = inNumberFrames/csoundGetKsmps(cs);
>    int ksmps = csoundGetKsmps(cs);
>    MYFLT *spin = csoundGetSpin(cs);
>    MYFLT *spout = csoundGetSpout(cs);
>    AudioUnitSampleType *buffer;
>
>    AudioUnitRender(*cdata->aunit, ioActionFlags, inTimeStamp, 1,
> inNumberFrames, ioData);
>
>    NSMutableArray* cache = cdata->valuesCache;
>
>    for(i=0; i < slices; i++){
>
> for (int i = 0; i < cache.count; i++) {
> id<CsoundValueCacheable> cachedValue = [cache objectAtIndex:i];
> [cachedValue updateValuesToCsound];
> }
>
> /* performance */
>        if(cdata->useAudioInput) {
>            for (k = 0; k < nchnls; k++){
>                buffer = (AudioUnitSampleType *) ioData->mBuffers[k].mData;
>                for(j=0; j < ksmps; j++){
>                    spin[j*nchnls+k] =(1./coef)*buffer[j+i*ksmps];
>                }
>            }
>        }
>        if(!ret) {
>            ret = csoundPerformKsmps(cs);
>        } else {
>            cdata->running = false;
>        }
>
> for (k = 0; k < nchnls; k++) {
> buffer = (AudioUnitSampleType *) ioData->mBuffers[k].mData;
> if (cdata->shouldMute == false) {
> for(j=0; j < ksmps; j++){
> buffer[j+i*ksmps] = (AudioUnitSampleType)
> lrintf(spout[j*nchnls+k]*coef) ;
> }
> } else {
> memset(buffer, 0, sizeof(AudioUnitSampleType) * inNumberFrames);
> }
> }
>
>
> for (int i = 0; i < cache.count; i++) {
> id<CsoundValueCacheable> cachedValue = [cache objectAtIndex:i];
> [cachedValue updateValuesFromCsound];
> }
>
>    }
>
> // Write to file.
> if (cdata->shouldRecord) {
> OSStatus err = ExtAudioFileWriteAsync(cdata->file, inNumberFrames,
> ioData);
> if (err != noErr) {
> printf("***Error writing to file: %d\n", (int)err);
> }
> }
>
>    cdata->ret = ret;
>    return 0;
> }
>
>
>
>
> --
> View this message in context: http://csound.1045644.n5.nabble.com/Question-on-ksmps-on-iOS-tp5735112.html
> Sent from the Csound - Dev mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
> &#149; 3 signs your SCM is hindering your productivity
> &#149; Requirements for releasing software faster
> &#149; Expert tips and advice for migrating your SCM now
> http://p.sf.net/sfu/perforce
> _______________________________________________
> Csound-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/csound-devel

------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Csound-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/csound-devel



If you reply to this email, your message will be added to the discussion below:
http://csound.1045644.n5.nabble.com/Question-on-ksmps-on-iOS-tp5735112p5735113.html
To unsubscribe from Question on ksmps on iOS, click here.
NAML


View this message in context: Re: Question on ksmps on iOS
Sent from the Csound - Dev mailing list archive at Nabble.com.

Date2014-05-13 04:14
Fromlppier
SubjectRe: [Cs-dev] Question on ksmps on iOS
Hi, 

I solved it, here's the code in case anyone else hits this issue. I used a
circular buffer TPCircularBuffer from Amazing Audio Engine. 

        if (frames==64) {
            
                for (int i = 0; i < cache.count; i++) {
                    id cachedValue = [cache
objectAtIndex:i];
                    [cachedValue updateValuesToCsound];
                }
                
                if(!ret) {
                    if (TPCircularBufferTail(&framebuffer,
&availableBytes)==NULL) {
                        ret = csoundPerformKsmps(cs);
                       
TPCircularBufferProduceBytes(&framebuffer,spout,(ksmps*2)*sizeof(float));
                   }
                } else {
                    cdata->running = false;
                    cdata->play = false;
                }
                
            
                float* newspout;
                newspout = TPCircularBufferTail(&framebuffer,
&availableBytes);
            
                for (k = 0; k < nchnls; k++) {
                    buffer = (float *) audio->mBuffers[k].mData;
                    if (cdata->shouldMute == false) {
                        for(j=0; j < frames; j++){

                            if (newspout==NULL) {
                                NSLog(@"NULL!");
                            }
                            buffer[j] = (float)(newspout[j*nchnls+k]);
                        }
                    } else {
                        memset(buffer, 0, sizeof(float) * frames);
                    }
                }
                TPCircularBufferConsume(&framebuffer,
frames*2*sizeof(float));
        }
       else { //... normal csound render processing
       




        }




--
View this message in context: http://csound.1045644.n5.nabble.com/Question-on-ksmps-on-iOS-tp5735112p5735194.html
Sent from the Csound - Dev mailing list archive at Nabble.com.

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2014-05-13 05:40
FromAndres Cabrera
SubjectRe: [Cs-dev] Question on ksmps on iOS
AttachmentsNone  None  
Which makes me think, should we use an implementation like:
http://svn.drobilla.net/zix/trunk/zix/ring.c


Cheers,
Andrés


On Mon, May 12, 2014 at 8:14 PM, lppier <madstrum@gmail.com> wrote:
Hi,

I solved it, here's the code in case anyone else hits this issue. I used a
circular buffer TPCircularBuffer from Amazing Audio Engine.

        if (frames==64) {

                for (int i = 0; i < cache.count; i++) {
                    id<CsoundValueCacheable> cachedValue = [cache
objectAtIndex:i];
                    [cachedValue updateValuesToCsound];
                }

                if(!ret) {
                    if (TPCircularBufferTail(&framebuffer,
&availableBytes)==NULL) {
                        ret = csoundPerformKsmps(cs);

TPCircularBufferProduceBytes(&framebuffer,spout,(ksmps*2)*sizeof(float));
                   }
                } else {
                    cdata->running = false;
                    cdata->play = false;
                }


                float* newspout;
                newspout = TPCircularBufferTail(&framebuffer,
&availableBytes);

                for (k = 0; k < nchnls; k++) {
                    buffer = (float *) audio->mBuffers[k].mData;
                    if (cdata->shouldMute == false) {
                        for(j=0; j < frames; j++){

                            if (newspout==NULL) {
                                NSLog(@"NULL!");
                            }
                            buffer[j] = (float)(newspout[j*nchnls+k]);
                        }
                    } else {
                        memset(buffer, 0, sizeof(float) * frames);
                    }
                }
                TPCircularBufferConsume(&framebuffer,
frames*2*sizeof(float));
        }
       else { //... normal csound render processing





        }




--
View this message in context: http://csound.1045644.n5.nabble.com/Question-on-ksmps-on-iOS-tp5735112p5735194.html
Sent from the Csound - Dev mailing list archive at Nabble.com.

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/csound-devel


Date2014-05-13 07:29
FromVictor Lazzarini
SubjectRe: [Cs-dev] Question on ksmps on iOS
Two things:

1) I think you should check for slice size not for framesize (that way you make it relate to ksmps)

2) I am not sure you need to add an extra layer of buffering, with the circular buffer. You
can use spin and spout directly. Say in the case frames=64 and ksmps=128, then
you fill each half of spin at a time and when it's full you call csoundPerformKsmps(). Then
you empty each half of spout at a time too. All you need to do this is a single variable to
keep track of where in spin/spout you need to start writing/reading (1st or 2nd half).

This way you eliminate the overhead of creating the circular buffer. Normally you
only need these things if you want to communicate between threads, which is not the
case here.

Victor
On 13 May 2014, at 04:14, lppier wrote:

> Hi, 
> 
> I solved it, here's the code in case anyone else hits this issue. I used a
> circular buffer TPCircularBuffer from Amazing Audio Engine. 
> 
>        if (frames==64) {
> 
>                for (int i = 0; i < cache.count; i++) {
>                    id cachedValue = [cache
> objectAtIndex:i];
>                    [cachedValue updateValuesToCsound];
>                }
> 
>                if(!ret) {
>                    if (TPCircularBufferTail(&framebuffer,
> &availableBytes)==NULL) {
>                        ret = csoundPerformKsmps(cs);
> 
> TPCircularBufferProduceBytes(&framebuffer,spout,(ksmps*2)*sizeof(float));
>                   }
>                } else {
>                    cdata->running = false;
>                    cdata->play = false;
>                }
> 
> 
>                float* newspout;
>                newspout = TPCircularBufferTail(&framebuffer,
> &availableBytes);
> 
>                for (k = 0; k < nchnls; k++) {
>                    buffer = (float *) audio->mBuffers[k].mData;
>                    if (cdata->shouldMute == false) {
>                        for(j=0; j < frames; j++){
> 
>                            if (newspout==NULL) {
>                                NSLog(@"NULL!");
>                            }
>                            buffer[j] = (float)(newspout[j*nchnls+k]);
>                        }
>                    } else {
>                        memset(buffer, 0, sizeof(float) * frames);
>                    }
>                }
>                TPCircularBufferConsume(&framebuffer,
> frames*2*sizeof(float));
>        }
>       else { //... normal csound render processing
> 
> 
> 
> 
> 
>        }
> 
> 
> 
> 
> --
> View this message in context: http://csound.1045644.n5.nabble.com/Question-on-ksmps-on-iOS-tp5735112p5735194.html
> Sent from the Csound - Dev mailing list archive at Nabble.com.
> 
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel

Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: +353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2014-05-13 10:58
Fromlppier
SubjectRe: [Cs-dev] Question on ksmps on iOS
AttachmentsNone  None  

Hi thanks Victor,

I was not so sure how spout worked.
Is it refreshed only when you call  csoundPerformKsmps? Say if I call
csoundPerformKsmps and then retrieve half of spout, and I call csoundPerformKsmps again in the next callback, is the other old half that I didn't retrieve still in spout?

Pier.

On May 13, 2014 2:30 PM, "Victor.Lazzarini [via Csound]" <[hidden email]> wrote:
Two things:

1) I think you should check for slice size not for framesize (that way you make it relate to ksmps)

2) I am not sure you need to add an extra layer of buffering, with the circular buffer. You
can use spin and spout directly. Say in the case frames=64 and ksmps=128, then
you fill each half of spin at a time and when it's full you call csoundPerformKsmps(). Then
you empty each half of spout at a time too. All you need to do this is a single variable to
keep track of where in spin/spout you need to start writing/reading (1st or 2nd half).

This way you eliminate the overhead of creating the circular buffer. Normally you
only need these things if you want to communicate between threads, which is not the
case here.

Victor
On 13 May 2014, at 04:14, lppier wrote:

> Hi,
>
> I solved it, here's the code in case anyone else hits this issue. I used a
> circular buffer TPCircularBuffer from Amazing Audio Engine.
>
>        if (frames==64) {
>
>                for (int i = 0; i < cache.count; i++) {
>                    id<CsoundValueCacheable> cachedValue = [cache
> objectAtIndex:i];
>                    [cachedValue updateValuesToCsound];
>                }
>
>                if(!ret) {
>                    if (TPCircularBufferTail(&framebuffer,
> &availableBytes)==NULL) {
>                        ret = csoundPerformKsmps(cs);
>
> TPCircularBufferProduceBytes(&framebuffer,spout,(ksmps*2)*sizeof(float));
>                   }
>                } else {
>                    cdata->running = false;
>                    cdata->play = false;
>                }
>
>
>                float* newspout;
>                newspout = TPCircularBufferTail(&framebuffer,
> &availableBytes);
>
>                for (k = 0; k < nchnls; k++) {
>                    buffer = (float *) audio->mBuffers[k].mData;
>                    if (cdata->shouldMute == false) {
>                        for(j=0; j < frames; j++){
>
>                            if (newspout==NULL) {
>                                NSLog(@"NULL!");
>                            }
>                            buffer[j] = (float)(newspout[j*nchnls+k]);
>                        }
>                    } else {
>                        memset(buffer, 0, sizeof(float) * frames);
>                    }
>                }
>                TPCircularBufferConsume(&framebuffer,
> frames*2*sizeof(float));
>        }
>       else { //... normal csound render processing
>
>
>
>
>
>        }
>
>
>
>
> --
> View this message in context: http://csound.1045644.n5.nabble.com/Question-on-ksmps-on-iOS-tp5735112p5735194.html
> Sent from the Csound - Dev mailing list archive at Nabble.com.

>
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________
> Csound-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/csound-devel
Dr Victor Lazzarini
Senior Lecturer
Dept. of Music
NUI Maynooth Ireland
tel.: <a href="tel:%2B353%201%20708%203545" value="+35317083545" target="_blank">+353 1 708 3545
Victor dot Lazzarini AT nuim dot ie




------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Csound-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/csound-devel



If you reply to this email, your message will be added to the discussion below:
http://csound.1045644.n5.nabble.com/Question-on-ksmps-on-iOS-tp5735112p5735197.html
To unsubscribe from Question on ksmps on iOS, click here.
NAML


View this message in context: Re: Question on ksmps on iOS
Sent from the Csound - Dev mailing list archive at Nabble.com.

Date2014-05-13 13:04
FromVictor Lazzarini
SubjectRe: [Cs-dev] Question on ksmps on iOS
That should work, but careful with the reading order:

first callback call:

1. read spin => 1st half
2. don’t call processKsmps()
3. write spout => 2nd half

second call:

1. read spin => 2nd half
2. call processKsmps()
3. write spout => 1st half


========================
Dr Victor Lazzarini
Senior Lecturer
NUI Maynooth, Ireland
victor dot lazzarini at nuim dot ie




On 13 May 2014, at 10:58, lppier  wrote:

> Hi thanks Victor,
> 
> I was not so sure how spout worked. 
> Is it refreshed only when you call  csoundPerformKsmps? Say if I call 
> csoundPerformKsmps and then retrieve half of spout, and I call csoundPerformKsmps again in the next callback, is the other old half that I didn't retrieve still in spout?
> 
> Pier.
> 
> On May 13, 2014 2:30 PM, "Victor.Lazzarini [via Csound]" <[hidden email]> wrote:
> Two things: 
> 
> 1) I think you should check for slice size not for framesize (that way you make it relate to ksmps) 
> 
> 2) I am not sure you need to add an extra layer of buffering, with the circular buffer. You 
> can use spin and spout directly. Say in the case frames=64 and ksmps=128, then 
> you fill each half of spin at a time and when it's full you call csoundPerformKsmps(). Then 
> you empty each half of spout at a time too. All you need to do this is a single variable to 
> keep track of where in spin/spout you need to start writing/reading (1st or 2nd half). 
> 
> This way you eliminate the overhead of creating the circular buffer. Normally you 
> only need these things if you want to communicate between threads, which is not the 
> case here. 
> 
> Victor 
> On 13 May 2014, at 04:14, lppier wrote: 
> 
> > Hi, 
> > 
> > I solved it, here's the code in case anyone else hits this issue. I used a 
> > circular buffer TPCircularBuffer from Amazing Audio Engine. 
> > 
> >        if (frames==64) { 
> > 
> >                for (int i = 0; i < cache.count; i++) { 
> >                    id cachedValue = [cache 
> > objectAtIndex:i]; 
> >                    [cachedValue updateValuesToCsound]; 
> >                } 
> > 
> >                if(!ret) { 
> >                    if (TPCircularBufferTail(&framebuffer, 
> > &availableBytes)==NULL) { 
> >                        ret = csoundPerformKsmps(cs); 
> > 
> > TPCircularBufferProduceBytes(&framebuffer,spout,(ksmps*2)*sizeof(float)); 
> >                   } 
> >                } else { 
> >                    cdata->running = false; 
> >                    cdata->play = false; 
> >                } 
> > 
> > 
> >                float* newspout; 
> >                newspout = TPCircularBufferTail(&framebuffer, 
> > &availableBytes); 
> > 
> >                for (k = 0; k < nchnls; k++) { 
> >                    buffer = (float *) audio->mBuffers[k].mData; 
> >                    if (cdata->shouldMute == false) { 
> >                        for(j=0; j < frames; j++){ 
> > 
> >                            if (newspout==NULL) { 
> >                                NSLog(@"NULL!"); 
> >                            } 
> >                            buffer[j] = (float)(newspout[j*nchnls+k]); 
> >                        } 
> >                    } else { 
> >                        memset(buffer, 0, sizeof(float) * frames); 
> >                    } 
> >                } 
> >                TPCircularBufferConsume(&framebuffer, 
> > frames*2*sizeof(float)); 
> >        } 
> >       else { //... normal csound render processing 
> > 
> > 
> > 
> > 
> > 
> >        } 
> > 
> > 
> > 
> > 
> > -- 
> > View this message in context: http://csound.1045644.n5.nabble.com/Question-on-ksmps-on-iOS-tp5735112p5735194.html
> > Sent from the Csound - Dev mailing list archive at Nabble.com.
> 
> > 
> > ------------------------------------------------------------------------------ 
> > "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE 
> > Instantly run your Selenium tests across 300+ browser/OS combos. 
> > Get unparalleled scalability from the best Selenium testing platform available 
> > Simple to use. Nothing to install. Get started now for free." 
> > http://p.sf.net/sfu/SauceLabs
> > _______________________________________________ 
> > Csound-devel mailing list 
> > [hidden email] 
> > https://lists.sourceforge.net/lists/listinfo/csound-devel
> Dr Victor Lazzarini 
> Senior Lecturer 
> Dept. of Music 
> NUI Maynooth Ireland 
> tel.: +353 1 708 3545 
> Victor dot Lazzarini AT nuim dot ie 
> 
> 
> 
> 
> ------------------------------------------------------------------------------ 
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE 
> Instantly run your Selenium tests across 300+ browser/OS combos. 
> Get unparalleled scalability from the best Selenium testing platform available 
> Simple to use. Nothing to install. Get started now for free." 
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________ 
> Csound-devel mailing list 
> [hidden email] 
> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://csound.1045644.n5.nabble.com/Question-on-ksmps-on-iOS-tp5735112p5735197.html
> To unsubscribe from Question on ksmps on iOS, click here.
> NAML
> 
> View this message in context: Re: Question on ksmps on iOS
> Sent from the Csound - Dev mailing list archive at Nabble.com.
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs_______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net