Fix noise when starting audio under DX5 (thanks Jesse!)
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Jul 2001 21:25:22 +0000
changeset 1187c47e511459d
parent 117 aac75d5f7869
child 119 c2f7f5bb8cbd
Fix noise when starting audio under DX5 (thanks Jesse!)
src/audio/windx5/SDL_dx5audio.c
     1.1 --- a/src/audio/windx5/SDL_dx5audio.c	Sun Jul 22 20:57:24 2001 +0000
     1.2 +++ b/src/audio/windx5/SDL_dx5audio.c	Sun Jul 22 21:25:22 2001 +0000
     1.3 @@ -495,9 +495,11 @@
     1.4  static int CreateSecondary(LPDIRECTSOUND sndObj, HWND focus,
     1.5  	LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize)
     1.6  {
     1.7 +	const int numchunks = 2;
     1.8  	HRESULT result;
     1.9  	DSBUFFERDESC format;
    1.10 -	const int numchunks = 2;
    1.11 +	LPVOID pvAudioPtr1, pvAudioPtr2;
    1.12 +	DWORD  dwAudioBytes1, dwAudioBytes2;
    1.13  
    1.14  	/* Try to set primary mixing privileges */
    1.15  	if ( focus ) {
    1.16 @@ -540,6 +542,22 @@
    1.17  	}
    1.18  	IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);
    1.19  
    1.20 +	/* Silence the initial audio buffer */
    1.21 +	result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes,
    1.22 +	                                 (LPVOID *)&pvAudioPtr1, &dwAudioBytes1,
    1.23 +	                                 (LPVOID *)&pvAudioPtr2, &dwAudioBytes2,
    1.24 +	                                 DSBLOCK_ENTIREBUFFER);
    1.25 +	if ( result == DS_OK ) {
    1.26 +		if ( wavefmt->wBitsPerSample == 8 ) {
    1.27 +			memset(pvAudioPtr1, 0x80, dwAudioBytes1);
    1.28 +		} else {
    1.29 +			memset(pvAudioPtr1, 0x00, dwAudioBytes1);
    1.30 +		}
    1.31 +		IDirectSoundBuffer_Unlock(*sndbuf,
    1.32 +		                          (LPVOID)pvAudioPtr1, dwAudioBytes1,
    1.33 +		                          (LPVOID)pvAudioPtr2, dwAudioBytes2);
    1.34 +	}
    1.35 +
    1.36  	/* We're ready to go */
    1.37  	return(numchunks);
    1.38  }