我正在尝试使用CoreAudio在MacOS的硬件上获得预期的缓冲区大小。我目前的策略是基于this technical note。
该代码实现如下:
AudioObjectID DeviceAudioObjectID;
AudioObjectPropertyAddress DevicePropertyAddress;
UInt32 AudioDeviceQuerySize;
OSStatus Status;
int32 BufferSize = 0;
//Get Audio Device ID
DevicePropertyAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
DevicePropertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
DevicePropertyAddress.mElement = 0;
AudioDeviceQuerySize = sizeof(AudioDeviceID);
Status = AudioObjectGetPropertyData(kAudioObjectSystemObject, &DevicePropertyAddress, 0, nullptr, &AudioDeviceQuerySize, &DeviceAudioObjectID);
DevicePropertyAddress.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
DevicePropertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
DevicePropertyAddress.mElement = kAudioObjectPropertyElementMaster;
AudioValueRange BufferSizeRange = { 0, 0 };
AudioDeviceQuerySize = sizeof(AudioValueRange);
Status = AudioObjectGetPropertyData(DeviceAudioObjectID, &DevicePropertyAddress, 0, nullptr, &AudioDeviceQuerySize, &BufferSizeRange);
在我当前的Mac(运行Sierra的Mac Pro)上,此处对
AudioObjectGetPropertyData
的最终调用导致BufferSizeRange
明确设置为{ 0, 0 }
。调用返回0
,表明成功。如何正确查询硬件支持的缓冲区大小范围?
最佳答案
我不明白你的问题在哪里。我已经在装有OS X Sierra的MacBook上尝试了您的代码,效果很好。当我检查了存储在BufferSizeRange中的结果后,我得到了mMinimum = 14和mMaximum = 4096。
我刚刚更改了BufferSize的错误初始化(您编写的int32不作为变量存在),当您要知道谁是默认输出设备时,我将NULLptr替换为NULL并设置DevicePropertyAddress.mElement = kAudioObjectPropertyElementMaster。
但是,我建议您直接向CoreAudio询问要通过AudioObjectGetPropertyDataSize知道的属性的大小,并检查if语句函数的返回值。
关于macos - kAudioDevicePropertyBufferFrameSizeRange返回{0,0},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44444061/