[sdlsound] SDL_Sound Win32 sample ?

R Bresner robert at simtrek.com
Wed Oct 2 07:36:11 EDT 2002

Ryan C. Gordon wrote:
>>Now, I'm trying now to make it more Windows friendly. That is,
>>I'm trying to use a timer callback for reading data instead of
>>the, for example, sdl_desired.callback.
>>SDL_OpenAudio fails with a NULL callback, however, and WM_TIMER
>>callbacks don't quit fit the sdl_desired world.
> The callback is running in a separate thread; do you really need to use a
> timer event?
> --ryan.

Howdy --

Well, I'm not very sure which is the best/right way to do it.

I think I may have figured out a way to do what I meant
I want to do... versus what I managed to write in my first email.
I'm using the WM_TIMER to SDL_Decode() and update my GUI.
Then I'm filling the stream from my buffer in the callback.

There's a bit of skipping tho, that I can't account for.
I've got samples=8129, decode buf=32786, audio buf=16384.
And a callback that looks like this:

void mp3AudioCallback(void *userdata, Uint8 *stream, int len)
	int bw;
	static int pos = 0;
	static Uint8 *bpos = 0;

	if( bpos == 0 ) {
		bpos = decoded_buffer;

	if( pos + len > nBufferSize )
		len = nBufferSize - pos;
	memcpy(stream, bpos, len );
	bpos += len;
	pos += len;
	if( len == 0 ) {
		// finished playing buffer.

void *decoded_buffer and Uint32 nBufferSize are currently a couple
global vars.

So. Am I going about this entirely wrong? What is causing
the skipping? Why is the sky blue? Why do birds sing?

How many surrealists does it take to change a light bulb?
Pink elephant.



More information about the sdlsound mailing list