mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +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
074f43f377
commit
afa71ec7cd
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 float loop_point;
|
||||||
static boolean songpaused;
|
static boolean songpaused;
|
||||||
static UINT32 music_bytes;
|
static UINT32 music_bytes;
|
||||||
|
static boolean is_looping;
|
||||||
|
|
||||||
#ifdef HAVE_LIBGME
|
#ifdef HAVE_LIBGME
|
||||||
static Music_Emu *gme;
|
static Music_Emu *gme;
|
||||||
|
|
@ -440,9 +441,14 @@ void I_SetSfxVolume(UINT8 volume)
|
||||||
// Music hooks
|
// Music hooks
|
||||||
static void music_loop(void)
|
static void music_loop(void)
|
||||||
{
|
{
|
||||||
Mix_PlayMusic(music, 0);
|
if (is_looping)
|
||||||
Mix_SetMusicPosition(loop_point);
|
{
|
||||||
music_bytes = loop_point/1000.0L*44100.0L*4; //assume 44.1khz, 4-byte length (see I_GetMusicPosition)
|
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)
|
static void count_music_bytes(int chan, void *stream, int len, void *udata)
|
||||||
|
|
@ -558,6 +564,7 @@ void I_ShutdownDigMusic(void)
|
||||||
#endif
|
#endif
|
||||||
if (!music)
|
if (!music)
|
||||||
return;
|
return;
|
||||||
|
is_looping = false;
|
||||||
music_bytes = 0;
|
music_bytes = 0;
|
||||||
Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
||||||
Mix_HookMusicFinished(NULL);
|
Mix_HookMusicFinished(NULL);
|
||||||
|
|
@ -689,6 +696,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the OGG loop point.
|
// Find the OGG loop point.
|
||||||
|
is_looping = looping;
|
||||||
loop_point = 0.0f;
|
loop_point = 0.0f;
|
||||||
if (looping)
|
if (looping)
|
||||||
{
|
{
|
||||||
|
|
@ -755,6 +763,7 @@ void I_StopDigSong(void)
|
||||||
#endif
|
#endif
|
||||||
if (!music)
|
if (!music)
|
||||||
return;
|
return;
|
||||||
|
is_looping = false;
|
||||||
music_bytes = 0;
|
music_bytes = 0;
|
||||||
Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
||||||
Mix_HookMusicFinished(NULL);
|
Mix_HookMusicFinished(NULL);
|
||||||
|
|
@ -857,6 +866,7 @@ void I_ShutdownMIDIMusic(void)
|
||||||
{
|
{
|
||||||
if (!midimode || !music)
|
if (!midimode || !music)
|
||||||
return;
|
return;
|
||||||
|
is_looping = false;
|
||||||
//MIDI does count correctly, but dummy out because unsupported
|
//MIDI does count correctly, but dummy out because unsupported
|
||||||
//music_bytes = 0;
|
//music_bytes = 0;
|
||||||
//Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
//Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
||||||
|
|
@ -900,7 +910,11 @@ boolean I_PlaySong(INT32 handle, boolean looping)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_looping = looping;
|
||||||
|
|
||||||
//MIDI does count correctly, but dummy out because unsupported
|
//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;
|
//music_bytes = 0;
|
||||||
//if(!Mix_RegisterEffect(MIX_CHANNEL_POST, count_music_bytes, NULL, NULL))
|
//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());
|
// 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)
|
if (!midimode || !music)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
is_looping = false;
|
||||||
|
|
||||||
//MIDI does count correctly, but dummy out because unsupported
|
//MIDI does count correctly, but dummy out because unsupported
|
||||||
//music_bytes = 0;
|
//music_bytes = 0;
|
||||||
//Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
//Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
||||||
|
|
@ -926,6 +942,8 @@ void I_UnRegisterSong(INT32 handle)
|
||||||
if (!midimode || !music)
|
if (!midimode || !music)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
is_looping = false;
|
||||||
|
|
||||||
//MIDI does count correctly, but dummy out because unsupported
|
//MIDI does count correctly, but dummy out because unsupported
|
||||||
//music_bytes = 0;
|
//music_bytes = 0;
|
||||||
//Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
//Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue