Re: Looping Streamed Audio Using WaveOut



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".
>
.



Relevant Pages

  • Re: why I can not write to the file after initialize the MFC in a service program
    ... you check EVERY return from a call that can fail, ... Why do you need an intermedate buffer to write literal strings anyway? ... For example, if AfxWinInit fails, you copy a 45-character string into a ... So you are going to try to initialize MFC EACH TIME THROUGH THE LOOP? ...
    (microsoft.public.vc.mfc)
  • Re: why I can not write to the file after initialize the MFC in a service program
    ... you check EVERY return from a call that can fail, and any file system call can fail, ... Why do you need an intermedate buffer to write literal strings anyway? ... For example, if AfxWinInit fails, you copy a 45-character string into a 30-character ... So you are going to try to initialize MFC EACH TIME THROUGH THE LOOP? ...
    (microsoft.public.vc.mfc)
  • Re: Learning to stream audio from a file
    ... >> event handle, a thread that is started before waveOutWrite, and a public ... > dwBufferLength is set before resubmitting the buffer. ... the while loop is what I've been wondering about adding. ...
    (microsoft.public.win32.programmer.mmedia)
  • Re: 2.6.11-rc1-mm1
    ... the only way this will fail is if an interrupt occurred ... index value needs to get reloaded from memory each time around the loop. ... > Frankly this is legacy code for when ltt only supported one trace buffer, ... As Roman suggested, relayfs ...
    (Linux-Kernel)
  • Re: Count Lines in (Huge) Text Files
    ... A few years ago, I was doing some high-throughput disk stuff and my recollection is that I found the same thing you did: larger buffers only helped up to about 8K or so, and past that any improvement was minimal. ... me that with appropriate settings for its buffer, it should perform better, since it ought to be optimized for line-based i/o. ... Assuming what's hurting you in the explicit forloop is the retrieval of the data and not the counter increment, the above should perform basically as well as a plain foreach() loop. ...
    (microsoft.public.dotnet.languages.csharp)