play a streaming audio

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JC

    #1

    play a streaming audio

    Hi,

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

    thread{
    //some code
    for(;;){
    //some code
    waveOutPrepareH eader(hwo, &(whdr), sizeof(WAVEHDR) );
    waveOutWrite(hw o, &(whdr), sizeof(WAVEHDR) );

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

    waveOutUnprepar eHeader(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?


    }
  • William DePalo [MVP VC++]

    #2
    Re: play a streaming audio

    "JC" <someone@somewh ere.com> wrote in message
    news:cb3a21485c 4b4d34854717735 9d7795d@ureader .com...[color=blue]
    > I have to play a streaming audio.[/color]

    You should post questions on playing audio in the multimedia group

    microsoft.publi c.win32.program mer.mmedia
    [color=blue]
    > So in a thread I play audio as follow
    >
    > thread{
    > //some code
    > for(;;){
    > //some code
    > waveOutPrepareH eader(hwo, &(whdr), sizeof(WAVEHDR) );
    > waveOutWrite(hw o, &(whdr), sizeof(WAVEHDR) );
    >
    > while(finish == 0){} //will set in callback func
    >
    > waveOutUnprepar eHeader(hwo, &(whdr), sizeof(WAVEHDR) );[/color]

    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.
    [color=blue]
    > However, the sound is played not smooth. I think that the PrepareHeader
    > and
    > UnPrepareHeader should not be called so frequntly. Am I right?[/color]

    I am told that there are devices for which you must do that. I consider
    those devices "broken" and choose not to support them.
    [color=blue]
    > 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?[/color]

    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


    Comment

    Working...