Fixed directsound player

Originally committed to SVN as r591.
This commit is contained in:
Rodrigo Braz Monteiro 2006-12-23 03:07:21 +00:00
parent 3ac1000cfa
commit b935075945
1 changed files with 7 additions and 13 deletions

View File

@ -39,7 +39,6 @@
/////////// ///////////
// Headers // Headers
#ifdef USE_DSOUND
#include <wx/wxprec.h> #include <wx/wxprec.h>
#include "audio_provider.h" #include "audio_provider.h"
#include "audio_player_dsound.h" #include "audio_player_dsound.h"
@ -179,7 +178,6 @@ void DirectSoundPlayer::FillBuffer(bool fill) {
if (endPos > playPos) left = endPos - playPos; if (endPos > playPos) left = endPos - playPos;
unsigned long int delta = 0; unsigned long int delta = 0;
if (totalCount > left) delta = totalCount - left; if (totalCount > left) delta = totalCount - left;
int extra = 0;
// If so, don't allow it // If so, don't allow it
if (delta) { if (delta) {
@ -191,17 +189,15 @@ void DirectSoundPlayer::FillBuffer(bool fill) {
int temp = MIN(delta,count2); int temp = MIN(delta,count2);
count2 -= temp; count2 -= temp;
delta -= temp; delta -= temp;
extra += temp;
temp = MIN(delta,count1); temp = MIN(delta,count1);
count1 -= temp; count1 -= temp;
delta -= temp; delta -= temp;
extra += temp;
} }
// Get source wave // Get source wave
if (count1) provider->GetAudio(ptr1,playPos,count1); if (count1) provider->GetAudio(ptr1,playPos,count1);
if (count2) provider->GetAudio(ptr2,playPos+count1,count2); if (count2) provider->GetAudio(ptr2,playPos+count1,count2);
playPos += count1 + count2 + extra; playPos += totalCount;
// Unlock // Unlock
buffer->Unlock(ptr1,size1,ptr2,size2); buffer->Unlock(ptr1,size1,ptr2,size2);
@ -288,6 +284,7 @@ void DirectSoundPlayer::Stop(bool timerToo) {
if (timerToo && displayTimer) { if (timerToo && displayTimer) {
displayTimer->Stop(); displayTimer->Stop();
} }
playing = false;
} }
@ -309,7 +306,7 @@ void DirectSoundPlayer::SetCurrentPosition(__int64 pos) {
// Get current position // Get current position
__int64 DirectSoundPlayer::GetCurrentPosition() { __int64 DirectSoundPlayer::GetCurrentPosition() {
// Check if buffer is loaded // Check if buffer is loaded
if (!buffer) return 0; if (!buffer || !playing) return 0;
// Read position // Read position
unsigned long int play,write; unsigned long int play,write;
@ -349,7 +346,7 @@ wxThread::ExitCode DirectSoundPlayerThread::Entry() {
while (parent->playing) { while (parent->playing) {
// Get variables // Get variables
parent->DSMutex.Lock(); parent->DSMutex.Lock();
playPos = parent->playPos; playPos = parent->GetCurrentPosition();
endPos = parent->endPos; endPos = parent->endPos;
bufSize = parent->bufSize; bufSize = parent->bufSize;
parent->DSMutex.Unlock(); parent->DSMutex.Unlock();
@ -357,19 +354,17 @@ wxThread::ExitCode DirectSoundPlayerThread::Entry() {
// Still playing? // Still playing?
if (playPos < endPos + bufSize/8) { if (playPos < endPos + bufSize/8) {
// Wait for signal // Wait for signal
WaitForSingleObject(parent->notificationEvent,5000); WaitForSingleObject(parent->notificationEvent,1000);
// Fill buffer // Fill buffer
parent->DSMutex.Lock(); //parent->DSMutex.Lock();
parent->FillBuffer(false); parent->FillBuffer(false);
parent->DSMutex.Unlock(); //parent->DSMutex.Unlock();
} }
// Over, stop it // Over, stop it
else { else {
parent->DSMutex.Lock();
parent->buffer->Stop(); parent->buffer->Stop();
parent->DSMutex.Unlock();
break; break;
} }
} }
@ -377,4 +372,3 @@ wxThread::ExitCode DirectSoundPlayerThread::Entry() {
Delete(); Delete();
return 0; return 0;
} }
#endif