[GD-Windows] Streaming WAVE audio
Brought to you by:
vexxed72
From: Brian H. <bri...@py...> - 2002-04-27 21:34:03
|
Yes, it's me with a remedial, way-back, old-school question. However, this is because I'm working on WinCE 3.0 (my God, all those WinCE docs that show up in MSDN searches now MEAN something!). Since WinCE/PPC2K lack Direct Sound, I have to do my own audio mixing into wave buffers. Conceptually, this is simple, although some of the implementation details were a bit tough to find out (specifically, using a thread instead of a callback). In a nutshell, I'm doing this in the straightforward fashion you'd expect, double buffering two audio buffers that are filled periodically. fill( buffer[ 0 ] ); fill( buffer[ 1 ] ); Under Win32's waveOut interface, you can specify a thread to handle messages indicating WOM_DONE, WOM_OPEN, WOM_CLOSE. This is pretty easy, you just CreateThread() and pass the identifier and CALLBACK_FUNCTION to waveOut Open. That much works. The thread function basically does this: while ( GetMessage( ... ) { if ( msg == WOM_DONE ) { waveOutWrite( nextBuffer ); fill( bufferThatJustEnded ); } } The above works as well, in that it doesn't crash =) That's all a streaming WAVE audio subsystem should really need to do. Of course, I do the necessary waveOutPrepareHeader, etc. I'm doing this in 8-bit, mono, 11KHz format, and the device definitely supports it. In fact, I have this code running on Win2000 just so that I can make sure it works on a desktop before moving to a PDA. So the problem is that I'm getting dropouts and stuttering, echoing, and a host of other bad things. I boosted the thread's priority to highest, and I also set my buffers to some arbitrarily huge sizes to see if it was underruns to no avail. I check all the return values. Everything looks fine. I timed calls to WOM_DONE handling, and the delta times are the expected buffer sizes. The mixing code is the same for OS X and DirectSound and works as expected. Each buffer is 150ms, more than enough time to mix in some stuff (especially on a P3/1000). So I'm at a loss what else could be causing problems. Originally I was using a CALLBACK_FUNCTION, but that's somewhat problematic for other reasons (you can't call waveOutXXX functions within the callback, since that can cause a deadlock). Any suggestions on what else to look for that could be causing problems? Brian |