freelancer freelancer - 1 year ago 134
Objective-C Question

How to set pan in IOS Audio Unit Framework

Hello stack overflow users,

i want to change pan position using UISlided in my IOS application.

i am upgrading whole app which is currently using AudioStreamer of Matt Gallagher

To change the pan value in in AudioStreamer used below code.

AudioQueueRef audioQueue; // defined in AudioStreamer.h file

- (void)changePan:(float)newPan
OSStatus panErr = AudioQueueSetParameter( audioQueue, kAudioQueueParam_Pan, newPan);
NSLog(@" setting pan: %ld", panErr);
if( panErr )
NSLog(@"Error setting pan: %ld", panErr);

i am replacing AudioStreamer with StreamingKit which use AudioUnit

if i will get some help to make this thing done using StreamingKit or AudioUnit i will appreciate that.

P.S Let me know if anyone needs more info.


Answer Source

Using AudioUnit API, you can simply set the kMultiChannelMixerParam_Pan property of the audio mixer unit to set the stereo pan:

AudioUnitParameterValue panValue = 0.9; // panned almost dead-right. possible values are between -1 and 1
int result = AudioUnitSetParameter(mixerUnit, kMultiChannelMixerParam_Pan, kAudioUnitScope_Input, 0, panValue, 0);
if (result == 0)

You may also need to retrieve the internal mixerUnit instance variable from inside STKAudioPlayer. You can try [audioPlayer valueForKey:@"_mixerUnit"] for that or implement a getter yourself inside StreamingKit's files.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download