Fix noise when starting audio under DX5 (thanks Jesse!)
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Jul 2001 21:25:22 +0000
changeset 118 7c47e511459d
parent 117 aac75d5f7869
child 119 c2f7f5bb8cbd
Fix noise when starting audio under DX5 (thanks Jesse!)
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);
 }