?
Solved

Checking if wave file is playing

Posted on 1999-12-28
11
Medium Priority
?
325 Views
Last Modified: 2013-12-03
I use waveOutWrite() to play segments of a large wave file in Visual C++.  After I start playing it, I need to know whether the wave segment finished playing or not.
What is a way to check this?

0
Comment
Question by:mroslyak
11 Comments
 
LVL 4

Expert Comment

by:inpras
ID: 2309713
Hi
waveOutGetPosition( ) ??
Regards
0
 

Author Comment

by:mroslyak
ID: 2309847
I tried using waveOutGetPosition() but was not able to get it to work, since I could not find a lot of documentaion on it
A simple example would be nice.
0
 
LVL 2

Expert Comment

by:WDB
ID: 2310160
Have you tried looking for the MM_WOM_DONE message? This is how I determine when a segment is complete and when to move to the bext one. Here is an explanation of it:

The MM_WOM_DONE message is sent to a window when the given output buffer is being returned to the application. Buffers are returned to the application when they have been played, or as the result of a call to the waveOutReset function.

MM_WOM_DONE
wParam = (WPARAM) hOutputDev
lParam = (LONG) lpwvhdr
 
Parameters
hOutputDev
Handle of the waveform-audio output device that played the buffer.

lpwvhdr
Address of a WAVEHDR structure identifying the buffer.
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 23

Expert Comment

by:chensu
ID: 2310327
WDB is right. You may find the following article useful.

Recording and Playing Waveform Audio
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/techart/msdn_spellit.htm
0
 
LVL 6

Expert Comment

by:WxW
ID: 2310807
When u open the device with waveOutOpen , put the CALLBACK_WINDOW flag and a handle to a window . When writing to the device finishes , your window receives a message MM_WOM_DONE .
0
 
LVL 3

Accepted Solution

by:
byang earned 200 total points
ID: 2311863
After a successful call to:

   waveOutWrite(..., ph, ...);

just check ph->dwFlags. When the wave buffer is finished playing, WHDR_DONE will be set in dwFlags. So:

   if (WHDR_DONE ==
       (WHDR_DONE&ph->dwFlags))
   { //finished playing

   } else
   { //not finished playing

   }
 
You are supposed to keep *ph around so you can call waveOutUnprepareHeader() later.
0
 
LVL 2

Expert Comment

by:WDB
ID: 2312101
Checking the ph->dwFLags is not as convienent as waiting for the MM_WOM_DONE message. When you check the ph->dwFlags and WHDR_DONE isn't set then you need to keep checking until it is. Therefore, this method will require some extra logic, not to mention it won't be as efficient as processing MM_WOM_DONE.
0
 
LVL 3

Expert Comment

by:byang
ID: 2313378
You don't have to check it in an endless loop, just once in a while. If at any given time you want to check if a wave block finished playing, I'd say WHDR_DONE is the way to go, even if you have a window callback for other purposes already.

If you wait for MM_WOM_DONE, where are you going to put the finished flags for wave blocks ? Some extra variables? You might as well just check dwFlags as the systems sets it for you.
0
 
LVL 2

Expert Comment

by:WDB
ID: 2313441
Why would I need to put the finished flags anywhere?? I still have ph and the flags still get set but I won't need to do any extra work in determining when they get set.
   I've worked with many MM apps and  MM_WOM_DONE is always used. I can think of some special instances where it would be useful to keep tabs on the flag, but just to find out when a block has finished, MM_WOM_DONE is the way to go.
0
 
LVL 3

Expert Comment

by:byang
ID: 2314635
Sorry, I have to disagree there. What I mean is, for example, 1 second after a wave started playing, you need to check if it's finished. Using MM_WOM_DONE, how would you do it ? At minimum you need a one-bit flag to indicate if MM_WOM_DONE is sent already. So why not just check dwFlags in wave header, which you already have anyway.

Besides, checking the WHR_DONE is simpler as it doesn't require you to worry about windows message callback.

0
 
LVL 2

Expert Comment

by:WDB
ID: 2314720
Maybe I'm missing something here? The only way that method makes sense to me is if you are planning on doing something different to the buffer if it hasn't finished playing after 1 second, other then allowing it to continue to play.    
 Otherwise, why would you want to poll for this when the windows message callback will tell you when it's done? To me this seems very efficent and straight forward.
   Also, when polling the flag, you will have to have your timing just right, otherwise your application could take a performance hit or even experience audio dropouts when playing wave files. So, additional coding would be neccessary to make sure the timing is right.
   And, what is wrong with a windows message callback? They are very easy to setup, efficient to use, not to mention they lend themselves very well to most MM components.
  So, my point is, an application that plays a wave file and uses MM_WOM_DONE to determine and set the "buffer flow" will be more efficient and easier to code then an application that attempts to poll the wave header flags. I've yet to see it done any other way.

Take Care :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Suggested Courses
Course of the Month5 days, 1 hour left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question