使用 ALSA api - 在缓冲区填满之前声音不会启动

发布于 2024-09-27 20:44:13 字数 451 浏览 0 评论 0原文

我使用的应用程序仅在生成足够的声音后才播放声音。假设我单击鼠标 10 次,没有声音,然后在这十次单击之后,我会听到十次鼠标单击声音(例如)

我发现缓解此问题的唯一方法是设置非常短的缓冲区大小,我不想这样做。

我一直在尝试使用 start_threshold sw 参数,但这没有效果。

似乎我应该能够在写入低于缓冲区大小的指定数据量时强制它播放,这是正确的吗?这就是 start_threshold 似乎表明的内容,因为周期长度可能比缓冲区短得多(或者我在示例中看到的)。

我的代码是这样的:

调用硬件参数设置

获取一个带有数据循环的字节数组

,并在每次调用开始时写入缓冲区加上一个字节偏移量

(这应该强制它播放,对吗?)

如果有-EPIPE,调用prepare并将0添加到offset(我认为这是唯一一次播放的时候。)

谢谢!

The application I'm using only plays sounds after enough sound has been generated. Say I click the mouse 10 times, with no sound, and then after those ten clicks I'll hear ten mouse click sounds (for example)

The only way I've found to alleviate this problem is to set a very short buffer size, which I don't want to do.

I've been trying to use the start_threshold sw parameter but that has no effect.

It seems like I should be able to force it to play when a specified amount of data has been written that is under buffer size, is this correct? That's what start_threshold seems to indicate, since the period length can be much shorter than the buffer (or so I've seen in examples).

My code is like this:

Call HW parameter setup

get a byte array with data

loop through and write to the buffer plus one byte offset each time

call start (this should force it to play back, right??)

if there is -EPIPE, call prepare and add 0 to offset (I think this is the only time when things get played.)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文