Re: Looping Streamed Audio Using WaveOut
- From: Ben <cinele@xxxxxxxxxxxxxxxx>
- Date: Tue, 26 Jul 2005 05:30:03 -0700
Hmmm...didn't know it wasn't fully documented yet. Well, so far what I have
been doing is creating 20 8kb buffers and filling each buffer with data, then
preparing each buffer, and finally sending it to waveoutwrite. I was wanting
to do this with the loop flags, so after I ran through the file once, I could
break back into the main loop while the audio driver played the rest of the
loops. I guess what your telling me is that I have to wait there for the end
of the file, and restart filling the buffers every time we come close to the
end of the file? Is this something that I should do in a seperate thread?
If so, how exactly? I have tried to create seperate threads, but have not
had success yet. Here is a little of my code that takes the data from the
file to the buffer, and then calls a function to prepare the header and call
waveOutwrite.
if(waveOutOpen(&hWaveOut,WAVE_MAPPER,&wfx,(DWORD_PTR)PlayXP::waveOutProc, (DWORD_PTR)&waveFreeBlockCount,CALLBACK_FUNCTION
) != MMSYSERR_NOERROR)
{
ExitProcess(1);
}
/*
* playback loop
*/
while(1) {
DWORD readBytes;
f = f + 1;
if(!ReadFile(hFile, buffer, sizeof(buffer), &readBytes, NULL))
break;
if(readBytes == 0)
break;
if(readBytes < sizeof(buffer))
{
memset(buffer + readBytes, 0, sizeof(buffer) - readBytes);
}
PlayXP::writeAudio(hWaveOut, buffer, sizeof(buffer));
//prepares header and sends buffer to waveOutwrite
}
/*
* wait for all blocks to complete
*/
while(waveFreeBlockCount < BLOCK_COUNT)
Sleep(10);
/*
* unprepare any blocks that are still prepared
*/
for(i = 0; i < waveFreeBlockCount; i++)
if(waveBlocks[i].dwFlags & WHDR_PREPARED)
waveOutUnprepareHeader(hWaveOut, &waveBlocks[i], sizeof(WAVEHDR));
DeleteCriticalSection(&waveCriticalSection);
PlayXP::freeBlocks(waveBlocks);
waveOutClose(hWaveOut);
CloseHandle(hFile);
--
Ben
"Chris P. [MVP]" wrote:
> On Mon, 25 Jul 2005 14:21:02 -0700, Ben wrote:
>
> > I am using VC++.net on winXP. So far I have been able to pass blocks of
> > audio data to the waveoutwrite function and play audio fine. The problem I
> > am having now is that when I try and loop the data using the dwFlags, it
> > plays the first block, and then loops it forever. If I set both the
> > WHDR_BeginLoop and EndLoop flags for the same block, it loops the block the
> > set amount of times I specify. I have looked on MSDN and found this page
> > that describes how to loop streamed
> > audio(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcewave/html/_wcesdk_looping_playback.asp),
> > but it seems that it is not letting me pass more audio blocks to the
> > waveoutwrite function after I set the WHDR_BeginLoop dwFlag before it starts
> > looping. Any Suggestions?
>
> Don't use the loop flags, their support and documentation is not exactly
> complete.
>
> Only ever send streams to waveOutWrite(), you can create your own software
> loops by repeatedly sending data as required. You need at least 2 buffers
> in order to "stream".
>
.
- Follow-Ups:
- Re: Looping Streamed Audio Using WaveOut
- From: Chris P. [MVP]
- Re: Looping Streamed Audio Using WaveOut
- References:
- Looping Streamed Audio Using WaveOut
- From: Ben
- Re: Looping Streamed Audio Using WaveOut
- From: Chris P. [MVP]
- Looping Streamed Audio Using WaveOut
- Prev by Date: Re: Controling printers at a detailed level
- Next by Date: Re: Controling printers at a detailed level
- Previous by thread: Re: Looping Streamed Audio Using WaveOut
- Next by thread: Re: Looping Streamed Audio Using WaveOut
- Index(es):
Relevant Pages
|