# HG changeset patch # User Sam Lantinga # Date 995837122 0 # Node ID 7c47e511459dadf5d6885f66ed26498d9472f946 # Parent aac75d5f7869666bccea330b8b70bb70ec7cba01 Fix noise when starting audio under DX5 (thanks Jesse!) diff -r aac75d5f7869 -r 7c47e511459d src/audio/windx5/SDL_dx5audio.c --- a/src/audio/windx5/SDL_dx5audio.c Sun Jul 22 20:57:24 2001 +0000 +++ b/src/audio/windx5/SDL_dx5audio.c Sun Jul 22 21:25:22 2001 +0000 @@ -495,9 +495,11 @@ static int CreateSecondary(LPDIRECTSOUND sndObj, HWND focus, LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize) { + const int numchunks = 2; HRESULT result; DSBUFFERDESC format; - const int numchunks = 2; + LPVOID pvAudioPtr1, pvAudioPtr2; + DWORD dwAudioBytes1, dwAudioBytes2; /* Try to set primary mixing privileges */ if ( focus ) { @@ -540,6 +542,22 @@ } IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt); + /* Silence the initial audio buffer */ + result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes, + (LPVOID *)&pvAudioPtr1, &dwAudioBytes1, + (LPVOID *)&pvAudioPtr2, &dwAudioBytes2, + DSBLOCK_ENTIREBUFFER); + if ( result == DS_OK ) { + if ( wavefmt->wBitsPerSample == 8 ) { + memset(pvAudioPtr1, 0x80, dwAudioBytes1); + } else { + memset(pvAudioPtr1, 0x00, dwAudioBytes1); + } + IDirectSoundBuffer_Unlock(*sndbuf, + (LPVOID)pvAudioPtr1, dwAudioBytes1, + (LPVOID)pvAudioPtr2, dwAudioBytes2); + } + /* We're ready to go */ return(numchunks); }