获取audio驱动程序采样率的OSX AVAudioSession替代

在IOS上你可以使用[[AVAudioSession sharedInstance] sampleRate]; 检索audio驱动程序使用的当前采样率。 AVAudioSession在OSX上不存在,所以我想知道如何在OSX上实现相同的function,因为我无法在主题上find太多内容。

谢谢

好的,

经过一些更深入的研究, audio硬件服务似乎在OSX上诀窍。 以下是一些示例代码:

 //get the default output device AudioObjectPropertyAddress addr; UInt32 size; 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 audio – MIDI设置中更改的采样率设置。