OSX上的AVAudioSession替代方案,用于获取音频驱动程序采样率



在IOS上,您可以使用[[AVAudioSession sharedInstance] sampleRate];来检索音频驱动程序使用的当前采样率。AVAudioSession在OSX上不存在,所以我想知道如何在OSX中实现同样的东西,因为我在这个主题上找不到太多。

感谢

好的,

经过一些更深入的研究音频硬件服务似乎在OSX上发挥了作用。以下是一些示例代码:

//get the default output device
AudioObjectPropertyAddress addr;
UInt32 size;
AudioDeviceID deviceID = 0;
addr.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
addr.mScope = kAudioObjectPropertyScopeGlobal;
addr.mElement = 0;
size = sizeof(AudioDeviceID);
err = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &addr, 0, NULL, &size, &deviceID);
//get its sample rate
addr.mSelector = kAudioDevicePropertyNominalSampleRate;
addr.mScope = kAudioObjectPropertyScopeGlobal;
addr.mElement = 0;
size = sizeof(Float64);
Float64 outSampleRate;
err = AudioHardwareServiceGetPropertyData(deviceID, &addr, 0, NULL, &size, &outSampleRate);
//if there is no error, outSampleRate contains the sample rate

不幸的是,没有IOS版本那么容易,但做得好!这将为您提供可以在OSX音频MIDI设置中更改的采样率设置。

最新更新