0

I've got a callback from which I am attempting to capture audio from a remote I/O unit in an audio graph. Inside of my callback I have an AudioBufferList in an AudioUnitRender function that I need to store non-interleaved data from two channels.

Here's a code snippet for context:

//audiounit render function inside of a callback    
OSStatus status;
        status = AudioUnitRender(THIS.ioUnit,    
                                 ioActionFlags,
                                 inTimeStamp,
                                 0,
                                 inNumberFrames,
                                 &bufferList);

//want to initialize and configure bufferList to store non-interleaved data from both channels
...

//write audio data to disk 
    OSStatus result;
        if (*ioActionFlags == kAudioUnitRenderAction_PostRender) {
            result =  ExtAudioFileWriteAsync(THIS.extAudioFileRef, inNumberFrames, &bufferList);
            if(result) printf("ExtAudioFileWriteAsync  %ld \n", result);}
        return noErr; 

Does anyone know how to do this?

Thanks.

Orpheus Mercury
  • 1,617
  • 2
  • 15
  • 30

2 Answers2

2

You should make a float** array and initialize it lazily in your render callback to have the same buffersize as you are passed (reallacating it as necessary). From there you can simply copy to the channel you need and use that data in the other channel (I'm guessing you're making some type of effect which needs to have interaction between the channels).

Unfortunately, this will by necessarily a global variable, but due to the restrictions on AudioUnits in iOS you'll probably just have to live with that.

Nik Reiman
  • 39,067
  • 29
  • 104
  • 160
  • Thank you Nik. +1. I just realized that I'm probably barking up the wrong tree, however. My research has suggested that ExtAudioFileWriteAsync expects 1 buffer of interleaved data if I'm passing it stereo. Maybe you'll be able to help out with a related question: http://stackoverflow.com/questions/10511272/turn-non-interleaved-audio-data-into-interleaved – Orpheus Mercury May 09 '12 at 07:14
  • Yeah, it does. You'll probably need to do a lot of interlacing and de-interlacing in this case. :) – Nik Reiman May 09 '12 at 07:48
  • You can pass a struct of parameters to an Audio Unit callback. No need to use a global if your style guide does not prefer such. – hotpaw2 May 09 '12 at 20:44
  • @hotpaw2 I've not seen that before. How do you do it? – Nik Reiman May 11 '12 at 07:58
  • You want to avoid doing anything in the render callback that can block, including allocating memory. I think the `float **` should be allocated beforehand. – sbooth May 12 '12 at 17:42
0

Your buffer list should be initialized with

myBufferList.mNumberBuffers = 2;

For a working example, check MixerHost example by Apple.

Totoro
  • 3,398
  • 1
  • 24
  • 39