From 0718cf5a2c718fab06ccb6e67fcbb8ca35a34da9 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 29 Jul 2007 21:00:57 +0000 Subject: [PATCH] Hack: Use a single-play (non-looping) buffer for very short samples that fit entirely in the buffer for DSound playback. This avoids unwanted repeating of very short samples, but also makes it impossible to extend these selections to continue playback. Fixing the real problem could prove to be very hard or even impossible, as it seems to be a problem of timing and possibly even related to the time slices allocated by the OS. As a buffer size in the DSound player is fixed at 150 ms the side-effect of this hack hopefully won't be a real problem. Originally committed to SVN as r1460. --- aegisub/audio_player_dsound.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/aegisub/audio_player_dsound.cpp b/aegisub/audio_player_dsound.cpp index 69d54ef04..98f3ddd22 100644 --- a/aegisub/audio_player_dsound.cpp +++ b/aegisub/audio_player_dsound.cpp @@ -337,14 +337,18 @@ void DirectSoundPlayer::Play(__int64 start,__int64 count) { // Fill whole buffer FillBuffer(true); - // Start thread - thread = new DirectSoundPlayerThread(this); - thread->Create(); - thread->Run(); + DWORD play_flag = 0; + if (count > bufSize) { + // Start thread + thread = new DirectSoundPlayerThread(this); + thread->Create(); + thread->Run(); + play_flag = DSBPLAY_LOOPING; + } // Play buffer->SetCurrentPosition(0); - res = buffer->Play(0,0,DSBPLAY_LOOPING); + res = buffer->Play(0,0,play_flag); if (SUCCEEDED(res)) playing = true; startTime = GetTickCount();