mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Fix SDL music position getting; dummy out position methods for MIDI
# Conflicts: # src/sdl/mixer_sound.c # src/sdl12/mixer_sound.c
This commit is contained in:
parent
6d82e03710
commit
d23d77754e
2 changed files with 49 additions and 2 deletions
|
|
@ -67,6 +67,7 @@ static Mix_Music *music;
|
||||||
static UINT8 music_volume, midi_volume, sfx_volume;
|
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;
|
||||||
|
|
||||||
#ifdef HAVE_LIBGME
|
#ifdef HAVE_LIBGME
|
||||||
static Music_Emu *gme;
|
static Music_Emu *gme;
|
||||||
|
|
@ -441,6 +442,14 @@ static void music_loop(void)
|
||||||
{
|
{
|
||||||
Mix_PlayMusic(music, 0);
|
Mix_PlayMusic(music, 0);
|
||||||
Mix_SetMusicPosition(loop_point);
|
Mix_SetMusicPosition(loop_point);
|
||||||
|
music_bytes = loop_point/1000.0L*44100.0L*4; //assume 44.1khz, 4-byte length (see I_GetSongPosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
static void count_music_bytes(int chan, void *stream, int len, void *udata)
|
||||||
|
{
|
||||||
|
if(midimode || !music)
|
||||||
|
return;
|
||||||
|
music_bytes += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBGME
|
#ifdef HAVE_LIBGME
|
||||||
|
|
@ -514,6 +523,8 @@ void I_ShutdownDigMusic(void)
|
||||||
#endif
|
#endif
|
||||||
if (!music)
|
if (!music)
|
||||||
return;
|
return;
|
||||||
|
music_bytes = 0;
|
||||||
|
Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
||||||
Mix_HookMusicFinished(NULL);
|
Mix_HookMusicFinished(NULL);
|
||||||
Mix_FreeMusic(music);
|
Mix_FreeMusic(music);
|
||||||
music = NULL;
|
music = NULL;
|
||||||
|
|
@ -686,6 +697,11 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
|
||||||
|
|
||||||
if (loop_point != 0.0f)
|
if (loop_point != 0.0f)
|
||||||
Mix_HookMusicFinished(music_loop);
|
Mix_HookMusicFinished(music_loop);
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -705,6 +721,8 @@ void I_StopDigSong(void)
|
||||||
#endif
|
#endif
|
||||||
if (!music)
|
if (!music)
|
||||||
return;
|
return;
|
||||||
|
music_bytes = 0;
|
||||||
|
Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
||||||
Mix_HookMusicFinished(NULL);
|
Mix_HookMusicFinished(NULL);
|
||||||
Mix_FreeMusic(music);
|
Mix_FreeMusic(music);
|
||||||
music = NULL;
|
music = NULL;
|
||||||
|
|
@ -738,14 +756,22 @@ boolean I_SetSongSpeed(float speed)
|
||||||
|
|
||||||
boolean I_SetSongPosition(UINT32 position)
|
boolean I_SetSongPosition(UINT32 position)
|
||||||
{
|
{
|
||||||
|
if(midimode || !music)
|
||||||
|
return false;
|
||||||
Mix_PlayMusic(music, 0);
|
Mix_PlayMusic(music, 0);
|
||||||
Mix_SetMusicPosition((float)(position/1000.0L));
|
Mix_SetMusicPosition((float)(position/1000.0L));
|
||||||
return 1;
|
music_bytes = position/1000.0L*44100.0L*4; //assume 44.1khz, 4-byte length (see I_GetSongPositon)
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT32 I_GetSongPosition(void)
|
UINT32 I_GetSongPosition(void)
|
||||||
{
|
{
|
||||||
|
if(midimode)
|
||||||
return 0;
|
return 0;
|
||||||
|
return music_bytes/44100.0L*1000.0L/4; //assume 44.1khz
|
||||||
|
// 4 = byte length for 16-bit samples (AUDIO_S16SYS), stereo (2-channel)
|
||||||
|
// This is hardcoded in I_StartupSound. Other formats for factor:
|
||||||
|
// 8M: 1 | 8S: 2 | 16M: 2 | 16S: 4
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean I_SetSongTrack(int track)
|
boolean I_SetSongTrack(int track)
|
||||||
|
|
@ -791,6 +817,9 @@ void I_ShutdownMIDIMusic(void)
|
||||||
{
|
{
|
||||||
if (!midimode || !music)
|
if (!midimode || !music)
|
||||||
return;
|
return;
|
||||||
|
//MIDI does count correctly, but dummy out because unsupported
|
||||||
|
//music_bytes = 0;
|
||||||
|
//Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
||||||
Mix_FreeMusic(music);
|
Mix_FreeMusic(music);
|
||||||
music = NULL;
|
music = NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -831,6 +860,11 @@ boolean I_PlaySong(INT32 handle, boolean looping)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//MIDI does count correctly, but dummy out because unsupported
|
||||||
|
//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());
|
||||||
|
|
||||||
Mix_VolumeMusic((UINT32)midi_volume*128/31);
|
Mix_VolumeMusic((UINT32)midi_volume*128/31);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -840,6 +874,9 @@ void I_StopSong(INT32 handle)
|
||||||
if (!midimode || !music)
|
if (!midimode || !music)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
//MIDI does count correctly, but dummy out because unsupported
|
||||||
|
//music_bytes = 0;
|
||||||
|
//Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
||||||
(void)handle;
|
(void)handle;
|
||||||
Mix_HaltMusic();
|
Mix_HaltMusic();
|
||||||
}
|
}
|
||||||
|
|
@ -849,6 +886,9 @@ void I_UnRegisterSong(INT32 handle)
|
||||||
if (!midimode || !music)
|
if (!midimode || !music)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
//MIDI does count correctly, but dummy out because unsupported
|
||||||
|
//music_bytes = 0;
|
||||||
|
//Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes);
|
||||||
(void)handle;
|
(void)handle;
|
||||||
Mix_FreeMusic(music);
|
Mix_FreeMusic(music);
|
||||||
music = NULL;
|
music = NULL;
|
||||||
|
|
|
||||||
|
|
@ -758,6 +758,10 @@ boolean I_SetSongSpeed(float speed)
|
||||||
|
|
||||||
boolean I_SetSongPosition(UINT32 position)
|
boolean I_SetSongPosition(UINT32 position)
|
||||||
{
|
{
|
||||||
|
if(midimode)
|
||||||
|
// Dummy out; this works for some MIDI, but not others.
|
||||||
|
// SDL does not support this for any MIDI.
|
||||||
|
return false;
|
||||||
FMOD_RESULT e;
|
FMOD_RESULT e;
|
||||||
e = FMOD_Channel_SetPosition(music_channel, position, FMOD_TIMEUNIT_MS);
|
e = FMOD_Channel_SetPosition(music_channel, position, FMOD_TIMEUNIT_MS);
|
||||||
if (e == FMOD_OK)
|
if (e == FMOD_OK)
|
||||||
|
|
@ -774,6 +778,9 @@ boolean I_SetSongPosition(UINT32 position)
|
||||||
|
|
||||||
UINT32 I_GetSongPosition(void)
|
UINT32 I_GetSongPosition(void)
|
||||||
{
|
{
|
||||||
|
if(midimode)
|
||||||
|
// Dummy out because unsupported, even though FMOD does this correctly.
|
||||||
|
return 0;
|
||||||
FMOD_RESULT e;
|
FMOD_RESULT e;
|
||||||
unsigned int fmposition = 0;
|
unsigned int fmposition = 0;
|
||||||
e = FMOD_Channel_GetPosition(music_channel, &fmposition, FMOD_TIMEUNIT_MS);
|
e = FMOD_Channel_GetPosition(music_channel, &fmposition, FMOD_TIMEUNIT_MS);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue