且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ALSA中设置周期和缓冲区大小?

更新时间:2023-01-25 08:02:55

周期大小指定硬件通知您的应用程序已捕获完整周期的频率.这是一个硬件参数,表示该硬件可能不支持所需的值.

The period size specifies how often the hardware notifies your application that a complete period has been captured. It is a hardware parameter, which means that the hardware might not support the value that you want.

要获取最接近所需值的周期大小,请使用 snd_pcm_hw_params_set_period_size_near().

To get the period size that is nearest to your desired value, use snd_pcm_hw_params_set_period_size_near().

如果要读取160个样本,只需告诉 snd_pcm_read *()即可读取160帧.但是,如果这与周期大小不匹配,则会产生抖动.如果降低抖动很重要,则必须将样本放在自己的队列中,然后将其与用合适的计时器.

If you want to read 160 samples, just tell snd_pcm_read*() to read 160 frames. However, if this does not match the period size, you will get jitter. If reducing jitter is important, you have to put the samples in your own queue and take them with out with an appropriate timer.

请注意,捕获延迟仅取决于周期大小,而不取决于缓冲区大小,因此,应将缓冲区设置得尽可能大,以减少发生超限的风险.

Please note that capture latency depends only on the period size, not on the buffer size, so you should make the buffer as large as possible to reduce the risk of overruns.