• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: about audio unit callbacks, I am totally confused
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: about audio unit callbacks, I am totally confused


  • Subject: Re: about audio unit callbacks, I am totally confused
  • From: Antonio De Blasi <email@hidden>
  • Date: Fri, 13 May 2011 11:53:51 +0200

Take a look at the tutorial here:  
http://www.slideshare.net/invalidname/core-audio-dont-be-afraid-to-play-it-loud-360idev-san-jose-2010

This helped me to clarify many issues about AudioUnits and specifically about buses, scopes ad callbacks.
Hope it will help you too

Toni

2011/5/13 赵宇龙 <email@hidden>
Hi, all


Ok, I am new on iphone, for serval  days I have totally confused by the AudioUnit callbacks.

The document says: 

Awrite-onlyAURenderCallbackStruct(page13)datastructurevalidontheaudiounitinput scope.
Set this property to specify your callback function that provides audio samples to an audio unit. When you call the AudioUnitSetProperty function from your application to assign the callback, you specify the input bus that the callback applies to. See the AURenderCallback callback function. 

and I saw the code in the apples examples aurioTouch:

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;
}

And last, I observed the callbacks always failed first time in func1, even no modification is performed by me.

Can you guys give me a hand for the questions. I do google a lot, but get no answer.
Thanks a lot

Zhao Yulong


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >about audio unit callbacks, I am totally confused (From: 赵宇龙 <email@hidden>)

  • Prev by Date: about audio unit callbacks, I am totally confused
  • Next by Date: Re: audioqueue change sample rate
  • Previous by thread: about audio unit callbacks, I am totally confused
  • Next by thread: Question about AudioUnit parameter listeners
  • Index(es):
    • Date
    • Thread