AudioUnit 的数据包和帧大小使用什么值
我正在熟悉如何使用 AudioUnit 来播放声音,但对数据包和帧的概念感到困惑。我想知道:
AudioUnit 上下文中数据包和帧的定义是什么
交易是什么每个数据包使用多个样本,每帧使用多个数据包
我提问的原因:在到目前为止我看到的所有代码示例中,数据包本质上是一个示例,对于 16 位立体声流,通常 mBytesPerPacket=4。 mFramesPerPacket 通常为 1,使得帧、数据包和样本(都是立体样本)成为相同的概念。
我期望数据包和/或帧成为样本缓冲区,即一组 256 或 512 个连续样本,驱动程序可以指向并线性读取它们。将帧/数据包大小减少到一个样本似乎会给负责播放数据的任何驱动程序带来不必要的压力。我缺少什么?
I am familiarizing myself with how to use AudioUnit to play sounds and am confused by the notions of packets and frames. I would like to know:
what is the definition of a packet and a frame in the context of AudioUnit
what are the trades for using multiple samples per packet, and multiple packets per frame
My reason for asking: In all code samples I saw so far, a packet is essentially a sample, with typically mBytesPerPacket=4 for a 16-bit stereo stream. And mFramesPerPacket is typically 1, making a frame, a packet, and a sample (all be it stereo sample), the same concepts.
I was expecting a packet and/or a frame to be a buffer of samples, i.e. a group of 256 or 512 consecutive samples, to which the driver could be pointed and read linearly. Reducing a frame/packet size to one sample seems to put unnecessary strain on whatever driver will be responsible for playing the data. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,一些定义:
您不应该混淆数据包和帧,事实上
mFramesPerPacket
通常应设置为 1。这并不意味着您的 AudioUnit 的 render 方法将在每帧获得回调。如果您想控制发生这种情况的频率,则需要将 kAudioSessionProperty_PreferredHardwareIOBufferDuration 属性设置为首选缓冲区大小。设置此属性并不能保证您所要求的确切缓冲区大小,但系统会尝试为您提供接近此值的值。First, some definitions:
You should not confuse a packet and frame, and in fact
mFramesPerPacket
should generally be set to 1. This does not mean that your AudioUnit's render method will get a callback every frame. If you want to control how often that happens, you need to set thekAudioSessionProperty_PreferredHardwareIOBufferDuration
property to the preferred buffer size. Setting this property does not guarantee you the exact buffer size that you ask for, but the system will try to give you something close to this value.