fixed audio sync not working in DirectSound

This commit is contained in:
spacy51 2007-12-06 15:06:43 +00:00
parent 9007a9b262
commit 54284bd177
1 changed files with 6 additions and 19 deletions

View File

@ -35,7 +35,6 @@
#pragma comment( lib, "Dsound" ) #pragma comment( lib, "Dsound" )
#pragma comment( lib, "Dxguid" ) #pragma comment( lib, "Dxguid" )
int soundBufferTotalLen = 14700;
extern bool soundBufferLow; extern bool soundBufferLow;
extern void setsystemSoundOn(bool value); extern void setsystemSoundOn(bool value);
@ -48,7 +47,7 @@ private:
LPDIRECTSOUNDNOTIFY8 dsbNotify; LPDIRECTSOUNDNOTIFY8 dsbNotify;
HANDLE dsbEvent; HANDLE dsbEvent;
WAVEFORMATEX wfx; // Primary buffer wave format WAVEFORMATEX wfx; // Primary buffer wave format
int soundBufferTotalLen;
public: public:
DirectSound(); DirectSound();
@ -72,6 +71,7 @@ DirectSound::DirectSound()
dsbNotify = NULL; dsbNotify = NULL;
dsbEvent = NULL; dsbEvent = NULL;
soundBufferTotalLen = 14700;
} }
@ -155,21 +155,8 @@ bool DirectSound::init()
return false; return false;
} }
switch(soundQuality) freq = 44100 / soundQuality;
{ soundBufferLen = freq*2*2/60;
case 4:
freq = 11025;
break;
case 2:
freq = 22050;
break;
default:
soundQuality = 1;
case 1:
freq = 44100;
break;
}
soundBufferLen = freq/60*4;
soundBufferTotalLen = soundBufferLen * 10; soundBufferTotalLen = soundBufferLen * 10;
ZeroMemory( &wfx, sizeof(WAVEFORMATEX) ); ZeroMemory( &wfx, sizeof(WAVEFORMATEX) );
@ -313,7 +300,7 @@ void DirectSound::write()
if( !speedup && synchronize && !theApp.throttle ) { if( !speedup && synchronize && !theApp.throttle ) {
hr = dsbSecondary->GetStatus(&status); hr = dsbSecondary->GetStatus(&status);
if( status & DSBSTATUS_PLAYING ) { if( status & DSBSTATUS_PLAYING ) {
if( soundPaused ) { if( !soundPaused ) {
while( true ) { while( true ) {
dsbSecondary->GetCurrentPosition(&play, NULL); dsbSecondary->GetCurrentPosition(&play, NULL);
int BufferLeft = ((soundNextPosition <= play) ? int BufferLeft = ((soundNextPosition <= play) ?