Previous: Setting up the AUGraph.
In the previous two posts, we set up the project and hooked up the audio plumbing. Now we finally get to the actual work. Amazingly, all there’s just one function left to write. The audio render callback is the function you provided earlier to be the input to the mixer AudioUnit. Whenever the Mixer needs new audio input, it calls the render call back and it is up to you to fill a buffer up with audio samples. It is a C function that has this specific set of parameters.
- inRefCon – A pointer to an object that is used to pass in parameters.
- AudioUnitRenderActionFlags – Indicates special states, we won’t need it here.
- AudioTimeStamp – Used if you need to synchronize multiple sources.
- inBusNumber – The specific bus of the Audio Unit that is called the function.
- inNumberFrames – The number of frames of sample data that will be passed in.
- ioData – An AudioBufferList, which is a struct containing an array of buffers representing sample data and a count of those buffers.
Here’s what we’re going to be doing.
- Getting a pointer “THIS” so we can access AudioController variables.
- Getting a pointer to the buffer we want to write to. (here there is only one buffer, it will be at index [0]).
- Performing some preliminary setup for the sine wave.
- Looping through an inNumberFrames length loop, calculating a sine wave and writing sample values to the buffer.
- Saving any AudioController variables that need to be remembered across calls to the render function.



