iOS:在Audio Unit中动态更改采样率

时间:2015-09-13 07:00:10

标签: ios objective-c core-audio audiounit sample-rate

是否可以在正在运行的AudioSession / AudioUnit中间更改/设置采样率而无需停止/重新启动当前的AudioSession / AudioUnit(就像音频路径一样)?

我有一个有效的音频会话,其采样率为44.1 KHz

AudioStreamBasicDescription.mSampleRate         = 44100

我想在不取消初始化[AudioUnitUninitialize(audioUnit)]或停止[AudioOutputUnitStop(audioUnit)]或停用音频单元/会话的情况下将采样率更改为8KHz。

这是我的音频设备设置。

audioComponentDescription.componentType = kAudioUnitType_Output;
audioComponentDescription.componentSubType = kAudioUnitSubType_VoiceProcessingIO;
audioComponentDescription.componentFlags = 0;
audioComponentDescription.componentFlagsMask = 0;
audioComponentDescription.componentManufacturer = kAudioUnitManufacturer_Apple;


audioStreamBasicDescription.mSampleRate         = 44100;
audioStreamBasicDescription.mFormatID           = kAudioFormatLinearPCM;
audioStreamBasicDescription.mFormatFlags        =  kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
audioStreamBasicDescription.mFramesPerPacket    = 1;
audioStreamBasicDescription.mChannelsPerFrame   = 1;
audioStreamBasicDescription.mBitsPerChannel     = 16;
audioStreamBasicDescription.mBytesPerPacket     = 2;
audioStreamBasicDescription.mBytesPerFrame      = 2;

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

是的,您可以使用kAudioUnitSubType_SpatialMixer音频单元动态地执行此操作。 用伪代码:

AudioUnitSetParameter(mixerUnit, k3DMixerParam_PlaybackRate, kAudioUnitScope_Input, 0, sampleRateRatio(from 0.0 to 2.0), 0);