Do not freeze the emulator while the melody plays

Playback waited for the sound card to drain before returning, and that runs
on the emulation thread: the whole emulator stopped for the length of the
take - 7.8 s of a 24.7 s hwtest run, measured - with the window not
repainting, which Windows paints as a hung application. Dropping a payload
on the picker looked like it had wedged.

Nothing needs the wait. The entire buffer is queued in one call before
playback starts, so SDL drains it in the background with no risk of
underrun; the device is simply left open for it. Same run is now 17.5 s with
no gap over 0.1 s, and the melody still plays in full.
This commit is contained in:
Baptiste MOINE committed 2026-08-20 10:50:24 +02:00
1 parent a71ccdf682
commit 9f6e96001c
1 file changed
+6 -7
+6 -7
View File
@@ -3027,13 +3027,12 @@ static void audio_play_take(void) {
(double)(audio_pcm.size() / 2) / (double)have.freq, have.freq); (double)(audio_pcm.size() / 2) / (double)have.freq, have.freq);
fflush(stdout); fflush(stdout);
// Wait it out, bounded, so the run cannot hang on a stuck device. // Deliberately does NOT wait for playback to finish. This runs on the
int guard = (int)(audio_pcm.size() / 2 / (size_t)have.freq) * 20 + 200; // emulation thread, so blocking here freezes the whole emulator for the
while (guard-- > 0 && SDL_GetQueuedAudioSize(audio_dev) > 0) // length of the take - nearly ten seconds for hwtest's melody - during
SDL_Delay(50); // which the window stops repainting and Windows paints it as hung. The
// whole buffer is already queued, so SDL drains it in the background
SDL_CloseAudioDevice(audio_dev); // while emulation carries on, and the device is left open for it.
audio_dev = 0;
} }