comparison 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
comparison
equal deleted inserted replaced
117:aac75d5f7869 118:7c47e511459d
493 number of audio chunks available in the created buffer. 493 number of audio chunks available in the created buffer.
494 */ 494 */
495 static int CreateSecondary(LPDIRECTSOUND sndObj, HWND focus, 495 static int CreateSecondary(LPDIRECTSOUND sndObj, HWND focus,
496 LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize) 496 LPDIRECTSOUNDBUFFER *sndbuf, WAVEFORMATEX *wavefmt, Uint32 chunksize)
497 { 497 {
498 const int numchunks = 2;
498 HRESULT result; 499 HRESULT result;
499 DSBUFFERDESC format; 500 DSBUFFERDESC format;
500 const int numchunks = 2; 501 LPVOID pvAudioPtr1, pvAudioPtr2;
502 DWORD dwAudioBytes1, dwAudioBytes2;
501 503
502 /* Try to set primary mixing privileges */ 504 /* Try to set primary mixing privileges */
503 if ( focus ) { 505 if ( focus ) {
504 result = IDirectSound_SetCooperativeLevel(sndObj, 506 result = IDirectSound_SetCooperativeLevel(sndObj,
505 focus, DSSCL_PRIORITY); 507 focus, DSSCL_PRIORITY);
538 SetDSerror("DirectSound CreateSoundBuffer", result); 540 SetDSerror("DirectSound CreateSoundBuffer", result);
539 return(-1); 541 return(-1);
540 } 542 }
541 IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt); 543 IDirectSoundBuffer_SetFormat(*sndbuf, wavefmt);
542 544
545 /* Silence the initial audio buffer */
546 result = IDirectSoundBuffer_Lock(*sndbuf, 0, format.dwBufferBytes,
547 (LPVOID *)&pvAudioPtr1, &dwAudioBytes1,
548 (LPVOID *)&pvAudioPtr2, &dwAudioBytes2,
549 DSBLOCK_ENTIREBUFFER);
550 if ( result == DS_OK ) {
551 if ( wavefmt->wBitsPerSample == 8 ) {
552 memset(pvAudioPtr1, 0x80, dwAudioBytes1);
553 } else {
554 memset(pvAudioPtr1, 0x00, dwAudioBytes1);
555 }
556 IDirectSoundBuffer_Unlock(*sndbuf,
557 (LPVOID)pvAudioPtr1, dwAudioBytes1,
558 (LPVOID)pvAudioPtr2, dwAudioBytes2);
559 }
560
543 /* We're ready to go */ 561 /* We're ready to go */
544 return(numchunks); 562 return(numchunks);
545 } 563 }
546 564
547 /* This function tries to set position notify events on the mixing buffer */ 565 /* This function tries to set position notify events on the mixing buffer */