mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-18 10:31:42 +00:00
SDL: Fix looping bug when looping=false; reset bytes counter when non-looping
# Conflicts: # src/sdl12/mixer_sound.c
This commit is contained in:
parent
a9776f7b25
commit
11c6148d4b
1 changed files with 21 additions and 3 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue