[Cs-dev] Question on ksmps on iOS
Date | 2014-05-11 09:43 |
From | lppier |
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 |
Date | 2014-05-11 10:02 |
From | Victor Lazzarini |
Subject | Re: [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 |
Date | 2014-05-11 12:43 |
From | lppier |
Subject | Re: [Cs-dev] Question on ksmps on iOS |
Attachments | None None |
Ah I think I understand , will give it a try and post back if I get it working, thanks! Sent from my iPhone
View this message in context: Re: Question on ksmps on iOS Sent from the Csound - Dev mailing list archive at Nabble.com. |
Date | 2014-05-13 04:14 |
From | lppier |
Subject | Re: [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 |
Date | 2014-05-13 05:40 |
From | Andres Cabrera |
Subject | Re: [Cs-dev] Question on ksmps on iOS |
Attachments | None None |
Csound can also provide a lock free ring buffer: Which makes me think, should we use an implementation like:http://csound.github.io/docs/api/group__MISCELLANEOUS.html#ga22d06cd479b47eccfe428dbd19b185bb http://svn.drobilla.net/zix/trunk/zix/ring.c Andrés On Mon, May 12, 2014 at 8:14 PM, lppier <madstrum@gmail.com> wrote: Hi, |
Date | 2014-05-13 07:29 |
From | Victor Lazzarini |
Subject | Re: [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 |
Date | 2014-05-13 10:58 |
From | lppier |
Subject | Re: [Cs-dev] Question on ksmps on iOS |
Attachments | None None |
Hi thanks Victor, I was not so sure how spout worked. Pier. On May 13, 2014 2:30 PM, "Victor.Lazzarini [via Csound]" <[hidden email]> wrote:
Two things: View this message in context: Re: Question on ksmps on iOS Sent from the Csound - Dev mailing list archive at Nabble.com. |
Date | 2014-05-13 13:04 |
From | Victor Lazzarini |
Subject | Re: [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 |