,您可以使用[[AVAudioSession sharedInstance] sampleRate];
来检索音频驱动程序使用的当前采样率。 OSX上不存在AVAudioSession,所以我想知道如何在OSX上实现同样的功能,因为我在这个主题上找不到太多。
由于
答案 0 :(得分:2)
好,
经过一些更深入的研究音频硬件服务似乎在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 中更改的采样率设置。