Ok, I am new on iphone, for serval days I have totally confused by the AudioUnit callbacks.
int SetupRemoteIO (AudioUnit& inRemoteIOUnit, AURenderCallbackStruct inRenderProc, AURenderCallbackStruct inRenderProc2, CAStreamBasicDescription& outFormat)
{
try {
// Open the output unit
AudioComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_RemoteIO;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
AudioComponent comp = AudioComponentFindNext(NULL, &desc);
XThrowIfError(AudioComponentInstanceNew(comp, &inRemoteIOUnit), "couldn't open the remote I/O unit");
UInt32 style="color:rgb(47, 48, 211)">1;
XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof(one)), "couldn't enable input on the remote I/O unit");
XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inRenderProc, sizeof(inRenderProc)), "couldn't set remote i/o render callback");
//1: I modify the line above from input to output, and runs, nothing different oberserved, the document says this property is for input scope, seems the api just ignore this argment
XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Output, 0, &inRenderProc, sizeof(inRenderProc)), "couldn't set remote i/o render callback");
//2: I added the 3 lines below, wanting to make kAudioUnitProperty_ShouldAllocateBuffer property clear, but still no difference in callbacks observed.
// In my opinion, maybe the lines could cause the last argument in the callback to be zero, however, I am wrong, I don't know what it is for
UInt32 zero = 0;
XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioUnitProperty_ShouldAllocateBuffer, kAudioUnitScope_Output, 0, &zero, sizeof(zero)), "couldn't set remote i/o render callback");
XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioUnitProperty_ShouldAllocateBuffer, kAudioUnitScope_Input, 0, &zero, sizeof(zero)), "couldn't set remote i/o render callback");
//3: this line is added by me, the inRenderProc2 point to just a copy of the callback in inRenderProc, means, a function (func1) of same logic with the callback in inRenderProc(func2)
// what I observed is: (1) the func1 is called before the func2 (2) the last argument of func1 is always zero, however, is not zero when func2 got called (3), the inBusNumber argument has a value of 1 for func1, 0 for func2
// I am totally get confused for the argument values, what the difference stands?
XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioOutputUnitProperty_SetInputCallback, kAudioUnitScope_Global, 0, &inRenderProc2, sizeof(inRenderProc2)), "couldn't set remote i/o render callback");
// set our required format - Canonical AU format: LPCM non-interleaved 8.24 fixed point
outFormat.SetAUCanonical(2, false);
outFormat.mSampleRate = 44100;
XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &outFormat, sizeof(outFormat)), "couldn't set the remote I/O unit's output client format");
XThrowIfError(AudioUnitSetProperty(inRemoteIOUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &outFormat, sizeof(outFormat)), "couldn't set the remote I/O unit's input client format");
XThrowIfError(AudioUnitInitialize(inRemoteIOUnit), "couldn't initialize the remote I/O unit");
}
catch (CAXException &e) {
char buf[256];
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
return 1;
}
catch (...) {
fprintf(stderr, "An unknown error occurred\n");
return 1;
}
return 0;
}
Can you guys give me a hand for the questions. I do google a lot, but get no answer.