Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set pan in IOS Audio Unit Framework

Tags:

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.

Thanks

like image 655
freelancer Avatar asked Jul 28 '16 12:07

freelancer


1 Answers

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)
{
   NSLog("success");
}

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.

like image 161
Tomer Avatar answered Nov 04 '22 17:11

Tomer