简体   繁体   中英

iOS - Recording from RemoteIO AudioUnit

I'm trying to record from remoteIO and here is my callback. I have an issue though... the code never goes into the if (*ioActionFlags == kAudioUnitRenderAction_PostRender)

How do I actually stop the recording such that it goes into kAudioUnitRenderAction_PostRender ? Very new to Core Audio so this may be a dumb question (I have a good feeling it is ;) ) Many thanks.

Pier.

static OSStatus RecordingCallback (
                               void *                           inRefCon,
                               AudioUnitRenderActionFlags * ioActionFlags,
                               const AudioTimeStamp *           inTimeStamp,
                               UInt32                           inBusNumber,
                               UInt32                           inNumberFrames,
                               AudioBufferList *                ioData) {
EffectState *effectState = (EffectState*) inRefCon;

// just copy samples
UInt32 bus1 = 1;
CheckError(AudioUnitRender(effectState->rioUnit,
                            ioActionFlags,
                            inTimeStamp,
                            bus1,
                            inNumberFrames,
                            ioData),
           "Couldn't render from RemoteIO unit");

if (*ioActionFlags == kAudioUnitRenderAction_PostRender)
{
    OSStatus result = ExtAudioFileWriteAsync(effectState->outputFile,inNumberFrames,ioData);
    if(result) printf("ExtAudioFileWriteAsync %ld \n", result);
}
return noErr;
}

There's a couple issues here.

First, you're probably intending to check if kAudioUnitRenderAction_PostRender is set, right? In that case, you should use *ioActionFlags & kAudioUnitRenderAction_PostRender instead of *ioActionFlags == kAudioUnitRenderAction_PostRender . The former will check if the flag is set, whereas what you're doing is checking if ONLY that flag is set (ie if the kAudioUnitRenderAction_OutputIsSilence flag is also set, then *ioActionFlags == kAudioUnitRenderAction_PostRender would be false ).

That said, I don't believe you need to be checking that flag at all in this case. The description for that flag reads:

Called on a render notification Proc - which is called either before or after the render operation of the audio unit. If this flag is set, the proc is being called after the render operation is completed.

Which makes it sound like that flag is only used in a AUGraph render notification, to indicate whether the callback is happening before or after a render has completed (not relevant to you, since it looks like you're getting callbacks from a RemoteIO).

So basically, you don't need to check for that flag in your case. You should check to see if your AudioUnitRender call returned noErr , though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM