2014-08-28 94 views
3

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

感谢

回答

2

好吧,

一些更深入的研究音频硬件服务后,似乎做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-Setup中更改的采样率设置。

+0

使用未声明的标识符'deviceID'。应该是什么? – 2017-07-22 11:12:10