Technical Q&A QA1695

Audio panning with the 3D Mixer audio unit

Q:  How do I implement audio panning with the 3D Mixer on iPhone OS devices?

A: How do I implement audio panning with the 3D Mixer on iPhone OS devices?

The 3D Mixer audio unit, of subtype kAudioUnitSubType_AU3DMixerEmbedded, allows you to mix multiple mono audio streams and specify stereo output panning. You can change the spatial location of each input source by varying its azimuth (angle) and distance relative to the listener, using the k3DMixerParam_Azimuth and k3DMixerParam_Distance audio unit parameters.

The 3D Mixer audio unit only supports mono LPCM input streams. In other words, it can only accept single-channel input streams. To use a stereo source, you may treat its left and right channels as two independent single-channel sources, and then feed each side of the stereo stream to its own input bus. You should setup a mono stream format for each input bus of the 3D Mixer audio unit.

Make sure you set a non-zero positive distance value, for example 1.0, so that changes to azimuth of the audio unit take effect. The following describes in detail how to do this using the k3DMixerParam_Distance and k3DMixerParam_Azimuth parameters.

Listing 1  Setting a non-zero positive distance

Float32 distance = 1.0;  for (int i = 0; i < numbuses; i++) {     AudioUnitSetParameter(mMixer, k3DMixerParam_Distance, kAudioUnitScope_Input, i, distance, 0); }

Listing 2  Panning from left to right by adjusting azimuth

// pan ranges from -1 to +1 Float32 azimuth = 90.0 * pan;  for (int i = 0; i < numbuses; i++) {     AudioUnitSetParameter(mMixer, k3DMixerParam_Azimuth, kAudioUnitScope_Input, i, azimuth, 0); }

For more information on how to use the 3D Mixer audio unit, see Using the 3D Mixer audio unit. While this document discusses the non-embedded version of this audio unit, they are very similar especially in general setup.

For reference information on the k3DMixerParam_Distance and k3DMixerParam_Azimuth audio unit parameters, see Audio Unit Parameters Reference.



Document Revision History


DateNotes
2010-05-22

New document that discusses how to implement stereo panning using the 3D Mixer audio unit.