OSX:用于设置IO缓冲区长度的CoreAudio API? [英] OSX: CoreAudio API for setting IO Buffer length?

查看:169
本文介绍了OSX:用于设置IO缓冲区长度的CoreAudio API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是上一个问题的后续内容: OSX CoreAudio:提前获取inNumberFrames-在初始化时可以吗?

This is a follow-up to a previous question: OSX CoreAudio: Getting inNumberFrames in advance - on initialization?

我试图弄清楚什么是AudioUnit API,可以为输入回调设置 inNumberFrames 首选IO缓冲区持续时间 OSX 中的一个 HAL 音频组件实例(不是插件!). 虽然我了解到有关如何在iOS中实现此功能的全面文档,但借助于 AVAudioSession API,我既找不到也找不到有关在Windows中设置这些值的文档. OSX,无论哪个API. 网络上到处都是专家,但语句相互矛盾,范围从"有一个音频单元API来请求采样率和首选的缓冲持续时间... ",到"您肯定可以得到帧数,但仅适用于当前的回调调用... .

I am trying to figure out what will be the AudioUnit API for possibly setting inNumberFrames or preffered IO buffer duration of an input callback for a single HAL audio component instance in OSX (not a plug-in!). While I understand there is a comprehensive documentation on how this can be achieved in iOS, by means of AVAudioSession API, I can neither figure out nor find documentation on setting these values in OSX, whichever API. The web is full of expert, yet conflicting statements ranging from "There is an Audio Unit API to request a sample rate and a preferred buffer duration...", to "You can definitely get the number of frames, but only for the current callback call...".

是否至少有一种方法可以获取(并适应)系统提供的 inNumberFrames 音频缓冲区长度 OSX中输入选择的采样率?例如,对于44.1k及其倍数(这似乎部分起作用),以及对于48k及其倍数(这似乎根本不起作用,我不知道允许修改缓冲区的破解方法在哪里)不够这些值)?这是控制台的打印输出:

Is there a way of at least getting (and adapting to) the inNumberFrames or the audio buffer length offerd by the system, for the input-selected sampling rates in OSX? For example, for 44.1k and its multiples (this seems to work partly), as well as for 48k and its multiples (this doesn't seem to work at all, I don't know where's the hack which allows for adapting the buffer lenfth to these values)? Here's the console printout:

Available 7 Sample Rates
Available Sample Rate value : 8000.000000
Available Sample Rate value : 16000.000000
Available Sample Rate value : 32000.000000
Available Sample Rate value : 44100.000000
Available Sample Rate value : 48000.000000
Available Sample Rate value : 88200.000000
Available Sample Rate value : 96000.000000

.mSampleRate          =   48000.00
.mFormatID            = 1819304813
.mBytesPerPacket      = 8
.mFramesPerPacket     = 1
.mBytesPerFrame       = 8
.mChannelsPerFrame    = 2
.mBitsPerChannel      = 32
.mFormatFlags         = 9
_mFormatHumanReadable = kAudioFormatFlagIsFloat 
    kAudioFormatFlagIsPacked 
    kLinearPCMFormatFlagIsFloat 
    kLinearPCMFormatFlagIsPacked 
    kLinearPCMFormatFlagsSampleFractionShift 
    kAppleLosslessFormatFlag_16BitSourceData 
    kAppleLosslessFormatFlag_24BitSourceData 

expectedInNumberFrames = 512

Couldn't render in current context (Error -10863)

从系统中读取预期的inNumberFrames:

The expected inNumberFrames is read from the system:

UInt32 expectedInNumberFrames = 0;
UInt32 propSize = sizeof(UInt32);
AudioUnitGetProperty(gInputUnitComponentInstance,
                     kAudioDevicePropertyBufferFrameSize,
                     kAudioUnitScope_Global,
                     0,
                     &expectedInNumberFrames,
                     &propSize);

预先感谢您指出正确的方向!

Thanks in advance for pointing me at the right direction!

推荐答案

请参阅此Apple技术说明:

See this Apple Technical Note: https://developer.apple.com/library/mac/technotes/tn2321/_index.html#//apple_ref/doc/uid/DTS40013499-CH1-THE_I_O_BUFFER_SIZE

有关GetIOBufferFrameSizeRange(),GetCurrentIOBufferFrameSize()和SetCurrentIOBufferFrameSize()的信息,请参阅此技术说明中的OS X示例代码.

See the OS X example code in this technical note for GetIOBufferFrameSizeRange(), GetCurrentIOBufferFrameSize(), and SetCurrentIOBufferFrameSize().

请注意,有一个API属性返回允许的范围,并且在属性设置器上返回错误.还要注意,各种Mac省电模式可能会在应用程序运行时更改缓冲区大小,因此,实际的缓冲区大小inNumberFrames可能不会保持恒定,甚至直到音频单元开始运行时才知道.

Note that there is an API property returning an allowed range, and an error return on the property setter. Also note the various Mac power saving modes may change the buffer size while an app is running, so the actual buffer size, inNumberFrames, may not stay constant, or even be known until the Audio Unit starts running.

如果获得异常的缓冲区大小(不是2的幂),则可能是特定Apple产品型号上的实际音频硬件具有固定或有限范围的音频采样率,因此正在使用OS软件来如果应用程序请求电路板上实际编解码器芯片不支持的采样率,则根据该硬件重新采样并调整发送到音频单元回调的缓冲区的大小.

If you get unusual buffer sizes (not a power of 2), it may be that the actual audio hardware on a particular Apple product model has a fixed or limited range of audio sample rates, and thus OS software is being used to resample and thus resize the buffers being sent to audio unit callbacks depending on that hardware, if the app requests a sample rate not supported by the actual codec chips on the circuit board.

这篇关于OSX:用于设置IO缓冲区长度的CoreAudio API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆