From 02a53226aba763d73d32e75552d94a2d2f9616b4 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 8 Jul 2007 13:28:15 +0000 Subject: [PATCH] "Fix" #471, shortened the buffer down to 250 ms (instead of 1500 ms) and tightened the loop filling it to run every 100 ms instead of every 500. Result is that it's almost impossible to reproduce the problem now. (It pretty much takes superhuman reflexes.) Originally committed to SVN as r1393. --- aegisub/audio_player_dsound.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/aegisub/audio_player_dsound.cpp b/aegisub/audio_player_dsound.cpp index 7c87a060c..6731bb121 100644 --- a/aegisub/audio_player_dsound.cpp +++ b/aegisub/audio_player_dsound.cpp @@ -182,7 +182,8 @@ void DirectSoundPlayer::OpenStream() { waveFormat.cbSize = 0; // Create the buffer initializer - int aim = waveFormat.nAvgBytesPerSec + waveFormat.nAvgBytesPerSec/2; // one and a half second of buffer + //int aim = waveFormat.nAvgBytesPerSec + waveFormat.nAvgBytesPerSec/2; // one and a half second of buffer + int aim = waveFormat.nAvgBytesPerSec / 4; // quarter second of buffer int min = DSBSIZE_MIN; int max = DSBSIZE_MAX; bufSize = MIN(MAX(min,aim),max); @@ -423,7 +424,7 @@ DirectSoundPlayerThread::~DirectSoundPlayerThread() { wxThread::ExitCode DirectSoundPlayerThread::Entry() { // Wake up thread every half second to fill buffer as needed // This more or less assumes the buffer is at least one second long - while (WaitForSingleObject(stopnotify, 500) == WAIT_TIMEOUT) { + while (WaitForSingleObject(stopnotify, 100) == WAIT_TIMEOUT) { if (!parent->FillBuffer(false)) { // FillBuffer returns false when end of stream is reached wxLogDebug(_T("DS thread hit end of stream")); @@ -433,7 +434,7 @@ wxThread::ExitCode DirectSoundPlayerThread::Entry() { // Now fill buffer with silence DWORD bytesFilled = 0; - while (WaitForSingleObject(stopnotify, 500) == WAIT_TIMEOUT) { + while (WaitForSingleObject(stopnotify, 100) == WAIT_TIMEOUT) { void *buf1, *buf2; DWORD size1, size2; DWORD playpos; @@ -452,7 +453,7 @@ wxThread::ExitCode DirectSoundPlayerThread::Entry() { parent->offset = (parent->offset + size1 + size2) % parent->bufSize; } - WaitForSingleObject(stopnotify, 1500); + WaitForSingleObject(stopnotify, 300); wxLogDebug(_T("DS thread dead"));