macos - kAudioDevicePropertyBufferFrameSizeRange返回{0,0}

标签 macos audio core-audio hal

我正在尝试使用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/

相关文章:

c++ - 符号加载非常慢

swift - 在 OSX 应用程序上运行测试时为 "Message from debugger: unable to attach"

audio - 音频数据样本代表什么?

javascript - 如何避免setInterval过慢?

ios - 麦克风输入到 iOS 中的扬声器输出?

macos - OSX : Put terminal window as tab in another one

macos - openmpi 忽略错误 : mca interface is not recognized

windows - 部署时 QSoundEffect 不播放声音

audio - AVAudioEngine是否支持递归路由?

iphone - iOS LPCM Non-interleaved Audio input with 2 channels : not possible?