play a streaming audio

J

JC

Hi,

I have to play a streaming audio. So in a thread I play audio as follow

thread{
//some code
for(;;){
//some code
waveOutPrepareHeader(hwo, &(whdr), sizeof(WAVEHDR));
waveOutWrite(hwo, &(whdr), sizeof(WAVEHDR));

while(finish == 0){} //will set in callback func

waveOutUnprepareHeader(hwo, &(whdr), sizeof(WAVEHDR));

}
}


However, the sound is played not smooth. I think that the PrepareHeader and
UnPrepareHeader should not be called so frequntly. Am I right?

Also, otherthan using the while(finish==0){}, is there any method that I can
make sure the previous stream has been playbed before I play the next stream?


}
 
W

William DePalo [MVP VC++]

JC said:
I have to play a streaming audio.

You should post questions on playing audio in the multimedia group

microsoft.public.win32.programmer.mmedia
So in a thread I play audio as follow

thread{
//some code
for(;;){
//some code
waveOutPrepareHeader(hwo, &(whdr), sizeof(WAVEHDR));
waveOutWrite(hwo, &(whdr), sizeof(WAVEHDR));

while(finish == 0){} //will set in callback func

waveOutUnprepareHeader(hwo, &(whdr), sizeof(WAVEHDR));

Except for devices with the lousiest of drivers it is not necessary to
prepare and unprepare on every transmission. I prepare buffers once after
opening the device and when the driver returns a buffer I set the
WHDR_PREPARED bit before calling waveOutWrite() again. I unprepare just
before closing the device.
However, the sound is played not smooth. I think that the PrepareHeader
and
UnPrepareHeader should not be called so frequntly. Am I right?

I am told that there are devices for which you must do that. I consider
those devices "broken" and choose not to support them.
Also, otherthan using the while(finish==0){}, is there any method that I
can
make sure the previous stream has been playbed before I play the next
stream?

The driver sets the WHDR_DONE bit in the header when it is done with the
buffer. You could check that.

And depending on how you sized the buffer you may want to use more than one.

Regards,
Will
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top