From b01e579c2aaaee03b9f7ddf2bef41ed89e395e95 Mon Sep 17 00:00:00 2001 From: spacy51 Date: Thu, 6 Dec 2007 15:06:43 +0000 Subject: [PATCH] fixed audio sync not working in DirectSound git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@173 a31d4220-a93d-0410-bf67-fe4944624d44 --- src/win32/DirectSound.cpp | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/win32/DirectSound.cpp b/src/win32/DirectSound.cpp index 6831bf1c..2fe9da60 100644 --- a/src/win32/DirectSound.cpp +++ b/src/win32/DirectSound.cpp @@ -35,7 +35,6 @@ #pragma comment( lib, "Dsound" ) #pragma comment( lib, "Dxguid" ) -int soundBufferTotalLen = 14700; extern bool soundBufferLow; extern void setsystemSoundOn(bool value); @@ -48,8 +47,8 @@ private: LPDIRECTSOUNDNOTIFY8 dsbNotify; HANDLE dsbEvent; WAVEFORMATEX wfx; // Primary buffer wave format + int soundBufferTotalLen; - public: DirectSound(); virtual ~DirectSound(); @@ -71,7 +70,8 @@ DirectSound::DirectSound() dsbSecondary = NULL; dsbNotify = NULL; dsbEvent = NULL; - + + soundBufferTotalLen = 14700; } @@ -155,21 +155,8 @@ bool DirectSound::init() return false; } - switch(soundQuality) - { - case 4: - freq = 11025; - break; - case 2: - freq = 22050; - break; - default: - soundQuality = 1; - case 1: - freq = 44100; - break; - } - soundBufferLen = freq/60*4; + freq = 44100 / soundQuality; + soundBufferLen = freq*2*2/60; soundBufferTotalLen = soundBufferLen * 10; ZeroMemory( &wfx, sizeof(WAVEFORMATEX) ); @@ -313,7 +300,7 @@ void DirectSound::write() if( !speedup && synchronize && !theApp.throttle ) { hr = dsbSecondary->GetStatus(&status); if( status & DSBSTATUS_PLAYING ) { - if( soundPaused ) { + if( !soundPaused ) { while( true ) { dsbSecondary->GetCurrentPosition(&play, NULL); int BufferLeft = ((soundNextPosition <= play) ?