From 548893636632b874f177b26b38b40e42cd9fce58 Mon Sep 17 00:00:00 2001 From: StarManiaKG Date: Thu, 21 Mar 2024 22:00:04 -0400 Subject: [PATCH] Added new SDL_Mixer-X features to compensate for the upcoming/already done SDL_Mixer-X upgrade --- src/android/i_sound.c | 20 +++- src/dummy/i_sound.c | 20 +++- src/i_sound.h | 6 +- src/lua_baselib.c | 110 ++++++++++++++++++++ src/m_menu.c | 6 +- src/p_enemy.c | 2 +- src/p_tick.c | 4 +- src/s_sound.c | 55 ++++++++-- src/s_sound.h | 17 +++- src/sdl/mixer_sound.c | 230 +++++++++++++++++++++++++++++++++++------- src/sdl/sdl_sound.c | 20 +++- 11 files changed, 438 insertions(+), 52 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index b5a1c3646..d9ff5437c 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -90,10 +90,26 @@ boolean I_SongPaused(void) // MUSIC EFFECTS /// ------------------------ -boolean I_SetSongSpeed(float speed) +void I_SetSongSpeed(float speed) // StarManiaKG: was originally boolean, no longer needs to be // { (void)speed; - return false; + return; +} + +float I_GetSongSpeed(void) +{ + return 0.0f; +} + +void I_SetSongPitch(float pitch) +{ + (void)pitch; + return; +} + +float I_GetSongPitch(void) +{ + return 0.0f; } /// ------------------------ diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 436187805..7529ea8d1 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -89,10 +89,26 @@ boolean I_SongPaused(void) // MUSIC EFFECTS /// ------------------------ -boolean I_SetSongSpeed(float speed) +void I_SetSongSpeed(float speed) // StarManiaKG: was originally boolean, no longer needs to be // { (void)speed; - return false; + return; +} + +float I_GetSongSpeed(void) +{ + return 0.0f; +} + +void I_SetSongPitch(float pitch) +{ + (void)pitch; + return; +} + +float I_GetSongPitch(void) +{ + return 0.0f; } /// ------------------------ diff --git a/src/i_sound.h b/src/i_sound.h index c51d8e4f4..bf84df02e 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -143,7 +143,11 @@ boolean I_SongPaused(void); // MUSIC EFFECTS /// ------------------------ -boolean I_SetSongSpeed(float speed); +void I_SetSongSpeed(float speed); // StarManiaKG: was originally boolean, no longer needs to be // +float I_GetSongSpeed(void); + +void I_SetSongPitch(float pitch); +float I_GetSongPitch(void); /// ------------------------ // MUSIC SEEKING diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 19775eb8a..eff637512 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3377,6 +3377,57 @@ static int lib_sSpeedMusic(lua_State *L) return 0; } +static int lib_sGetSpeedMusic(lua_State *L) +{ + player_t *player = NULL; + //NOHUD + if (!lua_isnone(L, 1) && lua_isuserdata(L, 1)) + { + player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + if (!player) + return LUA_ErrInvalid(L, "player_t"); + } + if (!player || P_IsLocalPlayer(player)) + lua_pushinteger(L, S_GetSpeedMusic()); + else + lua_pushnil(L); + return 1; +} + +static int lib_sPitchMusic(lua_State *L) +{ + fixed_t fixedpitch = luaL_checkfixed(L, 1); + float pitch = FIXED_TO_FLOAT(fixedpitch); + player_t *player = NULL; + //NOHUD + if (!lua_isnone(L, 2) && lua_isuserdata(L, 2)) + { + player = *((player_t **)luaL_checkudata(L, 2, META_PLAYER)); + if (!player) + return LUA_ErrInvalid(L, "player_t"); + } + if (!player || P_IsLocalPlayer(player)) + S_PitchMusic(pitch); + return 0; +} + +static int lib_sGetPitchMusic(lua_State *L) +{ + player_t *player = NULL; + //NOHUD + if (!lua_isnone(L, 1) && lua_isuserdata(L, 1)) + { + player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + if (!player) + return LUA_ErrInvalid(L, "player_t"); + } + if (!player || P_IsLocalPlayer(player)) + lua_pushinteger(L, S_GetPitchMusic()); + else + lua_pushnil(L); + return 1; +} + static int lib_sStopMusic(lua_State *L) { player_t *player = NULL; @@ -3413,6 +3464,59 @@ static int lib_sSetInternalMusicVolume(lua_State *L) return 1; } +static int lib_sGetInternalMusicVolume(lua_State *L) +{ + player_t *player = NULL; + //NOHUD + if (!lua_isnone(L, 1) && lua_isuserdata(L, 1)) + { + player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + if (!player) + return LUA_ErrInvalid(L, "player_t"); + } + if (!player || P_IsLocalPlayer(player)) + lua_pushinteger(L, (UINT32)S_GetInternalMusicVolume()); + else + lua_pushnil(L); +} + +static int lib_sSetInternalSfxVolume(lua_State *L) +{ + UINT32 sfxvolume = (UINT32)luaL_checkinteger(L, 1); + player_t *player = NULL; + //NOHUD + if (!lua_isnone(L, 2) && lua_isuserdata(L, 2)) + { + player = *((player_t **)luaL_checkudata(L, 2, META_PLAYER)); + if (!player) + return LUA_ErrInvalid(L, "player_t"); + } + if (!player || P_IsLocalPlayer(player)) + { + S_SetInternalSfxVolume(sfxvolume); + lua_pushboolean(L, true); + } + else + lua_pushnil(L); + return 1; +} + +static int lib_sGetInternalSfxVolume(lua_State *L) +{ + player_t *player = NULL; + //NOHUD + if (!lua_isnone(L, 1) && lua_isuserdata(L, 1)) + { + player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + if (!player) + return LUA_ErrInvalid(L, "player_t"); + } + if (!player || P_IsLocalPlayer(player)) + lua_pushinteger(L, (UINT32)S_GetInternalSfxVolume()); + else + lua_pushnil(L); +} + static int lib_sStopFadingMusic(lua_State *L) { player_t *player = NULL; @@ -4592,8 +4696,14 @@ static luaL_Reg lib[] = { {"S_StopSoundByID",lib_sStopSoundByID}, {"S_ChangeMusic",lib_sChangeMusic}, {"S_SpeedMusic",lib_sSpeedMusic}, + {"S_GetSpeedMusic",lib_sGetSpeedMusic}, + {"S_PitchMusic",lib_sPitchMusic}, + {"S_GetPitchMusic",lib_sGetPitchMusic}, {"S_StopMusic",lib_sStopMusic}, {"S_SetInternalMusicVolume", lib_sSetInternalMusicVolume}, + {"S_GetInternalMusicVolume", lib_sGetInternalMusicVolume}, + {"S_SetInternalSfxVolume", lib_sSetInternalSfxVolume}, + {"S_GetInternalSfxVolume", lib_sGetInternalSfxVolume}, {"S_StopFadingMusic",lib_sStopFadingMusic}, {"S_FadeMusic",lib_sFadeMusic}, {"S_FadeOutStopMusic",lib_sFadeOutStopMusic}, diff --git a/src/m_menu.c b/src/m_menu.c index 2e4a42506..20126cb17 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -8081,7 +8081,11 @@ static void M_DrawSoundTest(void) } else { - V_DrawString(x, y, (t == st_sel ? V_YELLOWMAP : 0)|V_ALLOWLOWERCASE, soundtestdefs[t]->title); + if (strlen(soundtestdefs[t]->title) < 17) + V_DrawString(x, y, (t == st_sel ? V_YELLOWMAP : 0)|V_ALLOWLOWERCASE, soundtestdefs[t]->title); + else + V_DrawThinString(x, y, (t == st_sel ? V_YELLOWMAP : 0)|V_ALLOWLOWERCASE, soundtestdefs[t]->title)); + if (curplaying == soundtestdefs[t]) { V_DrawFill(165+140-9, y-4, 8, 16, 150); diff --git a/src/p_enemy.c b/src/p_enemy.c index 59ca95409..4db456fe6 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -4257,7 +4257,7 @@ void A_SuperSneakers(mobj_t *actor) if (P_IsLocalPlayer(player) && !player->powers[pw_super]) { - if (S_SpeedMusic(0.0f) && (mapheaderinfo[gamemap-1]->levelflags & LF_SPEEDMUSIC)) + if (mapheaderinfo[gamemap-1]->levelflags & LF_SPEEDMUSIC) S_SpeedMusic(1.4f); else P_PlayJingle(player, JT_SHOES); diff --git a/src/p_tick.c b/src/p_tick.c index 68de09138..0c98c3acf 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -584,8 +584,8 @@ static inline void P_DoSpecialStageStuff(void) players[i].powers[pw_underwater] = players[i].powers[pw_spacetime] = 0; } - //if (sstimer < 15*TICRATE+6 && sstimer > 7 && (mapheaderinfo[gamemap-1]->levelflags & LF_SPEEDMUSIC)) - //S_SpeedMusic(1.4f); + if (sstimer < 15*TICRATE+6 && sstimer > 7 && (mapheaderinfo[gamemap-1]->levelflags & LF_SPEEDMUSIC)) + S_SpeedMusic(1.4f); if (sstimer && !objectplacing) { diff --git a/src/s_sound.c b/src/s_sound.c index 0329c289e..a62637657 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -165,6 +165,10 @@ static INT32 numofchannels = 0; caption_t closedcaptions[NUMCAPTIONS]; +// allow the grabbing of internal volumes +INT32 internal_volume = min(max(100, 0), 100); +INT32 internal_sfx_volume = 0; + void S_ResetCaptions(void) { UINT8 i; @@ -1787,9 +1791,10 @@ boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi) /// Music Effects /// ------------------------ -boolean S_SpeedMusic(float speed) +void S_SpeedMusic(float speed) // StarManiaKG: was originally boolean, no longer needs to be // { - return I_SetSongSpeed(speed); + I_SetSongSpeed(speed); + return; } /// ------------------------ @@ -2402,6 +2407,36 @@ void S_SetInternalMusicVolume(INT32 volume) I_SetInternalMusicVolume(min(max(volume, 0), 100)); } +INT32 S_GetInternalMusicVolume(void) +{ + internal_volume = min(max(volume, 0), 100); + I_SetInternalMusicVolume((UINT8)internal_volume); +} + +void S_SetInternalSfxVolume(INT32 volume) +{ + if (volume < 0 || volume > 31) + { + CONS_Alert(CONS_WARNING, "sfxvolume should be between 0-31\n"); + volume = (volume < 0 ? 0 : 31); + } + internal_sfx_volume = volume; + +#ifdef HW3SOUND + hws_mode == HWS_DEFAULT_MODE ? I_SetSfxVolume(internal_sfx_volume&0x1F) : HW3S_SetSfxVolume(internal_sfx_volume&0x1F); +#else + // now hardware volume + I_SetSfxVolume(internal_sfx_volume&0x1F); +#endif +} + +INT32 S_GetInternalSfxVolume(void) +{ + if (!internal_sfx_volume && cv_soundvolume.value) + internal_sfx_volume = cv_soundvolume.value; + return internal_sfx_volume; +} + void S_StopFadingMusic(void) { I_StopFadingSong(); @@ -2458,7 +2493,7 @@ static void Command_Tunes_f(void) if (argc < 2) //tunes slot ... { - CONS_Printf("tunes [track] [speed] [position] / <-show> / <-default> / <-none>:\n"); + CONS_Printf("tunes [track] [speed] [pitch] [position] / <-show> / <-default> / <-none>:\n"); CONS_Printf(M_GetText("Play an arbitrary music lump. If a map number is used, 'MAP##M' is played.\n")); CONS_Printf(M_GetText("If the format supports multiple songs, you can specify which one to play.\n\n")); CONS_Printf(M_GetText("* With \"-show\", shows the currently playing tune and track.\n")); @@ -2496,8 +2531,8 @@ static void Command_Tunes_f(void) strncpy(mapmusname, tunearg, 7); mapmusname[6] = 0; - if (argc > 4) - position = (UINT32)atoi(COM_Argv(4)); + if (argc > 5) // StarManiaKG: shifted up by one to account for the new pitch argument + position = (UINT32)atoi(COM_Argv(5)); mapmusflags = (track & MUSIC_TRACKMASK); mapmusposition = position; @@ -2510,6 +2545,13 @@ static void Command_Tunes_f(void) if (speed > 0.0f) S_SpeedMusic(speed); } + + if (argc > 4) + { + float pitch = (float)atof(COM_Argv(4)); + if (pitch > 0.0f) + S_PitchMusic(pitch); + } } static void Command_RestartAudio_f(void) @@ -2621,7 +2663,8 @@ void GameMIDIMusic_OnChange(void) void MusicPref_OnChange(void) { if (M_CheckParm("-nomusic") || M_CheckParm("-noaudio") || - M_CheckParm("-nomidimusic") || M_CheckParm("-nodigmusic")) + M_CheckParm("-nomidimusic") || M_CheckParm("-nodigmusic") || + !sound_started) // StarManiaKG: prevents weird errors from popping up until the sound engine is actually started return; if (Playing()) diff --git a/src/s_sound.h b/src/s_sound.h index 589060c8c..0f6ce0ae3 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -177,7 +177,14 @@ boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi); // // Set Speed of Music -boolean S_SpeedMusic(float speed); +void S_SpeedMusic(float speed); // StarManiaKG: was originally boolean, no longer needs to be // +// Get Speed of Music +float S_GetSpeedMusic(void); + +// Set Pitch of Music +void S_PitchMusic(float pitch); +// Get Pitch of Music +float S_GetPitchMusic(void); // Music definitions typedef struct musicdef_s @@ -315,6 +322,14 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume); #define S_SetMIDIMusicVolume(a) S_SetMusicVolume(-1,a) #define S_InitMusicVolume() S_SetMusicVolume(-1,-1) +// Grab Internal Music Speed +INT32 S_GetInternalMusicVolume(void); + +// Set Internal SFX Speed +void S_SetInternalSfxVolume(INT32 volume); +// Grab Internal SFX Speed +INT32 S_GetInternalSfxVolume(void); + INT32 S_OriginPlaying(void *origin); INT32 S_IdPlaying(sfxenum_t id); INT32 S_SoundPlaying(void *origin, sfxenum_t id); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 8f2ca3408..335221024 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -94,6 +94,7 @@ UINT8 sound_started = false; static Mix_Music *music; static UINT8 music_volume, sfx_volume, internal_volume; +static float music_speed, music_pitch; static float loop_point; static float song_length; // length in seconds static boolean songpaused; @@ -125,10 +126,75 @@ static int result; #endif #ifdef HAVE_MIXERX +// +// Timdity Handlers (By StarManiaKG) // +// (You can tell which is Timidity based :p) +// +#if defined(__WIN32__) +#define TIMIDITY_CFG "sf2/timidity" +#elif defined(__OS2__) +#define TIMIDITY_CFG "/@unixroot/etc/timidity" +#else +#define TIMIDITY_CFG "/etc/timidity" +#endif + +static int I_SetTimidityCFG(const char *path) +{ +#if SDL_MIXER_VERSION_ATLEAST(2,0,4) + return Mix_SetTimidityCfg(path); +#else + return Mix_Timidity_addToPathList(path); +#endif +} + +static const char *I_GetTimidityCFG(void) +{ +#if SDL_MIXER_VERSION_ATLEAST(2,0,4) + return Mix_GetTimidityCfg(); +#else + static const char *CFGPaths[] = { + va("%s/timidity.cfg", cv_miditimiditypath.string), + TIMIDITY_CFG, + NULL + } + + for (INT32 i = 0; CFGPaths[i]; i++) + { + SDL_RWops *rw = SDL_RWFromFile(CFGPaths[i], "r"); + if (rw != NULL) + { + SDL_RWclose(rw); + return CFGPaths[i]; + } + } + + return NULL; +#endif +} + +static void I_ControlTimidityCFG(void) +{ + const char *path = va("%s/timidity.cfg", cv_miditimiditypath.string); + + if (Mix_GetMidiPlayer() != MIDI_Timidity || (I_SongType() != MU_NONE && I_SongType() != MU_MID_EX)) + return; + + if (!I_SetTimidityCFG(path) && (I_GetTimidityCFG() != NULL && stricmp(I_GetTimidityCFG(), path))) // == 0 means error + CONS_Alert(CONS_ERROR, "Timdity CFG error: %s\n", Mix_GetError()); + else + { + if (I_GetTimidityCFG() != NULL && stricmp(I_GetTimidityCFG(), path)) + S_StartEx(true); + } +} + static void Midiplayer_Onchange(void) { boolean restart = false; + const char *fluidsynthsoundfonts = Mix_GetSoundFonts(); + const char *timiditycfgs; + if (I_SongType() != MU_NONE && I_SongType() != MU_MID_EX && I_SongType() != MU_MID) return; @@ -140,18 +206,19 @@ static void Midiplayer_Onchange(void) restart = true; } - if (!Mix_GetSoundFonts() || stricmp(Mix_GetSoundFonts(), cv_midisoundfontpath.string)) + if (fluidsynthsoundfonts != NULL && stricmp(fluidsynthsoundfonts, cv_midisoundfontpath.string)) { if (!Mix_SetSoundFonts(cv_midisoundfontpath.string)) // == 0 means error CONS_Alert(CONS_ERROR, "Sound font error: %s", Mix_GetError()); else restart = true; } -#if SDL_MIXER_VERSION_ATLEAST(2,5,0) - Mix_SetTimidityCfg(cv_miditimiditypath.string); -#else - Mix_Timidity_addToPathList(cv_miditimiditypath.string); -#endif + + I_ControlTimidityCFG(); + timiditycfgs = I_GetTimidityCFG(); + + if (timiditycfgs != NULL && stricmp(timiditycfgs, va("%s/timidity.cfg", cv_miditimiditypath.string))) + restart = true; if (restart) S_StartEx(true); @@ -202,8 +269,8 @@ static void MidiSoundfontPath_Onchange(void) static CV_PossibleValue_t midiplayer_cons_t[] = {{MIDI_OPNMIDI, "OPNMIDI"}, {MIDI_Fluidsynth, "Fluidsynth"}, {MIDI_Timidity, "Timidity"}, {MIDI_Native, "Native"}, {0, NULL}}; consvar_t cv_midiplayer = CVAR_INIT ("midiplayer", "OPNMIDI" /*MIDI_OPNMIDI*/, CV_CALL|CV_NOINIT|CV_SAVE, midiplayer_cons_t, Midiplayer_Onchange); consvar_t cv_midisoundfontpath = CVAR_INIT ("midisoundfont", "sf2/8bitsf.SF2", CV_CALL|CV_NOINIT|CV_SAVE, NULL, MidiSoundfontPath_Onchange); -consvar_t cv_miditimiditypath = CVAR_INIT ("midisoundbank", "./timidity", CV_SAVE, NULL, NULL); -#endif +consvar_t cv_miditimiditypath = CVAR_INIT ("midisoundbank", TIMIDITY_CFG, CV_CALL|CV_NOINIT|CV_SAVE, NULL, I_ControlTimidityCFG); +#endif // HAVE_MIXERX static void var_cleanup(void) { @@ -211,6 +278,8 @@ static void var_cleanup(void) music_bytes = fading_source = fading_target =\ fading_timer = fading_duration = 0; + music_speed = music_pitch = 1.0f; + songpaused = is_looping =\ is_fading = false; @@ -289,11 +358,7 @@ void I_StartupSound(void) #ifdef HAVE_MIXERX Mix_SetMidiPlayer(cv_midiplayer.value); Mix_SetSoundFonts(cv_midisoundfontpath.string); -#if SDL_MIXER_VERSION_ATLEAST(2,5,0) - Mix_SetTimidityCfg(cv_miditimiditypath.string); -#else - Mix_Timidity_addToPathList(cv_miditimiditypath.string); -#endif + I_ControlTimidityCFG(); #endif #if SDL_MIXER_VERSION_ATLEAST(1,2,11) Mix_Init(MIX_INIT_FLAC|MIX_INIT_MP3|MIX_INIT_OGG|MIX_INIT_MOD); @@ -647,16 +712,16 @@ void I_SetSfxVolume(UINT8 volume) static UINT32 get_real_volume(UINT8 volume) { -#ifdef _WIN32 +#if defined (HAVE_MIXERX) && (_WIN32) && !defined(SDL_MIXER_VERSION_ATLEAST(2,6,0)) // StarManiaKG: recent SDL_Mixer_X builds fix whatever issue was here, apparently :p // if (I_SongType() == MU_MID) // HACK: Until we stop using native MIDI, // disable volume changes return ((UINT32)31*128/31); // volume = 31 - else #endif - // convert volume to mixer's 128 scale - // then apply internal_volume as a percentage - return ((UINT32)volume*128/31) * (UINT32)internal_volume / 100; + + // convert volume to mixer's 128 scale + // then apply internal_volume as a percentage + return ((UINT32)volume*128/31) * (UINT32)internal_volume / 100; } static UINT32 get_adjusted_position(UINT32 position) @@ -864,25 +929,28 @@ boolean I_SongPaused(void) /// Music Effects /// ------------------------ -boolean I_SetSongSpeed(float speed) +void I_SetSongSpeed(float speed) // StarManiaKG: was originally boolean, no longer needs to be // { if (speed > 250.0f) speed = 250.0f; //limit speed up to 250x + music_speed = speed; + #ifdef HAVE_GME if (gme) { SDL_LockAudio(); gme_set_tempo(gme, speed); SDL_UnlockAudio(); - return true; + return; } - else #endif + #ifdef HAVE_OPENMPT if (openmpt_mhandle) { if (speed > 4.0f) - speed = 4.0f; // Limit this to 4x to prevent crashing, stupid fix but... ~SteelT 27/9/19 + music_speed = speed = 4.0f; // Limit this to 4x to prevent crashing, stupid fix but... ~SteelT 27/9/19 + #if OPENMPT_API_VERSION_MAJOR < 1 && OPENMPT_API_VERSION_MINOR < 5 { // deprecated in 0.5.0 @@ -893,13 +961,111 @@ boolean I_SetSongSpeed(float speed) #else openmpt_module_ctl_set_floatingpoint(openmpt_mhandle, "play.tempo_factor", (double)speed); #endif - return true; + return; } -#else - (void)speed; - return false; #endif - return false; + + // StarManiaKG: a new speed system! (tons of modding options here!) // +#ifdef HAVE_MIXERX + if (music) + { + if (speed > 20.0f) // Limit this to 20x to prevent errors + { + CONS_Alert(CONS_WARNING, "I_SetSongSpeed(): Music speed cannot be set above 20x, lowering music speed to 20x.\n"); + music_speed = speed = 20.0f; + } + + if (FLOAT_TO_FIXED(I_GetSongSpeed()) != FLOAT_TO_FIXED(speed)) // StarManiaKG: prevents rapid and inconsistant music speeds when calling repeatedly // + { +#if (SDL_MIXER_VERSION_ATLEAST(2,6,0)) + if (!(I_SongType() == MU_MID_EX || I_SongType() == MU_MID)) + Mix_SetMusicSpeed(music, speed); + else +#endif + Mix_SetMusicTempo(music, speed); + } + return; + } +#endif +} + +float I_GetSongSpeed(void) +{ +#ifdef HAVE_MIXERX + if (music) + { +#if (SDL_MIXER_VERSION_ATLEAST(2,6,0)) + if (!(I_SongType() == MU_MID_EX || I_SongType() == MU_MID)) + return Mix_GetMusicSpeed(music); + else +#endif + return Mix_GetMusicTempo(music); + } +#endif + + return music_speed; +} + +void I_SetSongPitch(float pitch) +{ + if (pitch > 250.0f) + pitch = 250.0f; // limit pitch up to 250x + music_pitch = pitch; + +#ifdef HAVE_GME + if (gme) + { + SDL_LockAudio(); + gme_set_stereo_depth(gme, pitch); + SDL_UnlockAudio(); + return; + } +#endif + +#ifdef HAVE_OPENMPT + if (openmpt_mhandle) + { + if (pitch > 4.0f) + music_pitch = pitch = 4.0f; // Limit this to 4x to prevent crashing, stupid fix but... ~StarManiaKG 20/1/24 (stolen from SteelT) + +#if OPENMPT_API_VERSION_MAJOR < 1 && OPENMPT_API_VERSION_MINOR < 5 + { + // deprecated in 0.5.0 + char modspd[13]; + sprintf(modspd, "%g", pitch); + openmpt_module_ctl_set(openmpt_mhandle, "play.pitch_factor", modspd); + } +#else + openmpt_module_ctl_set_floatingpoint(openmpt_mhandle, "play.pitch_factor", (double)pitch); +#endif + return; + } +#endif + +#ifdef HAVE_MIXERX + if (music) + { + if (pitch > 20.0f) + { + CONS_Alert(CONS_WARNING, "I_SetSongPitch(): Music pitch cannot be set above 20x, lowering music pitch to 20x.\n"); + music_pitch = pitch = 20.0f; + } + + if (FLOAT_TO_FIXED(I_GetSongPitch()) != FLOAT_TO_FIXED(pitch)) // StarManiaKG: prevents rapid and inconsistant music pitches when calling repeatedly // + Mix_SetMusicPitch(music, pitch); + return; + } +#endif +} + +float I_GetSongPitch(void) +{ +#if defined (HAVE_MIXERX) && SDL_MIXER_VERSION_ATLEAST(2,6,0) + if (music) + return Mix_GetMusicPitch(music); +#endif + + return music_pitch; } /// ------------------------ @@ -1210,13 +1376,9 @@ boolean I_LoadSong(char *data, size_t len) #ifdef HAVE_MIXERX if (Mix_GetMidiPlayer() != cv_midiplayer.value) Mix_SetMidiPlayer(cv_midiplayer.value); - if (!Mix_GetSoundFonts() || stricmp(Mix_GetSoundFonts(), cv_midisoundfontpath.string)) + if (stricmp(Mix_GetSoundFonts(), cv_midisoundfontpath.string)) Mix_SetSoundFonts(cv_midisoundfontpath.string); -#if SDL_MIXER_VERSION_ATLEAST(2,5,0) - Mix_SetTimidityCfg(cv_miditimiditypath.string); -#else - Mix_Timidity_addToPathList(cv_miditimiditypath.string); // this overwrites previous custom path -#endif + I_ControlTimidityCFG(); // this overwrites previous custom path #endif #ifdef HAVE_OPENMPT @@ -1445,7 +1607,7 @@ void I_SetMusicVolume(UINT8 volume) if (!I_SongPlaying()) return; -#ifdef _WIN32 +#if defined (HAVE_MIXERX) && (_WIN32) && !defined(SDL_MIXER_VERSION_ATLEAST(2,6,0)) // StarManiaKG: recent SDL_Mixer_X builds fix whatever issue was here, apparently :p // if (I_SongType() == MU_MID) // HACK: Until we stop using native MIDI, // disable volume changes diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 2705261d6..ee9d5efa5 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1370,10 +1370,26 @@ boolean I_SongPaused(void) // MUSIC EFFECTS /// ------------------------ -boolean I_SetSongSpeed(float speed) +void I_SetSongSpeed(float speed) // StarManiaKG: was originally boolean, no longer needs to be // { (void)speed; - return false; + return; +} + +float I_GetSongSpeed(void) +{ + return 0.0f; +} + +void I_SetSongPitch(float pitch) +{ + (void)pitch; + return; +} + +float I_GetSongPitch(void) +{ + return 0.0f; } /// ------------------------