|
@@ -227,61 +227,35 @@ static void DSOUND_DetectDevices(SDL_AudioDevice **default_output, SDL_AudioDevi
|
|
|
|
|
|
static void DSOUND_WaitDevice(SDL_AudioDevice *device)
|
|
|
{
|
|
|
- DWORD status = 0;
|
|
|
- DWORD cursor = 0;
|
|
|
- DWORD junk = 0;
|
|
|
- HRESULT result = DS_OK;
|
|
|
-
|
|
|
/* Semi-busy wait, since we have no way of getting play notification
|
|
|
on a primary mixing buffer located in hardware (DirectX 5.0)
|
|
|
*/
|
|
|
- result = IDirectSoundBuffer_GetCurrentPosition(device->hidden->mixbuf,
|
|
|
- &junk, &cursor);
|
|
|
- if (result != DS_OK) {
|
|
|
- if (result == DSERR_BUFFERLOST) {
|
|
|
- IDirectSoundBuffer_Restore(device->hidden->mixbuf);
|
|
|
- }
|
|
|
-#ifdef DEBUG_SOUND
|
|
|
- SetDSerror("DirectSound GetCurrentPosition", result);
|
|
|
-#endif
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- while ((cursor / device->buffer_size) == device->hidden->lastchunk) {
|
|
|
- if (SDL_AtomicGet(&device->shutdown)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- SDL_Delay(1);
|
|
|
+ while (!SDL_AtomicGet(&device->shutdown)) {
|
|
|
+ DWORD status = 0;
|
|
|
+ DWORD cursor = 0;
|
|
|
+ DWORD junk = 0;
|
|
|
+ HRESULT result = DS_OK;
|
|
|
|
|
|
// Try to restore a lost sound buffer
|
|
|
IDirectSoundBuffer_GetStatus(device->hidden->mixbuf, &status);
|
|
|
if (status & DSBSTATUS_BUFFERLOST) {
|
|
|
IDirectSoundBuffer_Restore(device->hidden->mixbuf);
|
|
|
- IDirectSoundBuffer_GetStatus(device->hidden->mixbuf, &status);
|
|
|
- if (status & DSBSTATUS_BUFFERLOST) {
|
|
|
- break;
|
|
|
+ } else if (!(status & DSBSTATUS_PLAYING)) {
|
|
|
+ result = IDirectSoundBuffer_Play(device->hidden->mixbuf, 0, 0, DSBPLAY_LOOPING);
|
|
|
+ } else {
|
|
|
+ // Find out where we are playing
|
|
|
+ result = IDirectSoundBuffer_GetCurrentPosition(device->hidden->mixbuf, &junk, &cursor);
|
|
|
+ if ((result == DS_OK) && ((cursor / device->buffer_size) != device->hidden->lastchunk)) {
|
|
|
+ break; // ready for next chunk!
|
|
|
}
|
|
|
}
|
|
|
- if (!(status & DSBSTATUS_PLAYING)) {
|
|
|
- result = IDirectSoundBuffer_Play(device->hidden->mixbuf, 0, 0,
|
|
|
- DSBPLAY_LOOPING);
|
|
|
- if (result == DS_OK) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-#ifdef DEBUG_SOUND
|
|
|
- SetDSerror("DirectSound Play", result);
|
|
|
-#endif
|
|
|
- return;
|
|
|
- }
|
|
|
|
|
|
- // Find out where we are playing
|
|
|
- result = IDirectSoundBuffer_GetCurrentPosition(device->hidden->mixbuf,
|
|
|
- &junk, &cursor);
|
|
|
- if (result != DS_OK) {
|
|
|
- SetDSerror("DirectSound GetCurrentPosition", result);
|
|
|
+ if ((result != DS_OK) && (result != DSERR_BUFFERLOST)) {
|
|
|
+ SDL_AudioDeviceDisconnected(device);
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ SDL_Delay(1); // not ready yet; sleep a bit.
|
|
|
}
|
|
|
}
|
|
|
|