您可以在 Windows Wave 音频输入中重复使用缓冲区吗?

发布于 2024-10-03 19:13:34 字数 457 浏览 3 评论 0原文

我正在使用 Windows 多媒体 API 来录制和处理波形音频(waveInOpen 和朋友)。我想以循环方式使用少量缓冲区。

我知道您应该在向设备添加缓冲区之前使用waveInPrepareHeader,并且您应该在wave设备“返回缓冲区”之后调用waveInUnprepareHeader到应用程序”并在取消分配它之前。

我的问题是,我是否必须取消准备并重新准备才能重新使用缓冲区?或者我可以将以前使用过的缓冲区添加回设备吗?

另外,我在哪个线程上执行此操作有关系吗?我正在使用回调函数,它似乎是在属于音频系统的工作线程上调用的。在回调期间,我可以在该线程上调用 waveInUnprepareHeaderwaveInPrepareHeaderwaveInAddBuffer 吗?

I'm using the Windows multimedia APIs to record and process wave audio (waveInOpen and friends). I'd like to use a small number of buffers in a round robin fashion.

I know that you're supposed to use waveInPrepareHeader before adding a buffer to the device, and that you're supposed to call waveInUnprepareHeader after the wave device has "returned the buffer to the application" and before you deallocate it.

My question is, do I have to unprepare and re-prepare in order to re-use a buffer? Or can I just add a previously used buffer back to the device?

Also, does it matter what thread I do this on? I'm using the callback function, which seems to be called on a worker thread that belongs to the audio system. Can I call waveInUnprepareHeader, waveInPrepareHeader, and waveInAddBuffer on that thread, during the callback?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素年丶 2024-10-10 19:13:34

是的,我的经验是你每次都需要调用准备和取消准备。根据记忆,如果您尝试重复使用同一个,它会返回一个错误。

您通常会在处理回调的任何线程上调用准备和取消准备。

Yes, my experience has been you need to call prepare and unprepare every time. From memory, it returns an error if you try to reuse the same one.

And you typically call the prepare and unprepare on whatever thread you are handling the callbacks on.

你的往事 2024-10-10 19:13:34

创建缓冲区时,调用waveInPrepareHeader。然后,您只需在从设备返回的缓冲区上调用 waveInAddBuffer 之前设置 prepared 标志即可。

pHdr->dwFlags = WHDR_PREPARED;

您可以在回调线程(或在消息处理程序中)执行此操作。

When you create the buffers, call waveInPrepareHeader. Then you can simply set the prepared flag before you call waveInAddBuffer on a buffer that was returned from the device.

pHdr->dwFlags = WHDR_PREPARED;

You can do this on the callback thread (or in the message handler).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文