【问题标题】:AVAudioSession alternative on OSX to get audio driver sample rateOSX 上的 AVAudioSession 替代方案,用于获取音频驱动程序采样率
【发布时间】:2014-08-28 19:36:05
【问题描述】:

在 IOS 上,您可以使用 [[AVAudioSession sharedInstance] sampleRate]; 检索音频驱动程序使用的当前采样率。 OSX 上不存在 AVAudioSession,所以我想知道如何在 OSX 上实现相同的功能,因为我找不到太多关于该主题的内容。

谢谢

【问题讨论】:

    标签: ios macos cocoa audio avfoundation


    【解决方案1】:

    好的,

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

    【讨论】:

    • 使用未声明的标识符“deviceID”。应该是什么?
    猜你喜欢
    • 2021-08-12
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    • 2011-05-28
    • 2017-03-04
    • 2018-07-14
    • 1970-01-01
    • 2016-01-12
    相关资源
    最近更新 更多