From f2c4396299fb87983063557681151534a304ce8b Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 10:18:38 -0400 Subject: [PATCH] Added I_GetMusicType and removed midimode variable * Revised S_PlayMusic arguments * Now music plays again! --- src/i_sound.h | 18 ++++++++++++++++++ src/s_sound.c | 13 +++++++++---- src/sdl/mixer_sound.c | 32 +++++++++++++++++++++----------- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 7cb7ee9b0..7af9985f6 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -18,6 +18,21 @@ #include "sounds.h" #include "command.h" +// copied from SDL mixer, plus GME +typedef enum { + MU_NONE, + MU_CMD, + MU_WAV, + MU_MOD, + MU_MID, + MU_OGG, + MU_MP3, + MU_MP3_MAD_UNUSED, // use MU_MP3 instead + MU_FLAC, + MU_MODPLUG_UNUSED, // use MU_MOD instead + MU_GME +} musictype_t; + /** \brief Sound subsystem runing and waiting */ extern UINT8 sound_started; @@ -108,6 +123,9 @@ void I_SetSfxVolume(UINT8 volume); // // MUSIC I/O // + +musictype_t I_GetMusicType(void); + /** \brief Init the music systems */ void I_InitMusic(void); diff --git a/src/s_sound.c b/src/s_sound.c index 7a0b99c30..668e5b607 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1359,7 +1359,7 @@ static void S_UnloadMusic(void) music_name[0] = 0; } -static boolean S_PlayMusic(const char *mname, boolean looping) +static boolean S_PlayMusic(boolean looping) { if (nodigimusic || digital_disabled) return false; // try midi @@ -1370,8 +1370,6 @@ static boolean S_PlayMusic(const char *mname, boolean looping) return false; } - strncpy(music_name, mname, 7); - music_name[6] = 0; return true; } @@ -1390,11 +1388,18 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) if (strncmp(music_name, mmusic, 6)) { S_StopMusic(); // shutdown old music - if (!S_LoadMusic(mmusic) && !S_PlayMusic(mmusic, looping)) + + if (!S_LoadMusic(mmusic)) { CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic); return; } + + if (!S_PlayMusic(looping)) + { + CONS_Alert(CONS_ERROR, "Music cannot be played!\n"); + return; + } } I_SetSongTrack(mflags & MUSIC_TRACKMASK); } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index f67784fcd..f9680bc76 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -62,7 +62,6 @@ UINT8 sound_started = false; -static boolean midimode; static Mix_Music *music; static UINT8 music_volume, midi_volume, sfx_volume; static float loop_point; @@ -87,7 +86,6 @@ void I_StartupSound(void) return; } - midimode = false; music = NULL; music_volume = midi_volume = sfx_volume = 0; @@ -436,6 +434,25 @@ void I_SetSfxVolume(UINT8 volume) // Music // +musictype_t I_GetMusicType(void) +{ +#ifdef HAVE_LIBGME + if (gme) + return MU_GME; + else +#endif + if (!music) + return MU_NONE; + else if (Mix_GetMusicType(music) == MUS_MID) + return MU_MID; + else if (Mix_GetMusicType(music) == MUS_MOD || Mix_GetMusicType(music) == MUS_MODPLUG_UNUSED) + return MU_MOD; + else if (Mix_GetMusicType(music) == MUS_MP3 || Mix_GetMusicType(music) == MUS_MP3_MAD_UNUSED) + return MU_MP3; + else + return (musictype_t)Mix_GetMusicType(music); +} + // Music hooks static void music_loop(void) { @@ -474,8 +491,6 @@ FUNCMATH void I_InitMusic(void) void I_ShutdownMusic(void) { - if (midimode) - return; #ifdef HAVE_LIBGME if (gme) { @@ -510,7 +525,7 @@ void I_ResumeSong(void) void I_SetDigMusicVolume(UINT8 volume) { music_volume = volume; - if (midimode || !music) + if (I_GetMusicType() == MU_MID || !music) return; Mix_VolumeMusic((UINT32)volume*128/31); } @@ -741,8 +756,6 @@ boolean I_PlaySong(boolean looping) void I_StopSong(void) { - if (midimode) - return; #ifdef HAVE_LIBGME if (gme) { @@ -768,16 +781,13 @@ void I_SetMIDIMusicVolume(UINT8 volume) midi_volume = 31; //midi_volume = volume; - if (!midimode || !music) + if (I_GetMusicType() != MU_MID || !music) return; Mix_VolumeMusic((UINT32)midi_volume*128/31); } void I_UnloadSong(void) { - if (!midimode || !music) - return; - Mix_FreeMusic(music); music = NULL; }