diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 48d296f69158444f2b089d3414ab1a5fff6c371a..2e9a91ef92e98b62b714296ad85c0b57f67363ae 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -67,6 +67,7 @@ static Mix_Music *music; static UINT8 music_volume, midi_volume, sfx_volume; static float loop_point; static boolean songpaused; +static UINT32 music_bytes; #ifdef HAVE_LIBGME static Music_Emu *gme; @@ -441,6 +442,14 @@ 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_GetSongPosition) +} + +static void count_music_bytes(int chan, void *stream, int len, void *udata) +{ + if(midimode || !music) + return; + music_bytes += len; } #ifdef HAVE_LIBGME @@ -514,6 +523,8 @@ void I_ShutdownDigMusic(void) #endif if (!music) return; + music_bytes = 0; + Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes); Mix_HookMusicFinished(NULL); Mix_FreeMusic(music); music = NULL; @@ -686,6 +697,11 @@ boolean I_StartDigSong(const char *musicname, boolean looping) if (loop_point != 0.0f) 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; } @@ -705,6 +721,8 @@ void I_StopDigSong(void) #endif if (!music) return; + music_bytes = 0; + Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes); Mix_HookMusicFinished(NULL); Mix_FreeMusic(music); music = NULL; @@ -738,14 +756,22 @@ boolean I_SetSongSpeed(float speed) boolean I_SetSongPosition(UINT32 position) { + if(midimode || !music) + return false; Mix_PlayMusic(music, 0); 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) { - return 0; + if(midimode) + 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) @@ -791,6 +817,9 @@ void I_ShutdownMIDIMusic(void) { if (!midimode || !music) return; + //MIDI does count correctly, but dummy out because unsupported + //music_bytes = 0; + //Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes); Mix_FreeMusic(music); music = NULL; } @@ -831,6 +860,11 @@ boolean I_PlaySong(INT32 handle, boolean looping) 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); return true; } @@ -840,6 +874,9 @@ void I_StopSong(INT32 handle) if (!midimode || !music) return; + //MIDI does count correctly, but dummy out because unsupported + //music_bytes = 0; + //Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes); (void)handle; Mix_HaltMusic(); } @@ -849,6 +886,9 @@ void I_UnRegisterSong(INT32 handle) if (!midimode || !music) return; + //MIDI does count correctly, but dummy out because unsupported + //music_bytes = 0; + //Mix_UnregisterEffect(MIX_CHANNEL_POST, count_music_bytes); (void)handle; Mix_FreeMusic(music); music = NULL; diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 214d217161918f8209d17e113fd1511d4b50337f..e125c721dbcabeaaf39beea44c4157e32abba32a 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -758,6 +758,10 @@ boolean I_SetSongSpeed(float speed) 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; e = FMOD_Channel_SetPosition(music_channel, position, FMOD_TIMEUNIT_MS); if (e == FMOD_OK) @@ -774,6 +778,9 @@ boolean I_SetSongPosition(UINT32 position) UINT32 I_GetSongPosition(void) { + if(midimode) + // Dummy out because unsupported, even though FMOD does this correctly. + return 0; FMOD_RESULT e; unsigned int fmposition = 0; e = FMOD_Channel_GetPosition(music_channel, &fmposition, FMOD_TIMEUNIT_MS);