开发者

Can you re-use buffers with Windows wave audio input?

I'm using the Windows multimedia APIs to record and process wave audio (waveInO开发者_开发技巧pen 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?


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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜