From 11c6148d4b263587d97217c0cf35f1b9c1fd262b Mon Sep 17 00:00:00 2001 From: mazmazz <mar.marcoz@outlook.com> Date: Wed, 15 Aug 2018 02:11:17 -0400 Subject: [PATCH] SDL: Fix looping bug when looping=false; reset bytes counter when non-looping # Conflicts: # src/sdl12/mixer_sound.c --- src/sdl/mixer_sound.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 6ccedc1248..759bd7dde3 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -68,6 +68,7 @@ static UINT8 music_volume, midi_volume, sfx_volume; static float loop_point; static boolean songpaused; static UINT32 music_bytes; +static boolean is_looping; #ifdef HAVE_LIBGME static Music_Emu *gme; @@ -440,9 +441,14 @@ void I_SetSfxVolume(UINT8 volume) // Music hooks static void music_loop(void) { - Mix_PlayMusic(music, 0); - Mix_SetMusicPosition(loop_point); - music_bytes = loop_point/1000.0L*44100.0L*4; //assume 44.1khz, 4-byte length (see I_GetMusicPosition) + if (is_looping) + { + Mix_PlayMusic(music, 0); + Mix_SetMusicPosition(loop_point); + music_bytes = loop_point/1000.0L*44100.0L*4; //assume 44.1khz, 4-byte length (see I_GetMusicPosition) + } + else + music_bytes = 0; } static void count_music_bytes(int chan, void *stream, int len, void *udata) @@ -558,6 +564,7 @@ void I_ShutdownDigMusic(void) #endif if (!music) return; + is_looping = false; music_bytes = 0; Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes); Mix_HookMusicFinished(NULL); @@ -689,6 +696,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) } // Find the OGG loop point. + is_looping = looping; loop_point = 0.0f; if (looping) { @@ -755,6 +763,7 @@ void I_StopDigSong(void) #endif if (!music) return; + is_looping = false; music_bytes = 0; Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes); Mix_HookMusicFinished(NULL); @@ -857,6 +866,7 @@ void I_ShutdownMIDIMusic(void) { if (!midimode || !music) return; + is_looping = false; //MIDI does count correctly, but dummy out because unsupported //music_bytes = 0; //Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes); @@ -900,7 +910,11 @@ boolean I_PlaySong(INT32 handle, boolean looping) return false; } + is_looping = looping; + //MIDI does count correctly, but dummy out because unsupported + //If this is enabled, you need to edit Mix_PlayMusic above to never loop (0) + //and register the music_loop callback //music_bytes = 0; //if(!Mix_RegisterEffect(MIX_CHANNEL_POST, count_music_bytes, NULL, NULL)) // CONS_Alert(CONS_WARNING, "Error registering SDL music position counter: %s\n", Mix_GetError()); @@ -914,6 +928,8 @@ void I_StopSong(INT32 handle) if (!midimode || !music) return; + is_looping = false; + //MIDI does count correctly, but dummy out because unsupported //music_bytes = 0; //Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes); @@ -926,6 +942,8 @@ void I_UnRegisterSong(INT32 handle) if (!midimode || !music) return; + is_looping = false; + //MIDI does count correctly, but dummy out because unsupported //music_bytes = 0; //Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes); -- GitLab