From 133adba10e8f8df3f3396a428e11831aa9018630 Mon Sep 17 00:00:00 2001 From: Dav999 Date: Tue, 28 Nov 2023 21:29:44 +0100 Subject: [PATCH] Fix remaining audio speedup/slowdown bug Fixes #1057. Based on Ethan's hunch, I simply removed the format comparison that decides whether to halt and restart, or reuse the voice. Voices are now always restarted when playing a new track. This also simplifies the code somewhat: `MusicTrack::musicVoiceFormat` was now no longer used, and an `if (!IsHalted())` was no longer necessary because `Halt()` already does that. So those are now removed as well. --- desktop_version/src/Music.cpp | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index 168a16da..b725940c 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -435,27 +435,12 @@ end: sample_pos = 0; stb_vorbis_seek_start(vorbis); - if (!IsHalted()) - { - if (SDL_memcmp(&musicVoiceFormat, &format, sizeof(format)) != 0) - { - Halt(); - musicVoiceFormat = format; - } - } + Halt(); - if (IsHalted()) - { - SDL_zero(callbacks); - callbacks.OnBufferStart = &MusicTrack::refillReserve; - callbacks.OnBufferEnd = &MusicTrack::swapBuffers; - FAudio_CreateSourceVoice(faudioctx, &musicVoice, &format, 0, 2.0f, &callbacks, NULL, NULL); - } - else - { - Pause(); - FAudioSourceVoice_FlushSourceBuffers(musicVoice); - } + SDL_zero(callbacks); + callbacks.OnBufferStart = &MusicTrack::refillReserve; + callbacks.OnBufferEnd = &MusicTrack::swapBuffers; + FAudio_CreateSourceVoice(faudioctx, &musicVoice, &format, 0, 2.0f, &callbacks, NULL, NULL); FAudioBuffer faudio_buffer; SDL_zero(faudio_buffer); @@ -546,7 +531,6 @@ end: static bool paused; static FAudioSourceVoice* musicVoice; - static FAudioWaveFormatEx musicVoiceFormat; static void refillReserve(FAudioVoiceCallback* callback, void* ctx) { @@ -725,7 +709,6 @@ end: }; bool MusicTrack::paused = false; FAudioSourceVoice* MusicTrack::musicVoice = NULL; -FAudioWaveFormatEx MusicTrack::musicVoiceFormat; musicclass::musicclass(void) {