• 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: Question re AudioUnitRender and AURenderCallback
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question re AudioUnitRender and AURenderCallback


  • Subject: Re: Question re AudioUnitRender and AURenderCallback
  • From: William Stewart <email@hidden>
  • Date: Mon, 30 Oct 2006 12:27:51 -0800


On 28/10/2006, at 6:17 PM, Michael Norris wrote:

(Reposted as smaller message)

Dear list

I'm writing an "external" (a plug-in) for Max/MSP to allow me to process audio with a specified Audio Unit. So far the external loads the AU and initializes it and Max supplies me with audio buffers. I'm just stumped as to how to actually process those buffers with the AU.

Max sends the audio a routine in my external (below), as 2 small buffers of non-interleaved Float 32 data. Ideally, I would like to just process those buffers directly with my Audio Unit using the AudioUnitRender call, have the AU do in-place processing, then send it back out. But AudioUnitRender returns the "not connected" error (-10876) if the Audio Unit isn't part of a graph, or there's no AURenderCallback installed.

I don't need an AUGraph — I just want the one Audio Unit loaded and not connected to any input or output device, as Max handles that. But if I'm right, then using an AURenderCallback means having to manage my own internal state & buffers in a rather cumbersome way. The trouble is that Max supplies me with audio in its own time and expects processed audio in return immediately, but the AU will only send a callback when it's ready, which may not be at the same time as Max. In other words: both Max and the AURenderCallback call different routines in their own time — how do I make them talk to one another?

Thanks, Michael

Below is a snippet of code to give you an idea:

t_int *au2_perform(t_int *w)
{
//This is the routine that Max calls when it has more audio for me to process
char s[256];
t_au *x;
int i,j;
ComponentResult result;
AudioUnitRenderActionFlags actionFlags = 0;
int numFramesToProcess = (int)(w[5]);
x = (t_au*)w[6]; // x is just a pointer to a struct containing my state variables

for ( i = 0; i < kNumChannels; i++) {
x->x_theAudioData->mBuffers[i].mDataByteSize = numFramesToProcess * sizeof(Float32);
}


// Point to the supplied audio buffers
x->x_theAudioData->mBuffers[0].mData = (t_float *)(w[2]); // left- channel buffer of audio (NB: t_float is a Float32)
x->x_theAudioData->mBuffers[1].mData = (t_float *)(w[3]); // right- channel buffer of audio

// In the loop below, AudioUnitRender returns a "not connected" error.
// So what's the easiest, least time-consuming way, to get my AudioUnit to *just process these darned buffers*?
for ( j = 0; j < kNumChannels; j++) {
result = AudioUnitRender (x->x_au, &actionFlags, &(x- >x_myTimeStamp), 0, numFramesToProcess, x->x_theAudioData);
}


	// increment time stamp etc...
}

You basically need to adapt your code above to do as follows:

Register the AURenderCallback.

Call AudioUnitRender with an ABL where the data pointers (the mBuffers [0..n].mData is set to NULL) - this signifies to the AU that it can provide buffers to you.

The AU will ask for input to process by calling your render callback. In that callback the AU will provide pointers to input buffers - replace those pointers with the pointers you have (w[2] and w[3] if I read your code correctly above).

If the AU is able to process in place (there is a property to check for this) it will process your input and the pointers you receive on the output in your ABL will be the pointers you provided for input. If it is not able to process in place, then the AU will hand back pointers to its own internal buffers.

I presume you are processing the audio with an AU effect unit? In that case the input that the AU asks for will be the same amount as the output you are asking the AU to produce - that is, if you ask for 512 sample frames on output, the AU will ask for 512 sample frames of input. You need to make sure that that is what you provide of course (no more and no less)

Bill

 _______________________________________________
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

--
mailto:email@hidden
tel: +1 408 974 4056
________________________________________________________________________ __
"Much human ingenuity has gone into finding the ultimate Before.
The current state of knowledge can be summarized thus:
In the beginning, there was nothing, which exploded" - Terry Pratchett
________________________________________________________________________ __


_______________________________________________
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: 
 >Question re AudioUnitRender and AURenderCallback (From: Michael Norris <email@hidden>)

  • Prev by Date: auval is ignoring my AU plugin
  • Next by Date: Re: AU surround hosts
  • Previous by thread: Question re AudioUnitRender and AURenderCallback
  • Next by thread: Another question re AURenderCallback
  • Index(es):
    • Date
    • Thread