REALLY fixed DSound playback this time.
Originally committed to SVN as r1113.
This commit is contained in:
parent
cf2d2ff5d4
commit
ba944fd9b2
1 changed files with 11 additions and 8 deletions
|
@ -273,9 +273,6 @@ RetryLock:
|
||||||
// Error
|
// Error
|
||||||
if (FAILED(res)) return false;
|
if (FAILED(res)) return false;
|
||||||
|
|
||||||
// Update offset
|
|
||||||
offset = (offset + toWrite) % bufSize;
|
|
||||||
|
|
||||||
// Convert size to number of samples
|
// Convert size to number of samples
|
||||||
unsigned long int count1 = size1 / bytesps;
|
unsigned long int count1 = size1 / bytesps;
|
||||||
unsigned long int count2 = size2 / bytesps;
|
unsigned long int count2 = size2 / bytesps;
|
||||||
|
@ -306,6 +303,9 @@ RetryLock:
|
||||||
// Unlock
|
// Unlock
|
||||||
buffer->Unlock(ptr1,count1*bytesps,ptr2,count2*bytesps);
|
buffer->Unlock(ptr1,count1*bytesps,ptr2,count2*bytesps);
|
||||||
|
|
||||||
|
// Update offset
|
||||||
|
offset = (offset + count1*bytesps + count2*bytesps) % bufSize;
|
||||||
|
|
||||||
return delta==0; // If delta>0 we hit end of stream
|
return delta==0; // If delta>0 we hit end of stream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ DirectSoundPlayerThread::~DirectSoundPlayerThread() {
|
||||||
wxThread::ExitCode DirectSoundPlayerThread::Entry() {
|
wxThread::ExitCode DirectSoundPlayerThread::Entry() {
|
||||||
// Wake up thread every half second to fill buffer as needed
|
// Wake up thread every half second to fill buffer as needed
|
||||||
// This more or less assumes the buffer is at least one second long
|
// This more or less assumes the buffer is at least one second long
|
||||||
while (WaitForSingleObject(stopnotify, 500)) {
|
while (WaitForSingleObject(stopnotify, 500) == WAIT_TIMEOUT) {
|
||||||
if (!parent->FillBuffer(false)) {
|
if (!parent->FillBuffer(false)) {
|
||||||
// FillBuffer returns false when end of stream is reached
|
// FillBuffer returns false when end of stream is reached
|
||||||
wxLogDebug(_T("DS thread hit end of stream"));
|
wxLogDebug(_T("DS thread hit end of stream"));
|
||||||
|
@ -431,27 +431,30 @@ wxThread::ExitCode DirectSoundPlayerThread::Entry() {
|
||||||
|
|
||||||
// Now fill buffer with silence
|
// Now fill buffer with silence
|
||||||
DWORD bytesFilled = 0;
|
DWORD bytesFilled = 0;
|
||||||
while (WaitForSingleObject(stopnotify, 500)) {
|
while (WaitForSingleObject(stopnotify, 500) == WAIT_TIMEOUT) {
|
||||||
void *buf1, *buf2;
|
void *buf1, *buf2;
|
||||||
DWORD size1, size2;
|
DWORD size1, size2;
|
||||||
DWORD playpos;
|
DWORD playpos;
|
||||||
HRESULT res;
|
HRESULT res;
|
||||||
res = parent->buffer->GetCurrentPosition(&playpos, NULL);
|
res = parent->buffer->GetCurrentPosition(&playpos, NULL);
|
||||||
if (FAILED(res)) break;
|
if (FAILED(res)) break;
|
||||||
res = parent->buffer->Lock(parent->offset, (playpos-parent->offset)%parent->bufSize, &buf1, &size1, &buf2, &size2, 0);
|
int toWrite = playpos - parent->offset;
|
||||||
|
while (toWrite < 0) toWrite += parent->bufSize;
|
||||||
|
res = parent->buffer->Lock(parent->offset, toWrite, &buf1, &size1, &buf2, &size2, 0);
|
||||||
if (FAILED(res)) break;
|
if (FAILED(res)) break;
|
||||||
parent->offset = (parent->offset + size1 + size2) % parent->bufSize;
|
|
||||||
if (size1) memset(buf1, 0, size1);
|
if (size1) memset(buf1, 0, size1);
|
||||||
if (size2) memset(buf2, 0, size2);
|
if (size2) memset(buf2, 0, size2);
|
||||||
bytesFilled += size1 + size2;
|
bytesFilled += size1 + size2;
|
||||||
parent->buffer->Unlock(buf1, size1, buf2, size2);
|
parent->buffer->Unlock(buf1, size1, buf2, size2);
|
||||||
if (bytesFilled >= parent->bufSize) break;
|
if (bytesFilled >= parent->bufSize) break;
|
||||||
|
parent->offset = (parent->offset + size1 + size2) % parent->bufSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WaitForSingleObject(stopnotify, 1500);
|
||||||
|
|
||||||
wxLogDebug(_T("DS thread dead"));
|
wxLogDebug(_T("DS thread dead"));
|
||||||
|
|
||||||
parent->playing = false;
|
parent->playing = false;
|
||||||
WaitForSingleObject(stopnotify, 1500);
|
|
||||||
parent->buffer->Stop();
|
parent->buffer->Stop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue