diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index 1ab847aa49..75e89797d4 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -678,6 +678,7 @@ static int SDLCALL SDL_RunAudio(void *userdata) int data_len = 0; Uint8 *data; Uint8 *device_buf_keepsafe = NULL; + Uint32 delay; SDL_assert(!device->iscapture); @@ -761,7 +762,7 @@ static int SDLCALL SDL_RunAudio(void *userdata) SDL_assert((got <= 0) || (got == device->spec.size)); if (data == NULL) { /* device is having issues... */ - const Uint32 delay = ((device->spec.samples * 1000) / device->spec.freq); + delay = ((device->spec.samples * 1000) / device->spec.freq); SDL_Delay(delay); /* wait for as long as this buffer would have played. Maybe device recovers later? */ } else { if (got != device->spec.size) { @@ -781,7 +782,7 @@ static int SDLCALL SDL_RunAudio(void *userdata) } } else if (data == device->work_buffer) { /* nothing to do; pause like we queued a buffer to play. */ - const Uint32 delay = ((device->spec.samples * 1000) / device->spec.freq); + delay = ((device->spec.samples * 1000) / device->spec.freq); SDL_Delay(delay); } else { /* writing directly to the device. */ /* queue this buffer and wait for it to finish playing. */ @@ -791,7 +792,11 @@ static int SDLCALL SDL_RunAudio(void *userdata) } /* Wait for the audio to drain. */ - SDL_Delay(((device->spec.samples * 1000) / device->spec.freq) * 2); + delay = ((device->spec.samples * 1000) / device->spec.freq) * 2; + if (delay > 100) { + delay = 100; + } + SDL_Delay(delay); current_audio.impl.ThreadDeinit(device); diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index b7d3edfaeb..120244ab00 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -472,6 +472,9 @@ static void ALSA_CloseDevice(_THIS) ALSA_snd_pcm_drop() can hang, so don't use that. */ Uint32 delay = ((this->spec.samples * 1000) / this->spec.freq) * 2; + if (delay > 100) { + delay = 100; + } SDL_Delay(delay); ALSA_snd_pcm_close(this->hidden->pcm_handle);