How to set pan in IOS Audio Unit Framework

我的未来我决定 提交于 2019-12-07 06:18:21

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/38636771/how-to-set-pan-in-ios-audio-unit-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!