在 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 Audio-MIDI-Setup 中更改的采样率设置。
关于ios - OSX 上的 AVAudioSession 替代方案以获取音频驱动程序采样率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25556680/