CoreAudio AudioUnitSetProperty always fails to set Sample Rate

跟風遠走 提交于 2019-12-04 07:46:20

With the DefaultOuput AudioUnit you only set the input side of the AudioUnit to the format you wish to render. The output side of the unit will match what you specify on the input side but you cannot set it yourself.

Try this after you have set the input stream format and you'll see that you are all set to go...

Float64 outSampleRate = 0.0;
UInt32 size = sizeof(Float64);
AudioUnitGetProperty (gOutputUnit,
                      kAudioUnitProperty_SampleRate,
                      kAudioUnitScope_Output,
                      0,
                      &outSampleRate,
                      &size);
NSLog(@"Output sample rate is now at %f Hz", outSampleRate);

You can also look at the Audio Unit Component Services Reference to see that error code -10865 is kAudioUnitErr_PropertyNotWritable.

The documentation states that when you set the Sample rate property, you are actually requesting a value (which the system may not be able to give you).

The system will then set the best approximation it can.

You then need to follow up with a call to retrieve the sampling rate that was actually set.

As I understand, it is not possible to specify any arbitrary sample rate.

I would love to be wrong on this!!!

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