Re: Threads for ongoing processes
From: Billw (notarealemail_at_nowhere.com)
Date: 01/31/05
- Next message: abcd: "AT-commands"
- Previous message: Robert Marquardt: "Re: Header Conversion"
- In reply to: Bram Bos: "Threads for ongoing processes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 31 Jan 2005 08:35:00 -0500
Actually, if you use a callback to trigger the buffer preparation and
submission, it already will be in a separate thread (the MME thread in
Windows).
Do it like so:
1. In your main thread, prepare your first several buffers and submit them,
setting up MME to call your callback function when done with each. I use
triple buffers, but double is usually sufficient. Start the Wav engine
"paused", so you can unpause it when all buffers have been initialized.
Then unpause to get it going.
2. in the callback function (that is called when a buffer has played),
prepare the replacement buffer. This occurs in the MME thread. But DONT
submit the buffer from the callback function, as you aren't supposed to call
that MME API function from within a callback. Instead, Post (not Send!)
your app (or a thread within it) a Message to tell it that the buffer is
ready. (Or use some other mechanism such as Windows' SetEvent to trigger
the submission outside of your callback).
3. In the message handler (or in whatever code ---outside the callback
thread -- that knows when a buffer is ready) resubmit the newly prepared
buffer.
4. You don't need to "go back' anywhere, since everything is triggered by
callbacks; it will keep itself running. Step 3 is where you would put the
code to close things down when all is finished or the user wants the sound
to stop.
It's not very difficult. Just remember to keep your hands off each buffer
until the callback tells you it is ready again.
"Bram Bos" <bram@mindless.com> wrote in message
news:e386cf42.0501310227.42639d13@posting.google.com...
> I'm working on an application that processes audio and plays
> it back using common MME functions. The process looks like this:
>
> 1. send buffer to playback output
> 2. prepare new buffer with sound data
> 3. callback: "playback is done" > go to step 1.
>
> I wish to do this using a separate thread, because the user
> is messing around in lots of graphical GUI things in the main
> thread. I can't really figure out how to assign this
> callback/process to a thread though. I know how to create
> a thread for a one-time job, but not how to do it for an
> ongoing process (using a callback mechanism)...
>
> can one of the Delphi gurus around here shed some light?
>
> Thanks!
>
> Bram
- Next message: abcd: "AT-commands"
- Previous message: Robert Marquardt: "Re: Header Conversion"
- In reply to: Bram Bos: "Threads for ongoing processes"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|