mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-21 05:53:12 -07:00
Fix switch audio delay with SDL_ClearQueuedAudio
This commit is contained in:
parent
e531a90d26
commit
b9a9ea497c
1 changed files with 10 additions and 0 deletions
|
@ -291,6 +291,16 @@ void IO::AudioCB(int16_t *buf, size_t samples_count)
|
|||
else
|
||||
buf[x] = (int16_t)sample;
|
||||
}
|
||||
|
||||
int audio_queued_size = SDL_GetQueuedAudioSize(this->sdl_audio_device_id);
|
||||
if(audio_queued_size > 16000)
|
||||
{
|
||||
// clear audio queue to avoid big audio delay
|
||||
// average values are close to 13000 bytes
|
||||
CHIAKI_LOGW(this->log, "Triggering SDL_ClearQueuedAudio with queue size = %d", audio_queued_size);
|
||||
SDL_ClearQueuedAudio(this->sdl_audio_device_id);
|
||||
}
|
||||
|
||||
int success = SDL_QueueAudio(this->sdl_audio_device_id, buf, sizeof(int16_t) * samples_count * 2);
|
||||
if(success != 0)
|
||||
CHIAKI_LOGE(this->log, "SDL_QueueAudio failed: %s\n", SDL_GetError());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue