BUG (and fix): Noise when starting audio under DX5

Hey all, me again:

I noticed this bug the other day after I got sound working in my emulator.
Every time I would start the program, I’d hear a momentary hiss before the
actually sound began playing. It wasn’t until today that I debugged the
cause and found that it was due to the SDL code not clearing out the audio
buffers it had created. Even the loopwave.c demo exhibits this problem when
compiled for w32/dx.

The following should be added to SDL_dx5audio.cpp to eliminate the startup
static:

// in CreateSecondary…
LPVOID pvAudioPtr1, pvAudioPtr2 = NULL;
unsigned long dwAudioBytes1, dwAudioBytes2 = 0;

//… after creating the buffer
result = IDirectSoundBuffer_Lock(
*sndbuf,
0, // DWORD dwOffset,
format.dwBufferBytes, //8820, // DWORD dwBytes,
(LPVOID *)&pvAudioPtr1,
&dwAudioBytes1,
(LPVOID *)&pvAudioPtr2,
&dwAudioBytes2,
DSBLOCK_ENTIREBUFFER
);

if(result == DS_OK)
memset(pvAudioPtr1, 0, dwAudioBytes1);

IDirectSoundBuffer_Unlock(
*sndbuf,
(LPVOID)pvAudioPtr1,
dwAudioBytes1,
(LPVOID)pvAudioPtr2,
dwAudioBytes2
);

Later!
Jesse

Hey all, me again:

I noticed this bug the other day after I got sound working in my emulator.
Every time I would start the program, I’d hear a momentary hiss before the
actually sound began playing. It wasn’t until today that I debugged the
cause and found that it was due to the SDL code not clearing out the audio
buffers it had created. Even the loopwave.c demo exhibits this problem when
compiled for w32/dx.

Thanks! This is now fixed in CVS. :slight_smile:

See ya,
-Sam Lantinga, Lead Programmer, Loki Software, Inc.