diff src/audio/windx5/SDL_dx5audio.c @ 118:7c47e511459d

Fix noise when starting audio under DX5 (thanks Jesse!)
author Sam Lantinga <slouken@libsdl.org>
date Sun, 22 Jul 2001 21:25:22 +0000
parents 74212992fb08
children add626b825bb
line wrap: on
line diff
--- 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);
 }