AudioHardwareALSA::getInputBufferSize(...) 中的缓冲区计算
我正在查看 AudioHardwareALSA.cpp 中的 getInputBufferSize(...) 函数,它返回硬编码的值 320。我的问题是:这个值是如何计算的?
我已经做了一些预校准,但仍然存在一些问题。
sample_rate = 8000
format = S16_LE = 2 bytes/sample
period_time = 10000 us (guessing)
buffer_size = 2 * period_size
period_size = period_time * bytes/sec
buffer_size = 2 * (0.01 * sample_rate * 2) = 320 bytes.
我在代码中找不到 period_time ,所以一个问题是:它是在哪里定义的还是只是一个粗略的计算?
我还尝试添加更多采样率,即 16000 和 32000(以后可能会更多)。如何计算正确的最小缓冲区大小?对于所有采样率,延迟是否始终为 10 毫秒?
任何帮助表示赞赏。
I'm looking at getInputBufferSize(...) function in AudioHardwareALSA.cpp and it returns hardcoded the value of 320. My question is: How is this value calculated?
I've done some pre-cals but still there are some questions.
sample_rate = 8000
format = S16_LE = 2 bytes/sample
period_time = 10000 us (guessing)
buffer_size = 2 * period_size
period_size = period_time * bytes/sec
buffer_size = 2 * (0.01 * sample_rate * 2) = 320 bytes.
I can't find the period_time in the code, so one question is: where is it defined or is just a rough calculation?
I'm also trying to add some more sample rates i.e 16000 and 32000 (later maybe more). How to calculate the right minimum buffer size? Is the delay always 10 ms for all the sample rates?
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信 Google 一开始就实施了 NB-AMR 编码。后来他们增加了对 AAC 的支持。对于 NB-AMR,帧大小为 320 字节。
您可能知道,对于 NB-AMR:
采样率 = 8000 个样本/秒
帧持续时间 = 20ms
样本大小 = 2 字节
通道 = 单声道
所以,每一帧包含
8000 个样本/秒 * 0.02 秒 * 2 字节/样本/通道 * 1 个通道 = 320 字节
对于 AAC,这些参数不同,因此帧大小也不同
I believe Google implemented NB-AMR encode to start with. later they added support for AAC. In the case of NB-AMR, the frame size is 320 bytes.
You may be aware that for NB-AMR:
sampling rate = 8000 samples / sec
frame duration = 20ms
sample size = 2 bytes
channels = mono
So, each frame contains
8000 samples / sec * 0.02 sec * 2 bytes / sample / channel * 1 channels = 320 bytes
For AAC, these parameters are different and hence the framesize