您可以在 Windows Wave 音频输入中重复使用缓冲区吗?
我正在使用 Windows 多媒体 API 来录制和处理波形音频(waveInOpen
和朋友)。我想以循环方式使用少量缓冲区。
我知道您应该在向设备添加缓冲区之前使用waveInPrepareHeader
,并且您应该在wave设备“返回缓冲区”之后调用waveInUnprepareHeader
到应用程序”并在取消分配它之前。
我的问题是,我是否必须取消准备并重新准备才能重新使用缓冲区?或者我可以将以前使用过的缓冲区添加回设备吗?
另外,我在哪个线程上执行此操作有关系吗?我正在使用回调函数,它似乎是在属于音频系统的工作线程上调用的。在回调期间,我可以在该线程上调用 waveInUnprepareHeader
、waveInPrepareHeader
和 waveInAddBuffer
吗?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,我的经验是你每次都需要调用准备和取消准备。根据记忆,如果您尝试重复使用同一个,它会返回一个错误。
您通常会在处理回调的任何线程上调用准备和取消准备。
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.
创建缓冲区时,调用
waveInPrepareHeader
。然后,您只需在从设备返回的缓冲区上调用waveInAddBuffer
之前设置 prepared 标志即可。您可以在回调线程(或在消息处理程序中)执行此操作。
When you create the buffers, call
waveInPrepareHeader
. Then you can simply set the prepared flag before you callwaveInAddBuffer
on a buffer that was returned from the device.You can do this on the callback thread (or in the message handler).