RE: [GD-Windows] Streaming WAVE audio
Brought to you by:
vexxed72
From: Jon W. <hp...@mi...> - 2002-04-28 16:35:52
|
> I was counting on/assuming that the "waveOutWrite( nextBuffer )" would > eventually dispatch a buffer that was filled NUM_BUFFERS-1 notifications > ago, which apparently wasn't the case. Yeah, that'd do it. If you count it, you're running with only a single buffer, if this is what you're doing. > Changing it to this fixed it: > > waveOutWrite( nextBuffer ); > fillBuffer( completedBuffer ); > waveOutWrite( completedBuffer ); //keep the chain going This can't possibly work right, as you enqueue two buffers for each buffer played. I think you actually mean something else, such as just calling fillBuffer() and waveOutWrite(). For the benefit of other readers of this thread, I've always found this logic to be the most robust when playing audio: unsigned char buffers[3][SIZE]; int nextBuffer; setup: memset( buffers[0], QUIET, SIZE ); memset( buffers[1], QUIET, SIZE ); memset( buffers[2], QUIET, SIZE ); prepareBuffer( 0 ); prepareBuffer( 1 ); prepareBuffer( 2 ); nextBuffer = 0; start: queueBuffer( 0 ); queueBuffer( 1 ); queueBuffer( 2 ); completion: fillBuffer( nextBuffer ); queueBuffer( nextBuffer ); nextBuffer = (nextBuffer + 1) % 3; If there's a chance that you will lose completion events, then you can turn completion into a while loop: completion_with_misses: while( bufferDone( nextBuffer ) ) { fillBuffer( nextBuffer ); queueBuffer( nextBuffer ); nextBuffer = (nextBuffer + 1) % 3; } Note that this mechanism scales very well to different number of buffers, and the code is very clean and decision-free, which is always a plus. This structure will work fine with double-buffering (only two buffers) assuming the buffers are big enough for the inherent scheduling jitter of your platform (missing a single buffer in double-buffering means you'll probably hear it). Cheers, / h+ |