From b5c30958203c8cf92e0e0addad4fc87f9351c60e Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 07:39:32 -0400 Subject: [PATCH 01/30] Nix'd midimusicvolume --- src/d_main.c | 2 +- src/d_netcmd.c | 2 -- src/i_sound.h | 8 -------- src/m_menu.c | 9 +++------ src/s_sound.c | 21 +-------------------- src/s_sound.h | 5 ++--- src/sdl/mixer_sound.c | 13 ------------- 7 files changed, 7 insertions(+), 53 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 95af1f754..f53761d6d 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1212,7 +1212,7 @@ void D_SRB2Main(void) } I_StartupSound(); I_InitMusic(); - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_Init(cv_soundvolume.value, cv_digmusicvolume.value); CONS_Printf("ST_Init(): Init status bar.\n"); ST_Init(); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 0cb1d4497..f1130f736 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -790,7 +790,6 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_soundvolume); CV_RegisterVar(&cv_closedcaptioning); CV_RegisterVar(&cv_digmusicvolume); - CV_RegisterVar(&cv_midimusicvolume); CV_RegisterVar(&cv_numChannels); // i_cdmus.c @@ -4058,7 +4057,6 @@ static void Command_RestartAudio_f(void) I_SetSfxVolume(cv_soundvolume.value); I_SetDigMusicVolume(cv_digmusicvolume.value); - I_SetMIDIMusicVolume(cv_midimusicvolume.value); if (Playing()) // Gotta make sure the player is in a level P_RestoreMusic(&players[consoleplayer]); diff --git a/src/i_sound.h b/src/i_sound.h index 084479ee1..450072cba 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -144,14 +144,6 @@ void I_InitMIDIMusic(void); */ void I_ShutdownMIDIMusic(void); -/** \brief The I_SetMIDIMusicVolume function - - \param volume volume to set at - - \return void -*/ -void I_SetMIDIMusicVolume(UINT8 volume); - /** \brief Registers a song handle to song data. \param data pointer to song data diff --git a/src/m_menu.c b/src/m_menu.c index f99f5d860..1f4c3ebc3 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1314,9 +1314,6 @@ static menuitem_t OP_SoundOptionsMenu[] = {IT_STRING | IT_KEYHANDLER, NULL, "Digital Music", M_ToggleDigital, 40}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Digital Music Volume", &cv_digmusicvolume, 50}, - {IT_STRING | IT_KEYHANDLER, NULL, "MIDI Music", M_ToggleMIDI, 70}, - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "MIDI Music Volume", &cv_midimusicvolume, 80}, - {IT_STRING | IT_CVAR, NULL, "Closed Captioning", &cv_closedcaptioning, 100}, }; @@ -9421,7 +9418,7 @@ static void M_ToggleSFX(INT32 choice) nosound = false; I_StartupSound(); if (nosound) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_Init(cv_soundvolume.value, cv_digmusicvolume.value); S_StartSound(NULL, sfx_strpst); OP_SoundOptionsMenu[6].status = IT_STRING | IT_CVAR; //M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); @@ -9474,7 +9471,7 @@ static void M_ToggleDigital(INT32 choice) nodigimusic = false; I_InitDigMusic(); if (nodigimusic) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_Init(cv_soundvolume.value, cv_digmusicvolume.value); S_StopMusic(); if (Playing()) P_RestoreMusic(&players[consoleplayer]); @@ -9531,7 +9528,7 @@ static void M_ToggleMIDI(INT32 choice) nomidimusic = false; I_InitMIDIMusic(); if (nomidimusic) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_Init(cv_soundvolume.value, cv_digmusicvolume.value); if (Playing()) P_RestoreMusic(&players[consoleplayer]); else diff --git a/src/s_sound.c b/src/s_sound.c index af152db5f..6a55523b8 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -77,7 +77,6 @@ static consvar_t precachesound = {"precachesound", "Off", CV_SAVE, CV_OnOff, NUL // actual general (maximum) sound & music volume, saved into the config consvar_t cv_soundvolume = {"soundvolume", "18", CV_SAVE, soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_digmusicvolume = {"digmusicvolume", "18", CV_SAVE, soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_midimusicvolume = {"midimusicvolume", "18", CV_SAVE, soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static void Captioning_OnChange(void) { @@ -788,7 +787,6 @@ void S_StopSound(void *origin) // static INT32 actualsfxvolume; // check for change through console static INT32 actualdigmusicvolume; -static INT32 actualmidimusicvolume; void S_UpdateSounds(void) { @@ -810,8 +808,6 @@ void S_UpdateSounds(void) S_SetSfxVolume (cv_soundvolume.value); if (actualdigmusicvolume != cv_digmusicvolume.value) S_SetDigMusicVolume (cv_digmusicvolume.value); - if (actualmidimusicvolume != cv_midimusicvolume.value) - S_SetMIDIMusicVolume (cv_midimusicvolume.value); // We're done now, if we're not in a level. if (gamestate != GS_LEVEL) @@ -1447,20 +1443,6 @@ void S_SetDigMusicVolume(INT32 volume) I_SetDigMusicVolume(volume&31); } -void S_SetMIDIMusicVolume(INT32 volume) -{ - if (volume < 0 || volume > 31) - CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n"); - - CV_SetValue(&cv_midimusicvolume, volume&0x1f); - actualmidimusicvolume = cv_midimusicvolume.value; //check for change of var - -#ifdef DJGPPDOS - I_SetMIDIMusicVolume(31); // Trick for buggy dos drivers. Win32 doesn't need this. -#endif - I_SetMIDIMusicVolume(volume&0x1f); -} - /// ------------------------ /// Init & Others /// ------------------------ @@ -1470,7 +1452,7 @@ void S_SetMIDIMusicVolume(INT32 volume) // Sets channels, SFX and music volume, // allocates channel buffer, sets S_sfx lookup. // -void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume) +void S_Init(INT32 sfxVolume, INT32 digMusicVolume) { INT32 i; @@ -1479,7 +1461,6 @@ void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume) S_SetSfxVolume(sfxVolume); S_SetDigMusicVolume(digMusicVolume); - S_SetMIDIMusicVolume(midiMusicVolume); SetChannelsNum(); diff --git a/src/s_sound.h b/src/s_sound.h index 4b9735480..3c3ff1b24 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -23,7 +23,7 @@ #define PICKUP_SOUND 0x8000 extern consvar_t stereoreverse; -extern consvar_t cv_soundvolume, cv_closedcaptioning, cv_digmusicvolume, cv_midimusicvolume; +extern consvar_t cv_soundvolume, cv_closedcaptioning, cv_digmusicvolume; extern consvar_t cv_numChannels; #ifdef SNDSERV @@ -99,7 +99,7 @@ void S_RegisterSoundStuff(void); // Initializes sound stuff, including volume // Sets channels, SFX and music volume, allocates channel buffer, sets S_sfx lookup. // -void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume); +void S_Init(INT32 sfxVolume, INT32 digMusicVolume); // // Per level startup code. @@ -150,7 +150,6 @@ void S_UpdateSounds(void); FUNCMATH fixed_t S_CalculateSoundDistance(fixed_t px1, fixed_t py1, fixed_t pz1, fixed_t px2, fixed_t py2, fixed_t pz2); void S_SetDigMusicVolume(INT32 volume); -void S_SetMIDIMusicVolume(INT32 volume); void S_SetSfxVolume(INT32 volume); INT32 S_OriginPlaying(void *origin); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 5211efe0a..a4758c854 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -783,19 +783,6 @@ void I_ShutdownMIDIMusic(void) music = NULL; } -void I_SetMIDIMusicVolume(UINT8 volume) -{ - // HACK: Until we stop using native MIDI, - // disable volume changes - (void)volume; - midi_volume = 31; - //midi_volume = volume; - - if (!midimode || !music) - return; - Mix_VolumeMusic((UINT32)midi_volume*128/31); -} - INT32 I_RegisterSong(void *data, size_t len) { music = Mix_LoadMUS_RW(SDL_RWFromMem(data, len), SDL_FALSE); From 58fbb4636f4a3dc940e31d6cce94e87dcd0dbaa7 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 07:39:45 -0400 Subject: [PATCH 02/30] Nix'd midimusicvolume other targets --- src/android/i_sound.c | 5 ----- src/djgppdos/i_sound.c | 11 +---------- src/dummy/i_sound.c | 5 ----- src/sdl/sdl_sound.c | 27 +++++++++++---------------- src/win32/win_cd.c | 1 - src/win32/win_snd.c | 8 -------- 6 files changed, 12 insertions(+), 45 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index ecf96f2f0..24db3e21d 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -84,11 +84,6 @@ void I_InitMIDIMusic(void){} void I_ShutdownMIDIMusic(void){} -void I_SetMIDIMusicVolume(INT32 volume) -{ - (void)volume; -} - INT32 I_RegisterSong(void *data, size_t len) { (void)data; diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 88fc807f4..dcf64fa69 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -140,15 +140,6 @@ void I_SetSfxVolume(INT32 volume) set_volume (Volset(volume),-1); } -void I_SetMIDIMusicVolume(INT32 volume) -{ - if (nomidimusic) - return; - - // Now set volume on output device. - set_volume (-1, Volset(volume)); -} - // // Starting a sound means adding it // to the current list of active sounds @@ -541,7 +532,7 @@ void I_SetDigMusicVolume(INT32 volume) return; // Now set volume on output device. -// CONS_Printf("Digital music not yet supported under DOS.\n"); + set_volume (-1, Volset(volume)); } boolean I_SetSongSpeed(float speed) diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 51dbb610d..89ccc2b6a 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -83,11 +83,6 @@ void I_InitMIDIMusic(void){} void I_ShutdownMIDIMusic(void){} -void I_SetMIDIMusicVolume(UINT8 volume) -{ - (void)volume; -} - INT32 I_RegisterSong(void *data, size_t len) { (void)data; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 63b51c625..e43afcb57 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1689,21 +1689,6 @@ INT32 I_RegisterSong(void *data, size_t len) return false; } -void I_SetMIDIMusicVolume(UINT8 volume) -{ -#ifdef HAVE_MIXER - if ((nomidimusic && nodigimusic) || !musicStarted) - return; - - if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); - musicvol = volume * 2; - if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); - Mix_VolumeMusic(musicvol); -#else - (void)volume; -#endif -} - #ifdef HAVE_LIBGME static void I_CleanupGME(void *userdata) { @@ -1963,7 +1948,17 @@ void I_StopDigSong(void) void I_SetDigMusicVolume(UINT8 volume) { - I_SetMIDIMusicVolume(volume); +#ifdef HAVE_MIXER + if ((nomidimusic && nodigimusic) || !musicStarted) + return; + + if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); + musicvol = volume * 2; + if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); + Mix_VolumeMusic(musicvol); +#else + (void)volume; +#endif } boolean I_SetSongSpeed(float speed) diff --git a/src/win32/win_cd.c b/src/win32/win_cd.c index f6c430748..2278fbdda 100644 --- a/src/win32/win_cd.c +++ b/src/win32/win_cd.c @@ -470,7 +470,6 @@ void I_PlayCD(UINT8 nTrack, UINT8 bLooping) //faB: stop MIDI music, MIDI music will restart if volume is upped later cv_digmusicvolume.value = 0; - cv_midimusicvolume.value = 0; I_StopSong (0); //faB: I don't use the notify message, I'm trying to minimize the delay diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 88f34abf8..281f48ea7 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -815,14 +815,6 @@ void I_ShutdownMIDIMusic(void) I_StopSong(0); } -void I_SetMIDIMusicVolume(UINT8 volume) -{ - // volume is 0 to 31. - midi_volume = volume; - if (midimode && music_stream) - FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); -} - INT32 I_RegisterSong(void *data, size_t len) { FMOD_CREATESOUNDEXINFO fmt; From 8b46bce155c0a1c62d12e537401687eb4701e7fa Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 07:49:09 -0400 Subject: [PATCH 03/30] CHANGED MIND: Nix'd S_MIDIMusic, I_PlaySong, and I_RegisterSong * music_lumpnum, music_data, music_handle are gone * Relevant interfaces I_PlaySong are transferred to I_StartDigSong --- src/android/i_sound.c | 7 ------ src/djgppdos/i_sound.c | 51 +++++++++++++++++++++--------------------- src/dummy/i_sound.c | 14 ------------ src/s_sound.c | 49 +--------------------------------------- 4 files changed, 27 insertions(+), 94 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 24db3e21d..c99f34096 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -84,13 +84,6 @@ void I_InitMIDIMusic(void){} void I_ShutdownMIDIMusic(void){} -INT32 I_RegisterSong(void *data, size_t len) -{ - (void)data; - (void)len; - return -1; -} - boolean I_PlaySong(INT32 handle, INT32 looping) { (void)handle; diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index dcf64fa69..6fd743aef 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -423,19 +423,6 @@ void I_ShutdownMusic(void) I_ShutdownDigMusic(); } -boolean I_PlaySong(INT32 handle, INT32 looping) -{ - handle = 0; - if (nomidimusic) - return false; - - islooping = looping; - musicdies = gametic + NEWTICRATE*30; - if (play_midi(currsong,looping)==0) - return true; - return false; -} - void I_PauseSong (INT32 handle) { handle = 0; @@ -486,11 +473,24 @@ void I_UnRegisterSong(INT32 handle) //destroy_midi(currsong); } -INT32 I_RegisterSong(void *data, size_t len) +boolean I_StartDigSong(const char *musicname, INT32 looping) { + ///////////////// + // Load the song! + + char *data; + size_t len; + lumpnum_t lumpnum = W_CheckNumForName(va("D_%s",musicname)); + + if (lumpnum == LUMPERROR) + return false; + + data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC); + len = W_LumpLength(lumpnum); + int e = len; //Alam: For error if (nomidimusic) - return 0; + return false; if (memcmp(data,"MThd",4)==0) // support mid file in WAD !!! { @@ -499,24 +499,25 @@ INT32 I_RegisterSong(void *data, size_t len) else { CONS_Printf("Music Lump is not a MIDI lump\n"); - return 0; + return false; } if (currsong==NULL) { CONS_Printf("Not a valid mid file : %d\n",e); - return 0; + return false; } - return 1; -} + ///////////////// + // Play the song! + handle = 0; + if (nomidimusic) + return false; -/// \todo Add OGG/MP3 support for dos -boolean I_StartDigSong(const char *musicname, INT32 looping) -{ - musicname = NULL; - looping = 0; - //CONS_Printf("I_StartDigSong: Not yet supported under DOS.\n"); + islooping = looping; + musicdies = gametic + NEWTICRATE*30; + if (play_midi(currsong,looping)==0) + return true; return false; } diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 89ccc2b6a..6b2ebeab2 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -83,20 +83,6 @@ void I_InitMIDIMusic(void){} void I_ShutdownMIDIMusic(void){} -INT32 I_RegisterSong(void *data, size_t len) -{ - (void)data; - (void)len; - return -1; -} - -boolean I_PlaySong(INT32 handle, boolean looping) -{ - (void)handle; - (void)looping; - return false; -} - void I_StopSong(INT32 handle) { (void)handle; diff --git a/src/s_sound.c b/src/s_sound.c index 6a55523b8..b921f733b 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1308,53 +1308,9 @@ const char *compat_special_music_slots[16] = #define music_playing (music_name[0]) // String is empty if no music is playing static char music_name[7]; // up to 6-character name -static lumpnum_t music_lumpnum; // lump number of music (used??) -static void *music_data; // music raw data -static INT32 music_handle; // once registered, the handle for the music static boolean mus_paused = 0; // whether songs are mus_paused -static boolean S_MIDIMusic(const char *mname, boolean looping) -{ - lumpnum_t mlumpnum; - void *mdata; - INT32 mhandle; - - if (nomidimusic || music_disabled) - return false; // didn't search. - - if (W_CheckNumForName(va("d_%s", mname)) == LUMPERROR) - return false; - mlumpnum = W_GetNumForName(va("d_%s", mname)); - - // load & register it - mdata = W_CacheLumpNum(mlumpnum, PU_MUSIC); - mhandle = I_RegisterSong(mdata, W_LumpLength(mlumpnum)); - -#ifdef MUSSERV - if (msg_id != -1) - { - struct musmsg msg_buffer; - - msg_buffer.msg_type = 6; - memset(msg_buffer.msg_text, 0, sizeof (msg_buffer.msg_text)); - sprintf(msg_buffer.msg_text, "d_%s", mname); - msgsnd(msg_id, (struct msgbuf*)&msg_buffer, sizeof (msg_buffer.msg_text), IPC_NOWAIT); - } -#endif - - // play it - if (!I_PlaySong(mhandle, looping)) - return false; - - strncpy(music_name, mname, 7); - music_name[6] = 0; - music_lumpnum = mlumpnum; - music_data = mdata; - music_handle = mhandle; - return true; -} - static boolean S_DigMusic(const char *mname, boolean looping) { if (nodigimusic || digital_disabled) @@ -1365,9 +1321,6 @@ static boolean S_DigMusic(const char *mname, boolean looping) strncpy(music_name, mname, 7); music_name[6] = 0; - music_lumpnum = LUMPERROR; - music_data = NULL; - music_handle = 0; return true; } @@ -1386,7 +1339,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) if (strncmp(music_name, mmusic, 6)) { S_StopMusic(); // shutdown old music - if (!S_DigMusic(mmusic, looping) && !S_MIDIMusic(mmusic, looping)) + if (!S_DigMusic(mmusic, looping)) { CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic); return; From 0bc9576eb0b85a6f9efa3869e98f132231696609 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 07:50:02 -0400 Subject: [PATCH 04/30] Revert "CHANGED MIND: Nix'd S_MIDIMusic, I_PlaySong, and I_RegisterSong" This reverts commit 8b46bce155c0a1c62d12e537401687eb4701e7fa. --- src/android/i_sound.c | 7 ++++++ src/djgppdos/i_sound.c | 51 +++++++++++++++++++++--------------------- src/dummy/i_sound.c | 14 ++++++++++++ src/s_sound.c | 49 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 94 insertions(+), 27 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index c99f34096..24db3e21d 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -84,6 +84,13 @@ void I_InitMIDIMusic(void){} void I_ShutdownMIDIMusic(void){} +INT32 I_RegisterSong(void *data, size_t len) +{ + (void)data; + (void)len; + return -1; +} + boolean I_PlaySong(INT32 handle, INT32 looping) { (void)handle; diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 6fd743aef..dcf64fa69 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -423,6 +423,19 @@ void I_ShutdownMusic(void) I_ShutdownDigMusic(); } +boolean I_PlaySong(INT32 handle, INT32 looping) +{ + handle = 0; + if (nomidimusic) + return false; + + islooping = looping; + musicdies = gametic + NEWTICRATE*30; + if (play_midi(currsong,looping)==0) + return true; + return false; +} + void I_PauseSong (INT32 handle) { handle = 0; @@ -473,24 +486,11 @@ void I_UnRegisterSong(INT32 handle) //destroy_midi(currsong); } -boolean I_StartDigSong(const char *musicname, INT32 looping) +INT32 I_RegisterSong(void *data, size_t len) { - ///////////////// - // Load the song! - - char *data; - size_t len; - lumpnum_t lumpnum = W_CheckNumForName(va("D_%s",musicname)); - - if (lumpnum == LUMPERROR) - return false; - - data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC); - len = W_LumpLength(lumpnum); - int e = len; //Alam: For error if (nomidimusic) - return false; + return 0; if (memcmp(data,"MThd",4)==0) // support mid file in WAD !!! { @@ -499,25 +499,24 @@ boolean I_StartDigSong(const char *musicname, INT32 looping) else { CONS_Printf("Music Lump is not a MIDI lump\n"); - return false; + return 0; } if (currsong==NULL) { CONS_Printf("Not a valid mid file : %d\n",e); - return false; + return 0; } - ///////////////// - // Play the song! - handle = 0; - if (nomidimusic) - return false; + return 1; +} - islooping = looping; - musicdies = gametic + NEWTICRATE*30; - if (play_midi(currsong,looping)==0) - return true; +/// \todo Add OGG/MP3 support for dos +boolean I_StartDigSong(const char *musicname, INT32 looping) +{ + musicname = NULL; + looping = 0; + //CONS_Printf("I_StartDigSong: Not yet supported under DOS.\n"); return false; } diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 6b2ebeab2..89ccc2b6a 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -83,6 +83,20 @@ void I_InitMIDIMusic(void){} void I_ShutdownMIDIMusic(void){} +INT32 I_RegisterSong(void *data, size_t len) +{ + (void)data; + (void)len; + return -1; +} + +boolean I_PlaySong(INT32 handle, boolean looping) +{ + (void)handle; + (void)looping; + return false; +} + void I_StopSong(INT32 handle) { (void)handle; diff --git a/src/s_sound.c b/src/s_sound.c index b921f733b..6a55523b8 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1308,9 +1308,53 @@ const char *compat_special_music_slots[16] = #define music_playing (music_name[0]) // String is empty if no music is playing static char music_name[7]; // up to 6-character name +static lumpnum_t music_lumpnum; // lump number of music (used??) +static void *music_data; // music raw data +static INT32 music_handle; // once registered, the handle for the music static boolean mus_paused = 0; // whether songs are mus_paused +static boolean S_MIDIMusic(const char *mname, boolean looping) +{ + lumpnum_t mlumpnum; + void *mdata; + INT32 mhandle; + + if (nomidimusic || music_disabled) + return false; // didn't search. + + if (W_CheckNumForName(va("d_%s", mname)) == LUMPERROR) + return false; + mlumpnum = W_GetNumForName(va("d_%s", mname)); + + // load & register it + mdata = W_CacheLumpNum(mlumpnum, PU_MUSIC); + mhandle = I_RegisterSong(mdata, W_LumpLength(mlumpnum)); + +#ifdef MUSSERV + if (msg_id != -1) + { + struct musmsg msg_buffer; + + msg_buffer.msg_type = 6; + memset(msg_buffer.msg_text, 0, sizeof (msg_buffer.msg_text)); + sprintf(msg_buffer.msg_text, "d_%s", mname); + msgsnd(msg_id, (struct msgbuf*)&msg_buffer, sizeof (msg_buffer.msg_text), IPC_NOWAIT); + } +#endif + + // play it + if (!I_PlaySong(mhandle, looping)) + return false; + + strncpy(music_name, mname, 7); + music_name[6] = 0; + music_lumpnum = mlumpnum; + music_data = mdata; + music_handle = mhandle; + return true; +} + static boolean S_DigMusic(const char *mname, boolean looping) { if (nodigimusic || digital_disabled) @@ -1321,6 +1365,9 @@ static boolean S_DigMusic(const char *mname, boolean looping) strncpy(music_name, mname, 7); music_name[6] = 0; + music_lumpnum = LUMPERROR; + music_data = NULL; + music_handle = 0; return true; } @@ -1339,7 +1386,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) if (strncmp(music_name, mmusic, 6)) { S_StopMusic(); // shutdown old music - if (!S_DigMusic(mmusic, looping)) + if (!S_DigMusic(mmusic, looping) && !S_MIDIMusic(mmusic, looping)) { CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic); return; From e42defa29938182e66d3b97213f53d9a2d8cdea3 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 09:02:14 -0400 Subject: [PATCH 05/30] Playback routines: Load, Play, Pause, Stop, Unload * Re-purpose I_LoadSong for digital music loading * I_StartDigSong logic split between I_LoadSong and I_PlaySong * Pause, Stop, and Unload routines are combined from Digi and MIDI * music_lumpnum, music_data, music_handle from s_sound.c are gone --- src/i_sound.h | 41 ++------ src/locale/en.po | 2 +- src/locale/srb2.pot | 2 +- src/m_menu.c | 4 +- src/s_sound.c | 85 +++++++-------- src/s_sound.h | 2 +- src/sdl/mixer_sound.c | 237 ++++++++++++++++-------------------------- 7 files changed, 145 insertions(+), 228 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 450072cba..99e343491 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -136,14 +136,6 @@ void I_ResumeSong(INT32 handle); // MIDI I/O // -/** \brief Startup the MIDI music system -*/ -void I_InitMIDIMusic(void); - -/** \brief Shutdown the MIDI music system -*/ -void I_ShutdownMIDIMusic(void); - /** \brief Registers a song handle to song data. \param data pointer to song data @@ -153,7 +145,7 @@ void I_ShutdownMIDIMusic(void); \todo Remove this */ -INT32 I_RegisterSong(void *data, size_t len); +boolean I_LoadSong(void *data, size_t len); /** \brief Called by anything that wishes to start music @@ -164,7 +156,7 @@ INT32 I_RegisterSong(void *data, size_t len); \todo pass music name, not handle */ -boolean I_PlaySong(INT32 handle, boolean looping); +boolean I_PlaySong(void); /** \brief Stops a song over 3 seconds @@ -173,46 +165,25 @@ boolean I_PlaySong(INT32 handle, boolean looping); /todo drop handle */ -void I_StopSong(INT32 handle); +void I_StopSong(void); -/** \brief See ::I_RegisterSong, then think backwards +/** \brief See ::I_LoadSong, then think backwards \param handle song handle - \sa I_RegisterSong + \sa I_LoadSong \todo remove midi handle */ -void I_UnRegisterSong(INT32 handle); +void I_UnloadSong(void); // // DIGMUSIC I/O // -/** \brief Startup the music system -*/ -void I_InitDigMusic(void); - -/** \brief Shutdown the music system -*/ -void I_ShutdownDigMusic(void); - boolean I_SetSongSpeed(float speed); boolean I_SetSongTrack(INT32 track); -/** \brief The I_StartDigSong function - - \param musicname music lump name - \param looping if true, loop the song - - \return if true, song playing -*/ -boolean I_StartDigSong(const char *musicname, boolean looping); - -/** \brief stop non-MIDI song -*/ -void I_StopDigSong(void); - /** \brief The I_SetDigMusicVolume function \param volume volume to set at diff --git a/src/locale/en.po b/src/locale/en.po index 069930b81..cc1426e08 100644 --- a/src/locale/en.po +++ b/src/locale/en.po @@ -3825,7 +3825,7 @@ msgid "Music lump is not MID music format\n" msgstr "" #: win32/win_snd.c:2128 -msgid "I_RegisterSong: StreamBufferSetup FAILED" +msgid "I_LoadSong: StreamBufferSetup FAILED" msgstr "" #: win32/win_sys.c:892 diff --git a/src/locale/srb2.pot b/src/locale/srb2.pot index ced13bbe6..4203cfe75 100644 --- a/src/locale/srb2.pot +++ b/src/locale/srb2.pot @@ -4021,7 +4021,7 @@ msgid "Music lump is not MID music format\n" msgstr "" #: win32/win_snd.c:2126 -msgid "I_RegisterSong: StreamBufferSetup FAILED" +msgid "I_LoadSong: StreamBufferSetup FAILED" msgstr "" #: win32/win_sys.c:894 diff --git a/src/m_menu.c b/src/m_menu.c index 1f4c3ebc3..9764cd728 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9469,7 +9469,7 @@ static void M_ToggleDigital(INT32 choice) if (nodigimusic) { nodigimusic = false; - I_InitDigMusic(); + I_InitMusic(); if (nodigimusic) return; S_Init(cv_soundvolume.value, cv_digmusicvolume.value); S_StopMusic(); @@ -9526,7 +9526,7 @@ static void M_ToggleMIDI(INT32 choice) if (nomidimusic) { nomidimusic = false; - I_InitMIDIMusic(); + I_InitMusic(); if (nomidimusic) return; S_Init(cv_soundvolume.value, cv_digmusicvolume.value); if (Playing()) diff --git a/src/s_sound.c b/src/s_sound.c index 6a55523b8..531eb7642 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -807,7 +807,7 @@ void S_UpdateSounds(void) if (actualsfxvolume != cv_soundvolume.value) S_SetSfxVolume (cv_soundvolume.value); if (actualdigmusicvolume != cv_digmusicvolume.value) - S_SetDigMusicVolume (cv_digmusicvolume.value); + S_SetMusicVolume (cv_digmusicvolume.value); // We're done now, if we're not in a level. if (gamestate != GS_LEVEL) @@ -1308,13 +1308,11 @@ const char *compat_special_music_slots[16] = #define music_playing (music_name[0]) // String is empty if no music is playing static char music_name[7]; // up to 6-character name -static lumpnum_t music_lumpnum; // lump number of music (used??) -static void *music_data; // music raw data -static INT32 music_handle; // once registered, the handle for the music -static boolean mus_paused = 0; // whether songs are mus_paused +static boolean mus_forcemidi = 0; // force midi even when digital exists +static boolean mus_paused = 0; // whether songs are mus_paused -static boolean S_MIDIMusic(const char *mname, boolean looping) +static boolean S_LoadMusic(const char *mname, boolean looping) { lumpnum_t mlumpnum; void *mdata; @@ -1323,51 +1321,57 @@ static boolean S_MIDIMusic(const char *mname, boolean looping) if (nomidimusic || music_disabled) return false; // didn't search. - if (W_CheckNumForName(va("d_%s", mname)) == LUMPERROR) - return false; - mlumpnum = W_GetNumForName(va("d_%s", mname)); + if (mus_forcemidi) + { + if (W_CheckNumForName(va("d_%s", mname)) == LUMPERROR) + return false; + mlumpnum = W_GetNumForName(va("d_%s", mname)); + } + else + { + if (W_CheckNumForName(va("o_%s", mname)) != LUMPERROR) + mlumpnum = W_GetNumForName(va("o_%s", mname)); + else if (W_CheckNumForName(va("d_%s", mname)) != LUMPERROR) + mlumpnum = W_GetNumForName(va("d_%s", mname)); + else + return false; + } // load & register it mdata = W_CacheLumpNum(mlumpnum, PU_MUSIC); - mhandle = I_RegisterSong(mdata, W_LumpLength(mlumpnum)); -#ifdef MUSSERV - if (msg_id != -1) + if (I_LoadSong(mdata, W_LumpLength(mlumpnum))) { - struct musmsg msg_buffer; - - msg_buffer.msg_type = 6; - memset(msg_buffer.msg_text, 0, sizeof (msg_buffer.msg_text)); - sprintf(msg_buffer.msg_text, "d_%s", mname); - msgsnd(msg_id, (struct msgbuf*)&msg_buffer, sizeof (msg_buffer.msg_text), IPC_NOWAIT); + strncpy(music_name, mname, 7); + music_name[6] = 0; + return true; } -#endif - - // play it - if (!I_PlaySong(mhandle, looping)) + else return false; - - strncpy(music_name, mname, 7); - music_name[6] = 0; - music_lumpnum = mlumpnum; - music_data = mdata; - music_handle = mhandle; - return true; } -static boolean S_DigMusic(const char *mname, boolean looping) +static void S_UnloadSong(void) +{ + I_UnloadSong(); + music_name[0] = 0; +} + +static boolean S_PlayMusic(const char *mname, boolean looping) { if (nodigimusic || digital_disabled) return false; // try midi - if (!I_StartDigSong(mname, looping)) + if (!S_LoadSong(mname, looping)) return false; + if (!I_PlaySong()) + { + S_UnloadSong(); + return false; + } + strncpy(music_name, mname, 7); music_name[6] = 0; - music_lumpnum = LUMPERROR; - music_data = NULL; - music_handle = 0; return true; } @@ -1386,7 +1390,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) if (strncmp(music_name, mmusic, 6)) { S_StopMusic(); // shutdown old music - if (!S_DigMusic(mmusic, looping) && !S_MIDIMusic(mmusic, looping)) + if (!S_LoadMusic(mmusic, looping) && !S_PlayMusic(mmusic, looping)) { CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic); return; @@ -1408,12 +1412,9 @@ void S_StopMusic(void) if (mus_paused) I_ResumeSong(music_handle); - if (!nodigimusic) - I_StopDigSong(); - S_SpeedMusic(1.0f); - I_StopSong(music_handle); - I_UnRegisterSong(music_handle); + I_StopSong(); + I_UnloadSong(); #ifndef HAVE_SDL //SDL uses RWOPS Z_ChangeTag(music_data, PU_CACHE); @@ -1429,7 +1430,7 @@ void S_StopMusic(void) } } -void S_SetDigMusicVolume(INT32 volume) +void S_SetMusicVolume(INT32 volume) { if (volume < 0 || volume > 31) CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n"); @@ -1460,7 +1461,7 @@ void S_Init(INT32 sfxVolume, INT32 digMusicVolume) return; S_SetSfxVolume(sfxVolume); - S_SetDigMusicVolume(digMusicVolume); + S_SetMusicVolume(digMusicVolume); SetChannelsNum(); diff --git a/src/s_sound.h b/src/s_sound.h index 3c3ff1b24..053f58669 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -149,7 +149,7 @@ void S_UpdateSounds(void); FUNCMATH fixed_t S_CalculateSoundDistance(fixed_t px1, fixed_t py1, fixed_t pz1, fixed_t px2, fixed_t py2, fixed_t pz2); -void S_SetDigMusicVolume(INT32 volume); +void S_SetMusicVolume(INT32 volume); void S_SetSfxVolume(INT32 volume); INT32 S_OriginPlaying(void *origin); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index a4758c854..7e9bd4bde 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -466,12 +466,29 @@ static void mix_gme(void *udata, Uint8 *stream, int len) FUNCMATH void I_InitMusic(void) { +#ifdef HAVE_LIBGME + gme = NULL; + current_track = -1; +#endif } void I_ShutdownMusic(void) { - I_ShutdownDigMusic(); - I_ShutdownMIDIMusic(); + if (midimode) + return; +#ifdef HAVE_LIBGME + if (gme) + { + Mix_HookMusic(NULL, NULL); + gme_delete(gme); + gme = NULL; + } +#endif + if (!music) + return; + Mix_HookMusicFinished(NULL); + Mix_FreeMusic(music); + music = NULL; } void I_PauseSong(INT32 handle) @@ -492,51 +509,74 @@ void I_ResumeSong(INT32 handle) // Digital Music // -void I_InitDigMusic(void) +void I_SetDigMusicVolume(UINT8 volume) { -#ifdef HAVE_LIBGME - gme = NULL; - current_track = -1; -#endif + music_volume = volume; + if (midimode || !music) + return; + Mix_VolumeMusic((UINT32)volume*128/31); } -void I_ShutdownDigMusic(void) +boolean I_SetSongSpeed(float speed) { - if (midimode) - return; + if (speed > 250.0f) + speed = 250.0f; //limit speed up to 250x #ifdef HAVE_LIBGME if (gme) { - Mix_HookMusic(NULL, NULL); - gme_delete(gme); - gme = NULL; + SDL_LockAudio(); + gme_set_tempo(gme, speed); + SDL_UnlockAudio(); + return true; } +#else + (void)speed; #endif - if (!music) - return; - Mix_HookMusicFinished(NULL); - Mix_FreeMusic(music); - music = NULL; + return false; } -boolean I_StartDigSong(const char *musicname, boolean looping) +boolean I_SetSongTrack(int track) { - char *data; - size_t len; - lumpnum_t lumpnum = W_CheckNumForName(va("O_%s",musicname)); +#ifdef HAVE_LIBGME + if (current_track == track) + return false; + // If the specified track is within the number of tracks playing, then change it + if (gme) + { + SDL_LockAudio(); + if (track >= 0 + && track < gme_track_count(gme)) + { + gme_err_t gme_e = gme_start_track(gme, track); + if (gme_e != NULL) + { + CONS_Alert(CONS_ERROR, "GME error: %s\n", gme_e); + return false; + } + current_track = track; + SDL_UnlockAudio(); + return true; + } + SDL_UnlockAudio(); + return false; + } +#endif + (void)track; + return false; +} + +// +// MIDI Music +// + +boolean I_LoadSong(void *data, size_t len) +{ I_Assert(!music); #ifdef HAVE_LIBGME I_Assert(!gme); #endif - if (lumpnum == LUMPERROR) - return false; - midimode = false; - - data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC); - len = W_LumpLength(lumpnum); - #ifdef HAVE_LIBGME if ((UINT8)data[0] == 0x1F && (UINT8)data[1] == 0x8B) @@ -627,10 +667,6 @@ boolean I_StartDigSong(const char *musicname, boolean looping) else if (!gme_open_data(data, len, &gme, 44100)) { gme_equalizer_t eq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; - gme_start_track(gme, 0); - current_track = 0; - gme_set_equalizer(gme, &eq); - Mix_HookMusic(mix_gme, gme); return true; } #endif @@ -639,7 +675,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) if (!music) { CONS_Alert(CONS_ERROR, "Mix_LoadMUS_RW: %s\n", Mix_GetError()); - return true; + return false; } // Find the OGG loop point. @@ -677,10 +713,28 @@ boolean I_StartDigSong(const char *musicname, boolean looping) } } + return true; +} + +boolean I_PlaySong(void) +{ + if (!music) + return false; +#ifdef HAVE_GME + if (gme) + { + gme_start_track(gme, 0); + current_track = 0; + gme_set_equalizer(gme, &eq); + Mix_HookMusic(mix_gme, gme); + return true; + } +#endif + if (Mix_PlayMusic(music, looping && loop_point == 0.0f ? -1 : 0) == -1) { CONS_Alert(CONS_ERROR, "Mix_PlayMusic: %s\n", Mix_GetError()); - return true; + return false; } Mix_VolumeMusic((UINT32)music_volume*128/31); @@ -689,7 +743,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) return true; } -void I_StopDigSong(void) +void I_StopSong(void) { if (midimode) return; @@ -710,116 +764,7 @@ void I_StopDigSong(void) music = NULL; } -void I_SetDigMusicVolume(UINT8 volume) -{ - music_volume = volume; - if (midimode || !music) - return; - Mix_VolumeMusic((UINT32)volume*128/31); -} - -boolean I_SetSongSpeed(float speed) -{ - if (speed > 250.0f) - speed = 250.0f; //limit speed up to 250x -#ifdef HAVE_LIBGME - if (gme) - { - SDL_LockAudio(); - gme_set_tempo(gme, speed); - SDL_UnlockAudio(); - return true; - } -#else - (void)speed; -#endif - return false; -} - -boolean I_SetSongTrack(int track) -{ -#ifdef HAVE_LIBGME - if (current_track == track) - return false; - - // If the specified track is within the number of tracks playing, then change it - if (gme) - { - SDL_LockAudio(); - if (track >= 0 - && track < gme_track_count(gme)) - { - gme_err_t gme_e = gme_start_track(gme, track); - if (gme_e != NULL) - { - CONS_Alert(CONS_ERROR, "GME error: %s\n", gme_e); - return false; - } - current_track = track; - SDL_UnlockAudio(); - return true; - } - SDL_UnlockAudio(); - return false; - } -#endif - (void)track; - return false; -} - -// -// MIDI Music -// - -FUNCMATH void I_InitMIDIMusic(void) -{ -} - -void I_ShutdownMIDIMusic(void) -{ - if (!midimode || !music) - return; - Mix_FreeMusic(music); - music = NULL; -} - -INT32 I_RegisterSong(void *data, size_t len) -{ - music = Mix_LoadMUS_RW(SDL_RWFromMem(data, len), SDL_FALSE); - if (!music) - { - CONS_Alert(CONS_ERROR, "Mix_LoadMUS_RW: %s\n", Mix_GetError()); - return -1; - } - return 1337; -} - -boolean I_PlaySong(INT32 handle, boolean looping) -{ - (void)handle; - - midimode = true; - - if (Mix_PlayMusic(music, looping ? -1 : 0) == -1) - { - CONS_Alert(CONS_ERROR, "Mix_PlayMusic: %s\n", Mix_GetError()); - return false; - } - - Mix_VolumeMusic((UINT32)midi_volume*128/31); - return true; -} - -void I_StopSong(INT32 handle) -{ - if (!midimode || !music) - return; - - (void)handle; - Mix_HaltMusic(); -} - -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { if (!midimode || !music) return; From 7efab8b3141698afc2e3eea2583455fb35102e99 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 09:06:13 -0400 Subject: [PATCH 06/30] Revert "Nix'd midimusicvolume", don't know what I want to do with this yet This reverts commit b5c30958203c8cf92e0e0addad4fc87f9351c60e. # Conflicts: # src/i_sound.h # src/s_sound.c # src/s_sound.h # src/sdl/mixer_sound.c --- src/d_main.c | 2 +- src/d_netcmd.c | 2 ++ src/i_sound.h | 8 ++++++++ src/m_menu.c | 9 ++++++--- src/s_sound.c | 25 ++++++++++++++++++++++--- src/s_sound.h | 7 ++++--- src/sdl/mixer_sound.c | 13 +++++++++++++ 7 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index f53761d6d..95af1f754 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1212,7 +1212,7 @@ void D_SRB2Main(void) } I_StartupSound(); I_InitMusic(); - S_Init(cv_soundvolume.value, cv_digmusicvolume.value); + S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); CONS_Printf("ST_Init(): Init status bar.\n"); ST_Init(); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index f1130f736..0cb1d4497 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -790,6 +790,7 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_soundvolume); CV_RegisterVar(&cv_closedcaptioning); CV_RegisterVar(&cv_digmusicvolume); + CV_RegisterVar(&cv_midimusicvolume); CV_RegisterVar(&cv_numChannels); // i_cdmus.c @@ -4057,6 +4058,7 @@ static void Command_RestartAudio_f(void) I_SetSfxVolume(cv_soundvolume.value); I_SetDigMusicVolume(cv_digmusicvolume.value); + I_SetMIDIMusicVolume(cv_midimusicvolume.value); if (Playing()) // Gotta make sure the player is in a level P_RestoreMusic(&players[consoleplayer]); diff --git a/src/i_sound.h b/src/i_sound.h index 99e343491..5368f3fd6 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -136,6 +136,14 @@ void I_ResumeSong(INT32 handle); // MIDI I/O // +/** \brief The I_SetMIDIMusicVolume function + + \param volume volume to set at + + \return void +*/ +void I_SetMIDIMusicVolume(UINT8 volume); + /** \brief Registers a song handle to song data. \param data pointer to song data diff --git a/src/m_menu.c b/src/m_menu.c index 9764cd728..fd3deab84 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1314,6 +1314,9 @@ static menuitem_t OP_SoundOptionsMenu[] = {IT_STRING | IT_KEYHANDLER, NULL, "Digital Music", M_ToggleDigital, 40}, {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Digital Music Volume", &cv_digmusicvolume, 50}, + {IT_STRING | IT_KEYHANDLER, NULL, "MIDI Music", M_ToggleMIDI, 70}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "MIDI Music Volume", &cv_midimusicvolume, 80}, + {IT_STRING | IT_CVAR, NULL, "Closed Captioning", &cv_closedcaptioning, 100}, }; @@ -9418,7 +9421,7 @@ static void M_ToggleSFX(INT32 choice) nosound = false; I_StartupSound(); if (nosound) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value); + S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); S_StartSound(NULL, sfx_strpst); OP_SoundOptionsMenu[6].status = IT_STRING | IT_CVAR; //M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); @@ -9471,7 +9474,7 @@ static void M_ToggleDigital(INT32 choice) nodigimusic = false; I_InitMusic(); if (nodigimusic) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value); + S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); S_StopMusic(); if (Playing()) P_RestoreMusic(&players[consoleplayer]); @@ -9528,7 +9531,7 @@ static void M_ToggleMIDI(INT32 choice) nomidimusic = false; I_InitMusic(); if (nomidimusic) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value); + S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); if (Playing()) P_RestoreMusic(&players[consoleplayer]); else diff --git a/src/s_sound.c b/src/s_sound.c index 531eb7642..81e3e78e6 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -77,6 +77,7 @@ static consvar_t precachesound = {"precachesound", "Off", CV_SAVE, CV_OnOff, NUL // actual general (maximum) sound & music volume, saved into the config consvar_t cv_soundvolume = {"soundvolume", "18", CV_SAVE, soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_digmusicvolume = {"digmusicvolume", "18", CV_SAVE, soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_midimusicvolume = {"midimusicvolume", "18", CV_SAVE, soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static void Captioning_OnChange(void) { @@ -787,6 +788,7 @@ void S_StopSound(void *origin) // static INT32 actualsfxvolume; // check for change through console static INT32 actualdigmusicvolume; +static INT32 actualmidimusicvolume; void S_UpdateSounds(void) { @@ -807,7 +809,9 @@ void S_UpdateSounds(void) if (actualsfxvolume != cv_soundvolume.value) S_SetSfxVolume (cv_soundvolume.value); if (actualdigmusicvolume != cv_digmusicvolume.value) - S_SetMusicVolume (cv_digmusicvolume.value); + S_SetDigMusicVolume (cv_digmusicvolume.value); + if (actualmidimusicvolume != cv_midimusicvolume.value) + S_SetMIDIMusicVolume (cv_midimusicvolume.value); // We're done now, if we're not in a level. if (gamestate != GS_LEVEL) @@ -1444,6 +1448,20 @@ void S_SetMusicVolume(INT32 volume) I_SetDigMusicVolume(volume&31); } +void S_SetMIDIMusicVolume(INT32 volume) +{ + if (volume < 0 || volume > 31) + CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n"); + + CV_SetValue(&cv_midimusicvolume, volume&0x1f); + actualmidimusicvolume = cv_midimusicvolume.value; //check for change of var + +#ifdef DJGPPDOS + I_SetMIDIMusicVolume(31); // Trick for buggy dos drivers. Win32 doesn't need this. +#endif + I_SetMIDIMusicVolume(volume&0x1f); +} + /// ------------------------ /// Init & Others /// ------------------------ @@ -1453,7 +1471,7 @@ void S_SetMusicVolume(INT32 volume) // Sets channels, SFX and music volume, // allocates channel buffer, sets S_sfx lookup. // -void S_Init(INT32 sfxVolume, INT32 digMusicVolume) +void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume) { INT32 i; @@ -1461,7 +1479,8 @@ void S_Init(INT32 sfxVolume, INT32 digMusicVolume) return; S_SetSfxVolume(sfxVolume); - S_SetMusicVolume(digMusicVolume); + S_SetDigMusicVolume(digMusicVolume); + S_SetMIDIMusicVolume(midiMusicVolume); SetChannelsNum(); diff --git a/src/s_sound.h b/src/s_sound.h index 053f58669..4b9735480 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -23,7 +23,7 @@ #define PICKUP_SOUND 0x8000 extern consvar_t stereoreverse; -extern consvar_t cv_soundvolume, cv_closedcaptioning, cv_digmusicvolume; +extern consvar_t cv_soundvolume, cv_closedcaptioning, cv_digmusicvolume, cv_midimusicvolume; extern consvar_t cv_numChannels; #ifdef SNDSERV @@ -99,7 +99,7 @@ void S_RegisterSoundStuff(void); // Initializes sound stuff, including volume // Sets channels, SFX and music volume, allocates channel buffer, sets S_sfx lookup. // -void S_Init(INT32 sfxVolume, INT32 digMusicVolume); +void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume); // // Per level startup code. @@ -149,7 +149,8 @@ void S_UpdateSounds(void); FUNCMATH fixed_t S_CalculateSoundDistance(fixed_t px1, fixed_t py1, fixed_t pz1, fixed_t px2, fixed_t py2, fixed_t pz2); -void S_SetMusicVolume(INT32 volume); +void S_SetDigMusicVolume(INT32 volume); +void S_SetMIDIMusicVolume(INT32 volume); void S_SetSfxVolume(INT32 volume); INT32 S_OriginPlaying(void *origin); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 7e9bd4bde..113c75d63 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -764,6 +764,19 @@ void I_StopSong(void) music = NULL; } +void I_SetMIDIMusicVolume(UINT8 volume) +{ + // HACK: Until we stop using native MIDI, + // disable volume changes + (void)volume; + midi_volume = 31; + //midi_volume = volume; + + if (!midimode || !music) + return; + Mix_VolumeMusic((UINT32)midi_volume*128/31); +} + void I_UnloadSong(void) { if (!midimode || !music) From 75cbfab8c6804f3f84e5c131601868e130bb7dac Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 09:06:31 -0400 Subject: [PATCH 07/30] Playback routines other targets --- src/android/i_sound.c | 25 ++------- src/djgppdos/i_sound.c | 50 ++--------------- src/dummy/i_sound.c | 25 ++------- src/sdl/sdl_sound.c | 75 +++++++------------------ src/win32/win_snd.c | 124 +++++++++++++++-------------------------- 5 files changed, 81 insertions(+), 218 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 24db3e21d..109faf57d 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -80,30 +80,26 @@ void I_ResumeSong(INT32 handle) UINT8 midimusic_started = 0; -void I_InitMIDIMusic(void){} - -void I_ShutdownMIDIMusic(void){} - -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(void *data, size_t len) { (void)data; (void)len; return -1; } -boolean I_PlaySong(INT32 handle, INT32 looping) +boolean I_PlaySong(void) { (void)handle; (void)looping; return false; } -void I_StopSong(INT32 handle) +void I_StopSong(void) { (void)handle; } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { (void)handle; } @@ -114,19 +110,6 @@ void I_UnRegisterSong(INT32 handle) UINT8 digmusic_started = 0; -void I_InitDigMusic(void){} - -void I_ShutdownDigMusic(void){} - -boolean I_StartDigSong(const char *musicname, INT32 looping) -{ - (void)musicname; - (void)looping; - return false; -} - -void I_StopDigSong(void){} - void I_SetDigMusicVolume(INT32 volume) { (void)volume; diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index dcf64fa69..993e164c9 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -380,7 +380,7 @@ static MIDI *load_midi_mem(char *mempointer,int *e) return midi; } -void I_InitMIDIMusic(void) +void I_InitMusic(void) { if (nomidimusic) return; @@ -389,7 +389,7 @@ void I_InitMIDIMusic(void) music_started = true; } -void I_ShutdownMIDIMusic(void) +void I_ShutdownMusic(void) { if ( !music_started ) return; @@ -399,31 +399,7 @@ void I_ShutdownMIDIMusic(void) music_started=false; } -void I_InitDigMusic(void) -{ -// CONS_Printf("Digital music not yet supported under DOS.\n"); -} - -void I_ShutdownDigMusic(void) -{ -// CONS_Printf("Digital music not yet supported under DOS.\n"); -} - -void I_InitMusic(void) -{ - if (!nodigimusic) - I_InitDigMusic(); - if (!nomidimusic) - I_InitMIDIMusic(); -} - -void I_ShutdownMusic(void) -{ - I_ShutdownMIDIMusic(); - I_ShutdownDigMusic(); -} - -boolean I_PlaySong(INT32 handle, INT32 looping) +boolean I_PlaySong(void) { handle = 0; if (nomidimusic) @@ -454,7 +430,7 @@ void I_ResumeSong (INT32 handle) midi_resume(); } -void I_StopSong(INT32 handle) +void I_StopSong(void) { handle = 0; if (nomidimusic) @@ -477,7 +453,7 @@ int I_QrySongPlaying(int handle) } #endif -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { handle = 0; if (nomidimusic) @@ -486,7 +462,7 @@ void I_UnRegisterSong(INT32 handle) //destroy_midi(currsong); } -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(void *data, size_t len) { int e = len; //Alam: For error if (nomidimusic) @@ -511,20 +487,6 @@ INT32 I_RegisterSong(void *data, size_t len) return 1; } -/// \todo Add OGG/MP3 support for dos -boolean I_StartDigSong(const char *musicname, INT32 looping) -{ - musicname = NULL; - looping = 0; - //CONS_Printf("I_StartDigSong: Not yet supported under DOS.\n"); - return false; -} - -void I_StopDigSong(void) -{ -// CONS_Printf("I_StopDigSong: Not yet supported under DOS.\n"); -} - void I_SetDigMusicVolume(INT32 volume) { volume = 0; diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 89ccc2b6a..ef186d5f3 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -79,30 +79,26 @@ void I_ResumeSong(INT32 handle) // MIDI I/O // -void I_InitMIDIMusic(void){} - -void I_ShutdownMIDIMusic(void){} - -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(void *data, size_t len) { (void)data; (void)len; return -1; } -boolean I_PlaySong(INT32 handle, boolean looping) +boolean I_PlaySong(void) { (void)handle; (void)looping; return false; } -void I_StopSong(INT32 handle) +void I_StopSong(void) { (void)handle; } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { (void)handle; } @@ -111,19 +107,6 @@ void I_UnRegisterSong(INT32 handle) // DIGMUSIC I/O // -void I_InitDigMusic(void){} - -void I_ShutdownDigMusic(void){} - -boolean I_StartDigSong(const char *musicname, boolean looping) -{ - (void)musicname; - (void)looping; - return false; -} - -void I_StopDigSong(void){} - void I_SetDigMusicVolume(UINT8 volume) { (void)volume; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index e43afcb57..fb4c301ae 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1313,12 +1313,6 @@ void I_StartupSound(void) // MUSIC API. // -void I_ShutdownMIDIMusic(void) -{ - nomidimusic = false; - if (nodigimusic) I_ShutdownMusic(); -} - #ifdef HAVE_LIBGME static void I_ShutdownGMEMusic(void) { @@ -1330,12 +1324,6 @@ static void I_ShutdownGMEMusic(void) } #endif -void I_ShutdownDigMusic(void) -{ - nodigimusic = false; - if (nomidimusic) I_ShutdownMusic(); -} - #ifdef HAVE_MIXER static boolean LoadSong(void *data, size_t lumplength, size_t selectpos) { @@ -1436,8 +1424,8 @@ void I_ShutdownMusic(void) CONS_Printf("%s", M_GetText("I_ShutdownMusic: ")); - I_UnRegisterSong(0); - I_StopDigSong(); + I_UnloadSong(); + I_StopSong(); Mix_CloseAudio(); #ifdef MIX_INIT Mix_Quit(); @@ -1450,16 +1438,6 @@ void I_ShutdownMusic(void) #endif } -void I_InitMIDIMusic(void) -{ - if (nodigimusic) I_InitMusic(); -} - -void I_InitDigMusic(void) -{ - if (nomidimusic) I_InitMusic(); -} - void I_InitMusic(void) { #ifdef HAVE_MIXER @@ -1639,17 +1617,29 @@ void I_ResumeSong(INT32 handle) #endif } -void I_StopSong(INT32 handle) +void I_StopSong(void) { - (void)handle; + I_StopGME(); #ifdef HAVE_MIXER - if (nomidimusic || !musicStarted) + if (nodigimusic) return; - Mix_FadeOutMusic(MIDIfade); + +#ifdef MIXER_POS + if (canlooping) + Mix_HookMusicFinished(NULL); #endif + + Mix_HaltMusic(); + while (Mix_PlayingMusic()) + ; + + if (music[1]) + Mix_FreeMusic(music[1]); + music[1] = NULL; + LoadSong(NULL, 0, 1); } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { #ifdef HAVE_MIXER @@ -1669,7 +1659,7 @@ void I_UnRegisterSong(INT32 handle) #endif } -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(void *data, size_t len) { #ifdef HAVE_MIXER if (nomidimusic || !musicStarted) @@ -1771,7 +1761,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) lumpnum = W_CheckNumForName(filename); - I_StopDigSong(); + I_StopSong(); if (lumpnum == LUMPERROR) { @@ -1923,29 +1913,6 @@ static void I_StopGME(void) #endif } -void I_StopDigSong(void) -{ - I_StopGME(); -#ifdef HAVE_MIXER - if (nodigimusic) - return; - -#ifdef MIXER_POS - if (canlooping) - Mix_HookMusicFinished(NULL); -#endif - - Mix_HaltMusic(); - while (Mix_PlayingMusic()) - ; - - if (music[1]) - Mix_FreeMusic(music[1]); - music[1] = NULL; - LoadSong(NULL, 0, 1); -#endif -} - void I_SetDigMusicVolume(UINT8 volume) { #ifdef HAVE_MIXER diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 281f48ea7..559feb2ae 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -450,8 +450,7 @@ void I_InitMusic(void) void I_ShutdownMusic(void) { - I_ShutdownDigMusic(); - I_ShutdownMIDIMusic(); + I_StopSong(); } void I_PauseSong(INT32 handle) @@ -468,17 +467,7 @@ void I_ResumeSong(INT32 handle) FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, false)); } -void I_InitDigMusic(void) -{ -} - -void I_ShutdownDigMusic(void) -{ - if (!midimode) - I_StopDigSong(); -} - -boolean I_StartDigSong(const char *musicname, boolean looping) +boolean I_LoadSong(char *data, size_t len) { char *data; size_t len; @@ -603,8 +592,6 @@ boolean I_StartDigSong(const char *musicname, boolean looping) { gme_equalizer_t gmeq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; Z_Free(data); // We don't need this anymore. - gme_start_track(gme, 0); - current_track = 0; gme_set_equalizer(gme,&gmeq); fmt.format = FMOD_SOUND_FORMAT_PCM16; fmt.defaultfrequency = 44100; @@ -614,32 +601,21 @@ boolean I_StartDigSong(const char *musicname, boolean looping) fmt.pcmreadcallback = GMEReadCallback; fmt.userdata = gme; FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); - FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); - FMR(FMOD_Channel_SetPriority(music_channel, 0)); return true; } #endif fmt.length = len; + + FMOD_RESULT e = FMOD_System_CreateStream(fsys, data, FMOD_OPENMEMORY_POINT|(looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream); + if (e != FMOD_OK) { - FMOD_RESULT e = FMOD_System_CreateStream(fsys, data, FMOD_OPENMEMORY_POINT|(looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream); - if (e != FMOD_OK) - { - if (e == FMOD_ERR_FORMAT) - CONS_Alert(CONS_WARNING, "Failed to play music lump %s due to invalid format.\n", W_CheckNameForNum(lumpnum)); - else - FMR(e); - return false; - } + if (e == FMOD_ERR_FORMAT) + CONS_Alert(CONS_WARNING, "Failed to play music lump %s due to invalid format.\n", W_CheckNameForNum(lumpnum)); + else + FMR(e); + return false; } - FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - if (midimode) - FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); - else - FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); - FMR(FMOD_Channel_SetPriority(music_channel, 0)); - current_track = 0; // Try to find a loop point in streaming music formats (ogg, mp3) if (looping) @@ -660,6 +636,13 @@ boolean I_StartDigSong(const char *musicname, boolean looping) return true; } + // todo + // if(music type == MIDI) + // { + // FMR(FMOD_Sound_SetMode(music_stream, FMOD_LOOP_NORMAL)); + // return true; + // } + // Use LOOPMS for time in miliseconds. e = FMOD_Sound_GetTag(music_stream, "LOOPMS", 0, &tag); if (e != FMOD_ERR_TAGNOTFOUND) @@ -698,23 +681,10 @@ boolean I_StartDigSong(const char *musicname, boolean looping) } } - // No special loop point, but we're playing so it's all good. + // No special loop point return true; } -void I_StopDigSong(void) -{ - if (music_stream) - FMR(FMOD_Sound_Release(music_stream)); - music_stream = NULL; -#ifdef HAVE_LIBGME - if (gme) - gme_delete(gme); - gme = NULL; -#endif - current_track = -1; -} - void I_SetDigMusicVolume(UINT8 volume) { // volume is 0 to 31. @@ -805,46 +775,44 @@ boolean I_SetSongTrack(INT32 track) // Fuck MIDI. ... Okay fine, you can have your silly D_-only mode. // -void I_InitMIDIMusic(void) +boolean I_PlaySong(void) { -} - -void I_ShutdownMIDIMusic(void) -{ - if (midimode) - I_StopSong(0); -} - -INT32 I_RegisterSong(void *data, size_t len) -{ - FMOD_CREATESOUNDEXINFO fmt; - memset(&fmt, 0, sizeof(FMOD_CREATESOUNDEXINFO)); - fmt.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); - fmt.length = len; - FMR(FMOD_System_CreateStream(fsys, (char *)data, FMOD_OPENMEMORY_POINT, &fmt, &music_stream)); - return 1337; -} - -boolean I_PlaySong(INT32 handle, boolean looping) -{ - if (1337 == handle) +#ifdef HAVE_LIBGME + if (gme) { - midimode = true; - if (looping) - FMR(FMOD_Sound_SetMode(music_stream, FMOD_LOOP_NORMAL)); + gme_start_track(gme, 0); + current_track = 0; FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); - FMR_MUSIC(FMOD_Channel_SetPriority(music_channel, 0)); + FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); + FMR(FMOD_Channel_SetPriority(music_channel, 0)); + return true; } +#endif + + FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); + if (midimode) + FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); + else + FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); + FMR(FMOD_Channel_SetPriority(music_channel, 0)); + current_track = 0; + return true; } -void I_StopSong(INT32 handle) +void I_StopSong(void) { - I_UnRegisterSong(handle); +#ifdef HAVE_LIBGME + if (gme) + gme_delete(gme); + gme = NULL; +#endif + current_track = -1; + + I_UnloadSong(); } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { UNREFERENCED_PARAMETER(handle); if (music_stream) From 3ec1a122e0165112c772b0d62a7aa68d7218a3cf Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 09:09:12 -0400 Subject: [PATCH 08/30] Revert "Nix'd midimusicvolume other targets" This reverts commit 58fbb4636f4a3dc940e31d6cce94e87dcd0dbaa7. # Conflicts: # src/android/i_sound.c # src/dummy/i_sound.c # src/win32/win_snd.c --- src/android/i_sound.c | 5 +++++ src/djgppdos/i_sound.c | 11 ++++++++++- src/dummy/i_sound.c | 5 +++++ src/sdl/sdl_sound.c | 27 ++++++++++++++++----------- src/win32/win_cd.c | 1 + src/win32/win_snd.c | 8 ++++++++ 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 109faf57d..744067623 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -87,6 +87,11 @@ boolean I_LoadSong(void *data, size_t len) return -1; } +void I_SetMIDIMusicVolume(INT32 volume) +{ + (void)volume; +} + boolean I_PlaySong(void) { (void)handle; diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 993e164c9..a0ad28553 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -140,6 +140,15 @@ void I_SetSfxVolume(INT32 volume) set_volume (Volset(volume),-1); } +void I_SetMIDIMusicVolume(INT32 volume) +{ + if (nomidimusic) + return; + + // Now set volume on output device. + set_volume (-1, Volset(volume)); +} + // // Starting a sound means adding it // to the current list of active sounds @@ -494,7 +503,7 @@ void I_SetDigMusicVolume(INT32 volume) return; // Now set volume on output device. - set_volume (-1, Volset(volume)); +// CONS_Printf("Digital music not yet supported under DOS.\n"); } boolean I_SetSongSpeed(float speed) diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index ef186d5f3..a70dcef83 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -65,6 +65,11 @@ void I_InitMusic(void){} void I_ShutdownMusic(void){} +void I_SetMIDIMusicVolume(UINT8 volume) +{ + (void)volume; +} + void I_PauseSong(INT32 handle) { (void)handle; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index fb4c301ae..c1badfe65 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1679,6 +1679,21 @@ boolean I_LoadSong(void *data, size_t len) return false; } +void I_SetMIDIMusicVolume(UINT8 volume) +{ +#ifdef HAVE_MIXER + if ((nomidimusic && nodigimusic) || !musicStarted) + return; + + if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); + musicvol = volume * 2; + if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); + Mix_VolumeMusic(musicvol); +#else + (void)volume; +#endif +} + #ifdef HAVE_LIBGME static void I_CleanupGME(void *userdata) { @@ -1915,17 +1930,7 @@ static void I_StopGME(void) void I_SetDigMusicVolume(UINT8 volume) { -#ifdef HAVE_MIXER - if ((nomidimusic && nodigimusic) || !musicStarted) - return; - - if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); - musicvol = volume * 2; - if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); - Mix_VolumeMusic(musicvol); -#else - (void)volume; -#endif + I_SetMIDIMusicVolume(volume); } boolean I_SetSongSpeed(float speed) diff --git a/src/win32/win_cd.c b/src/win32/win_cd.c index 2278fbdda..f6c430748 100644 --- a/src/win32/win_cd.c +++ b/src/win32/win_cd.c @@ -470,6 +470,7 @@ void I_PlayCD(UINT8 nTrack, UINT8 bLooping) //faB: stop MIDI music, MIDI music will restart if volume is upped later cv_digmusicvolume.value = 0; + cv_midimusicvolume.value = 0; I_StopSong (0); //faB: I don't use the notify message, I'm trying to minimize the delay diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 559feb2ae..c49be100d 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -775,6 +775,14 @@ boolean I_SetSongTrack(INT32 track) // Fuck MIDI. ... Okay fine, you can have your silly D_-only mode. // +void I_SetMIDIMusicVolume(UINT8 volume) +{ + // volume is 0 to 31. + midi_volume = volume; + if (midimode && music_stream) + FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); +} + boolean I_PlaySong(void) { #ifdef HAVE_LIBGME From e89eccf78e7689b39b8252a1d27bea645a432359 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 09:36:51 -0400 Subject: [PATCH 09/30] Loose ends from previous work * Pause/ResumeSong remove handle argument * LoadSong declare char *data argument * Variable weirdness --- src/i_sound.h | 8 ++--- src/s_sound.c | 27 +++++++---------- src/sdl/i_video.c | 4 +-- src/sdl/mixer_sound.c | 69 ++++++++++++++++++++----------------------- 4 files changed, 49 insertions(+), 59 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 5368f3fd6..7cb7ee9b0 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -122,7 +122,7 @@ void I_ShutdownMusic(void); \return void */ -void I_PauseSong(INT32 handle); +void I_PauseSong(void); /** \brief RESUME game handling @@ -130,7 +130,7 @@ void I_PauseSong(INT32 handle); \return void */ -void I_ResumeSong(INT32 handle); +void I_ResumeSong(void); // // MIDI I/O @@ -153,7 +153,7 @@ void I_SetMIDIMusicVolume(UINT8 volume); \todo Remove this */ -boolean I_LoadSong(void *data, size_t len); +boolean I_LoadSong(char *data, size_t len); /** \brief Called by anything that wishes to start music @@ -164,7 +164,7 @@ boolean I_LoadSong(void *data, size_t len); \todo pass music name, not handle */ -boolean I_PlaySong(void); +boolean I_PlaySong(boolean looping); /** \brief Stops a song over 3 seconds diff --git a/src/s_sound.c b/src/s_sound.c index 81e3e78e6..7a0b99c30 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1316,11 +1316,10 @@ static char music_name[7]; // up to 6-character name static boolean mus_forcemidi = 0; // force midi even when digital exists static boolean mus_paused = 0; // whether songs are mus_paused -static boolean S_LoadMusic(const char *mname, boolean looping) +static boolean S_LoadMusic(const char *mname) { lumpnum_t mlumpnum; void *mdata; - INT32 mhandle; if (nomidimusic || music_disabled) return false; // didn't search. @@ -1354,7 +1353,7 @@ static boolean S_LoadMusic(const char *mname, boolean looping) return false; } -static void S_UnloadSong(void) +static void S_UnloadMusic(void) { I_UnloadSong(); music_name[0] = 0; @@ -1365,12 +1364,9 @@ static boolean S_PlayMusic(const char *mname, boolean looping) if (nodigimusic || digital_disabled) return false; // try midi - if (!S_LoadSong(mname, looping)) - return false; - - if (!I_PlaySong()) + if (!I_PlaySong(looping)) { - S_UnloadSong(); + S_UnloadMusic(); return false; } @@ -1394,7 +1390,7 @@ 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, looping) && !S_PlayMusic(mmusic, looping)) + if (!S_LoadMusic(mmusic) && !S_PlayMusic(mmusic, looping)) { CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic); return; @@ -1414,7 +1410,7 @@ void S_StopMusic(void) return; if (mus_paused) - I_ResumeSong(music_handle); + I_ResumeSong(); S_SpeedMusic(1.0f); I_StopSong(); @@ -1424,7 +1420,6 @@ void S_StopMusic(void) Z_ChangeTag(music_data, PU_CACHE); #endif - music_data = NULL; music_name[0] = 0; if (cv_closedcaptioning.value) @@ -1434,7 +1429,7 @@ void S_StopMusic(void) } } -void S_SetMusicVolume(INT32 volume) +void S_SetDigMusicVolume(INT32 volume) { if (volume < 0 || volume > 31) CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n"); @@ -1536,11 +1531,11 @@ void S_Start(void) void S_PauseAudio(void) { if (!nodigimusic) - I_PauseSong(0); + I_PauseSong(); if (music_playing && !mus_paused) { - I_PauseSong(music_handle); + I_PauseSong(); mus_paused = true; } @@ -1555,11 +1550,11 @@ void S_PauseAudio(void) void S_ResumeAudio(void) { if (!nodigimusic) - I_ResumeSong(0); + I_ResumeSong(); else if (music_playing && mus_paused) { - I_ResumeSong(music_handle); + I_ResumeSong(); mus_paused = false; } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index bd3f5e60a..48bb61649 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -566,7 +566,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) // Tell game we got focus back, resume music if necessary window_notinfocus = false; if (!paused) - I_ResumeSong(0); //resume it + I_ResumeSong(); //resume it if (!firsttimeonmouse) { @@ -578,7 +578,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { // Tell game we lost focus, pause music window_notinfocus = true; - I_PauseSong(0); + I_PauseSong(); if (!disable_mouse) { diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 113c75d63..f67784fcd 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -491,16 +491,14 @@ void I_ShutdownMusic(void) music = NULL; } -void I_PauseSong(INT32 handle) +void I_PauseSong(void) { - (void)handle; Mix_PauseMusic(); songpaused = true; } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { - (void)handle; Mix_ResumeMusic(); songpaused = false; } @@ -570,7 +568,7 @@ boolean I_SetSongTrack(int track) // MIDI Music // -boolean I_LoadSong(void *data, size_t len) +boolean I_LoadSong(char *data, size_t len) { I_Assert(!music); #ifdef HAVE_LIBGME @@ -667,6 +665,8 @@ boolean I_LoadSong(void *data, size_t len) else if (!gme_open_data(data, len, &gme, 44100)) { gme_equalizer_t eq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; + gme_set_equalizer(gme, &eq); + Mix_HookMusic(mix_gme, gme); return true; } #endif @@ -680,43 +680,41 @@ boolean I_LoadSong(void *data, size_t len) // Find the OGG loop point. loop_point = 0.0f; - if (looping) + + const char *key1 = "LOOP"; + const char *key2 = "POINT="; + const char *key3 = "MS="; + const size_t key1len = strlen(key1); + const size_t key2len = strlen(key2); + const size_t key3len = strlen(key3); + char *p = data; + while ((UINT32)(p - data) < len) { - const char *key1 = "LOOP"; - const char *key2 = "POINT="; - const char *key3 = "MS="; - const size_t key1len = strlen(key1); - const size_t key2len = strlen(key2); - const size_t key3len = strlen(key3); - char *p = data; - while ((UINT32)(p - data) < len) + if (strncmp(p++, key1, key1len)) + continue; + p += key1len-1; // skip OOP (the L was skipped in strncmp) + if (!strncmp(p, key2, key2len)) // is it LOOPPOINT=? { - if (strncmp(p++, key1, key1len)) - continue; - p += key1len-1; // skip OOP (the L was skipped in strncmp) - if (!strncmp(p, key2, key2len)) // is it LOOPPOINT=? - { - p += key2len; // skip POINT= - loop_point = (float)((44.1L+atoi(p)) / 44100.0L); // LOOPPOINT works by sample count. - // because SDL_Mixer is USELESS and can't even tell us - // something simple like the frequency of the streaming music, - // we are unfortunately forced to assume that ALL MUSIC is 44100hz. - // This means a lot of tracks that are only 22050hz for a reasonable downloadable file size will loop VERY badly. - } - else if (!strncmp(p, key3, key3len)) // is it LOOPMS=? - { - p += key3len; // skip MS= - loop_point = (float)(atoi(p) / 1000.0L); // LOOPMS works by real time, as miliseconds. - // Everything that uses LOOPMS will work perfectly with SDL_Mixer. - } - // Neither?! Continue searching. + p += key2len; // skip POINT= + loop_point = (float)((44.1L+atoi(p)) / 44100.0L); // LOOPPOINT works by sample count. + // because SDL_Mixer is USELESS and can't even tell us + // something simple like the frequency of the streaming music, + // we are unfortunately forced to assume that ALL MUSIC is 44100hz. + // This means a lot of tracks that are only 22050hz for a reasonable downloadable file size will loop VERY badly. } + else if (!strncmp(p, key3, key3len)) // is it LOOPMS=? + { + p += key3len; // skip MS= + loop_point = (float)(atoi(p) / 1000.0L); // LOOPMS works by real time, as miliseconds. + // Everything that uses LOOPMS will work perfectly with SDL_Mixer. + } + // Neither?! Continue searching. } return true; } -boolean I_PlaySong(void) +boolean I_PlaySong(boolean looping) { if (!music) return false; @@ -725,8 +723,6 @@ boolean I_PlaySong(void) { gme_start_track(gme, 0); current_track = 0; - gme_set_equalizer(gme, &eq); - Mix_HookMusic(mix_gme, gme); return true; } #endif @@ -782,7 +778,6 @@ void I_UnloadSong(void) if (!midimode || !music) return; - (void)handle; Mix_FreeMusic(music); music = NULL; } From 9a5fc5f66a31baf713c6f32f7a696b933da6907b Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 09:37:02 -0400 Subject: [PATCH 10/30] Loose ends other targets --- src/android/i_sound.c | 8 +-- src/djgppdos/i_sound.c | 4 +- src/dummy/i_sound.c | 8 +-- src/sdl/sdl_sound.c | 6 +-- src/win32/win_main.c | 4 +- src/win32/win_snd.c | 113 ++++++++++++++++++++--------------------- 6 files changed, 70 insertions(+), 73 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 744067623..ed666428c 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -64,12 +64,12 @@ void I_InitMusic(void){} void I_ShutdownMusic(void){} -void I_PauseSong(INT32 handle) +void I_PauseSong(void) { (void)handle; } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { (void)handle; } @@ -80,7 +80,7 @@ void I_ResumeSong(INT32 handle) UINT8 midimusic_started = 0; -boolean I_LoadSong(void *data, size_t len) +boolean I_LoadSong(char *data, size_t len) { (void)data; (void)len; @@ -92,7 +92,7 @@ void I_SetMIDIMusicVolume(INT32 volume) (void)volume; } -boolean I_PlaySong(void) +boolean I_PlaySong(boolean looping) { (void)handle; (void)looping; diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index a0ad28553..cf66cbd2e 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -408,7 +408,7 @@ void I_ShutdownMusic(void) music_started=false; } -boolean I_PlaySong(void) +boolean I_PlaySong(boolean looping) { handle = 0; if (nomidimusic) @@ -471,7 +471,7 @@ void I_UnloadSong(void) //destroy_midi(currsong); } -boolean I_LoadSong(void *data, size_t len) +boolean I_LoadSong(char *data, size_t len) { int e = len; //Alam: For error if (nomidimusic) diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index a70dcef83..181abdf51 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -70,12 +70,12 @@ void I_SetMIDIMusicVolume(UINT8 volume) (void)volume; } -void I_PauseSong(INT32 handle) +void I_PauseSong(void) { (void)handle; } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { (void)handle; } @@ -84,14 +84,14 @@ void I_ResumeSong(INT32 handle) // MIDI I/O // -boolean I_LoadSong(void *data, size_t len) +boolean I_LoadSong(char *data, size_t len) { (void)data; (void)len; return -1; } -boolean I_PlaySong(void) +boolean I_PlaySong(boolean looping) { (void)handle; (void)looping; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index c1badfe65..a4334a78e 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1583,7 +1583,7 @@ static void I_PauseGME(void) #endif } -void I_PauseSong(INT32 handle) +void I_PauseSong(void) { (void)handle; I_PauseGME(); @@ -1603,7 +1603,7 @@ static void I_ResumeGME(void) #endif } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { (void)handle; I_ResumeGME(); @@ -1659,7 +1659,7 @@ void I_UnloadSong(void) #endif } -boolean I_LoadSong(void *data, size_t len) +boolean I_LoadSong(char *data, size_t len) { #ifdef HAVE_MIXER if (nomidimusic || !musicStarted) diff --git a/src/win32/win_main.c b/src/win32/win_main.c index 6c774f557..bfe620a43 100644 --- a/src/win32/win_main.c +++ b/src/win32/win_main.c @@ -110,9 +110,9 @@ static LRESULT CALLBACK MainWndproc(HWND hWnd, UINT message, WPARAM wParam, LPAR // pause music when alt-tab if (appActive && !paused) - I_ResumeSong(0); + I_ResumeSong(); else if (!paused) - I_PauseSong(0); + I_PauseSong(); { HANDLE ci = GetStdHandle(STD_INPUT_HANDLE); DWORD mode; diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index c49be100d..e9311026f 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -453,14 +453,14 @@ void I_ShutdownMusic(void) I_StopSong(); } -void I_PauseSong(INT32 handle) +void I_PauseSong(void) { UNREFERENCED_PARAMETER(handle); if (music_stream) FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, true)); } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { UNREFERENCED_PARAMETER(handle); if (music_stream) @@ -618,67 +618,64 @@ boolean I_LoadSong(char *data, size_t len) } // Try to find a loop point in streaming music formats (ogg, mp3) - if (looping) - { - FMOD_RESULT e; - FMOD_TAG tag; - unsigned int loopstart, loopend; + FMOD_RESULT e; + FMOD_TAG tag; + unsigned int loopstart, loopend; - // A proper LOOPPOINT is its own tag, stupid. - e = FMOD_Sound_GetTag(music_stream, "LOOPPOINT", 0, &tag); - if (e != FMOD_ERR_TAGNOTFOUND) + // A proper LOOPPOINT is its own tag, stupid. + e = FMOD_Sound_GetTag(music_stream, "LOOPPOINT", 0, &tag); + if (e != FMOD_ERR_TAGNOTFOUND) + { + FMR(e); + loopstart = atoi((char *)tag.data); // assumed to be a string data tag. + FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM)); + if (loopstart > 0) + FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM)); + return true; + } + + // todo + // if(music type == MIDI) + // { + // FMR(FMOD_Sound_SetMode(music_stream, FMOD_LOOP_NORMAL)); + // return true; + // } + + // Use LOOPMS for time in miliseconds. + e = FMOD_Sound_GetTag(music_stream, "LOOPMS", 0, &tag); + if (e != FMOD_ERR_TAGNOTFOUND) + { + FMR(e); + loopstart = atoi((char *)tag.data); // assumed to be a string data tag. + FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_MS, &loopend, FMOD_TIMEUNIT_PCM)); + if (loopstart > 0) + FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_MS, loopend, FMOD_TIMEUNIT_PCM)); + return true; + } + + // Try to fetch it from the COMMENT tag, like A.J. Freda + e = FMOD_Sound_GetTag(music_stream, "COMMENT", 0, &tag); + if (e != FMOD_ERR_TAGNOTFOUND) + { + char *loopText; + // Handle any errors that arose, first + FMR(e); + // Figure out where the number starts + loopText = strstr((char *)tag.data,"LOOPPOINT="); + if (loopText != NULL) { - FMR(e); - loopstart = atoi((char *)tag.data); // assumed to be a string data tag. + // Skip the "LOOPPOINT=" part. + loopText += 10; + // Convert it to our looppoint + // FMOD seems to ensure the tag is properly NULL-terminated. + // atoi will stop when it reaches anything that's not a number. + loopstart = atoi(loopText); + // Now do the rest like above FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM)); if (loopstart > 0) FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM)); - return true; - } - - // todo - // if(music type == MIDI) - // { - // FMR(FMOD_Sound_SetMode(music_stream, FMOD_LOOP_NORMAL)); - // return true; - // } - - // Use LOOPMS for time in miliseconds. - e = FMOD_Sound_GetTag(music_stream, "LOOPMS", 0, &tag); - if (e != FMOD_ERR_TAGNOTFOUND) - { - FMR(e); - loopstart = atoi((char *)tag.data); // assumed to be a string data tag. - FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_MS, &loopend, FMOD_TIMEUNIT_PCM)); - if (loopstart > 0) - FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_MS, loopend, FMOD_TIMEUNIT_PCM)); - return true; - } - - // Try to fetch it from the COMMENT tag, like A.J. Freda - e = FMOD_Sound_GetTag(music_stream, "COMMENT", 0, &tag); - if (e != FMOD_ERR_TAGNOTFOUND) - { - char *loopText; - // Handle any errors that arose, first - FMR(e); - // Figure out where the number starts - loopText = strstr((char *)tag.data,"LOOPPOINT="); - if (loopText != NULL) - { - // Skip the "LOOPPOINT=" part. - loopText += 10; - // Convert it to our looppoint - // FMOD seems to ensure the tag is properly NULL-terminated. - // atoi will stop when it reaches anything that's not a number. - loopstart = atoi(loopText); - // Now do the rest like above - FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM)); - if (loopstart > 0) - FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM)); - } - return true; } + return true; } // No special loop point @@ -783,7 +780,7 @@ void I_SetMIDIMusicVolume(UINT8 volume) FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); } -boolean I_PlaySong(void) +boolean I_PlaySong(boolean looping) { #ifdef HAVE_LIBGME if (gme) From 55f3803e4b9f8104c90cc6c769d54121e5bac0b8 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 10:18:38 -0400 Subject: [PATCH 11/30] 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; } From 14b393ab16736bb44dab6fd4a90b7bdd8ff782e0 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 10:19:04 -0400 Subject: [PATCH 12/30] Added I_GetMusicType and removed midimode variable: other targets --- src/android/i_sound.c | 5 +++++ src/djgppdos/i_sound.c | 9 ++++++++- src/dummy/i_sound.c | 5 +++++ src/sdl/sdl_sound.c | 23 +++++++++++++++++++++ src/win32/win_snd.c | 45 +++++++++++++++++++++++++++++++++++------- 5 files changed, 79 insertions(+), 8 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index ed666428c..f4ec1c563 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -60,6 +60,11 @@ void I_SetSfxVolume(INT32 volume) // UINT8 music_started = 0; +musictype_t I_GetMusicType(void) +{ + return MU_NONE; +} + void I_InitMusic(void){} void I_ShutdownMusic(void){} diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index cf66cbd2e..51b97ccce 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -322,6 +322,13 @@ static int islooping=0; static int musicdies=-1; UINT8 music_started=0; +musictype_t I_GetMusicType(void) +{ + if (currsong) + return MU_MID; + else + return MU_NONE; +} /* load_midi_mem: * Loads a standard MIDI file from memory, returning a pointer to @@ -403,7 +410,7 @@ void I_ShutdownMusic(void) if ( !music_started ) return; - I_StopSong(1); + I_StopSong(); music_started=false; } diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 181abdf51..c3c971552 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -61,6 +61,11 @@ void I_SetSfxVolume(UINT8 volume) // MUSIC I/O // +musictype_t I_GetMusicType(void) +{ + return MU_NONE; +} + void I_InitMusic(void){} void I_ShutdownMusic(void){} diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index a4334a78e..3e0902101 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1313,6 +1313,29 @@ void I_StartupSound(void) // MUSIC API. // +musictype_t I_GetMusicType(void) +{ +#ifdef HAVE_MIXER +#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); +#else + return MU_NONE +#endif +} + #ifdef HAVE_LIBGME static void I_ShutdownGMEMusic(void) { diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index e9311026f..fd44b3570 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -42,7 +42,6 @@ static FMOD_SYSTEM *fsys; static FMOD_SOUND *music_stream; static FMOD_CHANNEL *music_channel; -static boolean midimode; static UINT8 music_volume, midi_volume, sfx_volume; static INT32 current_track; @@ -444,6 +443,41 @@ void I_SetSfxVolume(UINT8 volume) // MUSIC // +musictype_t I_GetMusicType(void) +{ +#ifdef HAVE_LIBGME + if (gme) + return MU_GME; +#endif + + if (!music_stream) + return MU_NONE; + + FMOD_SOUND_TYPE type; + if (FMOD_Sound_GetFormat(music_stream, &type, NULL, NULL, NULL) == FMOD_OK) + { + switch(type) + { + case FMOD_SOUND_TYPE_WAV: + return MU_WAV; + case FMOD_SOUND_TYPE_MOD: + return MU_MOD; + case FMOD_SOUND_TYPE_MID: + return MU_MID; + case FMOD_SOUND_TYPE_OGGVORBIS: + return MU_OGG; + case FMOD_SOUND_TYPE_MP3: + return MU_MP3; + case FMOD_SOUND_TYPE_FLAC: + return MU_FLAC; + default: + return MU_NONE; + } + } + else + return MU_NONE; +} + void I_InitMusic(void) { } @@ -479,10 +513,7 @@ boolean I_LoadSong(char *data, size_t len) lumpnum = W_CheckNumForName(va("D_%s",musicname)); if (lumpnum == LUMPERROR) return false; - midimode = true; } - else - midimode = false; data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC); len = W_LumpLength(lumpnum); @@ -686,7 +717,7 @@ void I_SetDigMusicVolume(UINT8 volume) { // volume is 0 to 31. music_volume = volume; - if (!midimode && music_stream) + if (I_GetMusicType() != MU_MID && music_stream) FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); } @@ -776,7 +807,7 @@ void I_SetMIDIMusicVolume(UINT8 volume) { // volume is 0 to 31. midi_volume = volume; - if (midimode && music_stream) + if (I_GetMusicType() != MU_MID && music_stream) FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); } @@ -795,7 +826,7 @@ boolean I_PlaySong(boolean looping) #endif FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - if (midimode) + if (I_GetMusicType() != MU_MID) FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); else FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); From 701cc5a7dd1dfead87a42ec7558c9fa6a1deb193 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 11:51:23 -0400 Subject: [PATCH 13/30] Consolidate I_SetDigMusicVolume and I_SetMIDIMusicVolume into one method * In s_sound, they are merged to one method as well, but there are still two separate digvolume and seqvolume variables * Simplified Dig/MidiMusicDisabled in s_sound * Method reordering --- src/d_netcmd.c | 4 +- src/i_sound.h | 12 +----- src/s_sound.c | 96 +++++++++++++++++++++++++++++-------------- src/s_sound.h | 28 ++++++++++--- src/sdl/mixer_sound.c | 28 +++++-------- 5 files changed, 102 insertions(+), 66 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 0cb1d4497..1e09c1c9e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4057,11 +4057,9 @@ static void Command_RestartAudio_f(void) // These must be called or no sound and music until manually set. I_SetSfxVolume(cv_soundvolume.value); - I_SetDigMusicVolume(cv_digmusicvolume.value); - I_SetMIDIMusicVolume(cv_midimusicvolume.value); + S_SetMusicVolume(cv_digmusicvolume.value, cv_midimusicvolume.value); if (Playing()) // Gotta make sure the player is in a level P_RestoreMusic(&players[consoleplayer]); - } /** Quits a game and returns to the title screen. diff --git a/src/i_sound.h b/src/i_sound.h index 7af9985f6..2045752de 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -154,13 +154,13 @@ void I_ResumeSong(void); // MIDI I/O // -/** \brief The I_SetMIDIMusicVolume function +/** \brief The I_SetMusicVolume function \param volume volume to set at \return void */ -void I_SetMIDIMusicVolume(UINT8 volume); +void I_SetMusicVolume(UINT8 volume); /** \brief Registers a song handle to song data. @@ -210,14 +210,6 @@ boolean I_SetSongSpeed(float speed); boolean I_SetSongTrack(INT32 track); -/** \brief The I_SetDigMusicVolume function - - \param volume volume to set at - - \return void -*/ -void I_SetDigMusicVolume(UINT8 volume); - // // CD MUSIC I/O // diff --git a/src/s_sound.c b/src/s_sound.c index 668e5b607..f58db4145 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1312,19 +1312,54 @@ const char *compat_special_music_slots[16] = #define music_playing (music_name[0]) // String is empty if no music is playing static char music_name[7]; // up to 6-character name - -static boolean mus_forcemidi = 0; // force midi even when digital exists static boolean mus_paused = 0; // whether songs are mus_paused +/// ------------------------ +/// Music Status +/// ------------------------ + +boolean S_DigMusicDisabled() +{ + return (nodigimusic || digital_disabled); +} + +boolean S_MIDIMusicDisabled() +{ + return (nomidimusic || music_disabled); +} + +boolean S_MusicDisabled() +{ + return ( + (nodigimusic && nomidimusic) || + (music_disabled && digital_disabled) || + (nodigimusic && music_disabled) || + (nomidimusic && digital_disabled) + ); +} + +/// ------------------------ +/// Music Properties +/// ------------------------ + +boolean S_SpeedMusic(float speed) +{ + return I_SetSongSpeed(speed); +} + +/// ------------------------ +/// Music Routines +/// ------------------------ + static boolean S_LoadMusic(const char *mname) { lumpnum_t mlumpnum; void *mdata; - if (nomidimusic || music_disabled) - return false; // didn't search. + if (S_MusicDisabled()) + return false; - if (mus_forcemidi) + if (S_DigMusicDisabled()) { if (W_CheckNumForName(va("d_%s", mname)) == LUMPERROR) return false; @@ -1370,12 +1405,13 @@ static boolean S_PlayMusic(boolean looping) return false; } + S_InitMusicVolume(); // switch between digi and sequence volume return true; } void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) { - if ((nomidimusic || music_disabled) && (nodigimusic || digital_disabled)) + if (S_MusicDisabled()) return; // No Music (empty string) @@ -1404,11 +1440,6 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) I_SetSongTrack(mflags & MUSIC_TRACKMASK); } -boolean S_SpeedMusic(float speed) -{ - return I_SetSongSpeed(speed); -} - void S_StopMusic(void) { if (!music_playing) @@ -1434,32 +1465,36 @@ void S_StopMusic(void) } } -void S_SetDigMusicVolume(INT32 volume) +void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) { - if (volume < 0 || volume > 31) - CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n"); + if (digvolume < 0) + digvolume = cv_digmusicvolume.value; + if (seqvolume < 0) + seqvolume = cv_midimusicvolume.value; - CV_SetValue(&cv_digmusicvolume, volume&31); + if (digvolume < 0 || digvolume > 31) + CONS_Alert(CONS_WARNING, "digmusicvolume should be between 0-31\n"); + CV_SetValue(&cv_digmusicvolume, digvolume&31); actualdigmusicvolume = cv_digmusicvolume.value; //check for change of var -#ifdef DJGPPDOS - I_SetDigMusicVolume(31); // Trick for buggy dos drivers. Win32 doesn't need this. -#endif - I_SetDigMusicVolume(volume&31); -} - -void S_SetMIDIMusicVolume(INT32 volume) -{ - if (volume < 0 || volume > 31) - CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n"); - - CV_SetValue(&cv_midimusicvolume, volume&0x1f); + if (digvolume < 0 || digvolume > 31) + CONS_Alert(CONS_WARNING, "midimusicvolume should be between 0-31\n"); + CV_SetValue(&cv_midimusicvolume, seqvolume&31); actualmidimusicvolume = cv_midimusicvolume.value; //check for change of var #ifdef DJGPPDOS - I_SetMIDIMusicVolume(31); // Trick for buggy dos drivers. Win32 doesn't need this. + digvolume = seqvolume = 31; #endif - I_SetMIDIMusicVolume(volume&0x1f); + + switch(I_GetMusicType()) + { + case MU_MID: + case MU_MOD: + case MU_GME: + I_SetMusicVolume(seqvolume&31); + default: + I_SetMusicVolume(digvolume&31); + } } /// ------------------------ @@ -1479,8 +1514,7 @@ void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume) return; S_SetSfxVolume(sfxVolume); - S_SetDigMusicVolume(digMusicVolume); - S_SetMIDIMusicVolume(midiMusicVolume); + S_SetMusicVolume(digMusicVolume, midiMusicVolume); SetChannelsNum(); diff --git a/src/s_sound.h b/src/s_sound.h index 4b9735480..891254b4c 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -125,6 +125,25 @@ void S_StartSoundAtVolume(const void *origin, sfxenum_t sound_id, INT32 volume); // Stop sound for thing at void S_StopSound(void *origin); +// +// Music Status +// + +boolean S_DigMusicDisabled(); +boolean S_MIDIMusicDisabled(); +boolean S_MusicDisabled(); + +// +// Music Properties +// + +// Set Speed of Music +boolean S_SpeedMusic(float speed); + +// +// Music Routines +// + // Start music track, arbitrary, given its name, and set whether looping // note: music flags 12 bits for tracknum (gme, other formats with more than one track) // 13-15 aren't used yet @@ -132,9 +151,6 @@ void S_StopSound(void *origin); #define S_ChangeMusicInternal(a,b) S_ChangeMusic(a,0,b) void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping); -// Set Speed of Music -boolean S_SpeedMusic(float speed); - // Stops the music. void S_StopMusic(void); @@ -149,9 +165,11 @@ void S_UpdateSounds(void); FUNCMATH fixed_t S_CalculateSoundDistance(fixed_t px1, fixed_t py1, fixed_t pz1, fixed_t px2, fixed_t py2, fixed_t pz2); -void S_SetDigMusicVolume(INT32 volume); -void S_SetMIDIMusicVolume(INT32 volume); void S_SetSfxVolume(INT32 volume); +void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume); +#define S_SetDigMusicVolume(a) S_SetMusicVolume(a,-1) +#define S_SetMIDIMusicVolume(a) S_SetMusicVolume(-1,a) +#define S_InitMusicVolume() S_SetMusicVolume(-1,-1) INT32 S_OriginPlaying(void *origin); INT32 S_IdPlaying(sfxenum_t id); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index f9680bc76..2ebc5750d 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -522,14 +522,6 @@ void I_ResumeSong(void) // Digital Music // -void I_SetDigMusicVolume(UINT8 volume) -{ - music_volume = volume; - if (I_GetMusicType() == MU_MID || !music) - return; - Mix_VolumeMusic((UINT32)volume*128/31); -} - boolean I_SetSongSpeed(float speed) { if (speed > 250.0f) @@ -773,17 +765,19 @@ void I_StopSong(void) music = NULL; } -void I_SetMIDIMusicVolume(UINT8 volume) +void I_SetMusicVolume(UINT8 volume) { - // HACK: Until we stop using native MIDI, - // disable volume changes - (void)volume; - midi_volume = 31; - //midi_volume = volume; - - if (I_GetMusicType() != MU_MID || !music) + if (!music) return; - Mix_VolumeMusic((UINT32)midi_volume*128/31); + + if (I_GetMusicType() == MU_MID) + // HACK: Until we stop using native MIDI, + // disable volume changes + music_volume = 31; + else + music_volume = volume; + + Mix_VolumeMusic((UINT32)music_volume*128/31); } void I_UnloadSong(void) From 9fb9386f84b3739fe765a78bcb9683eb7e98bc36 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 11:54:58 -0400 Subject: [PATCH 14/30] Consolidate I_SetDigMusicVolume and I_SetMIDIMusicVolume other targets --- src/android/i_sound.c | 7 +------ src/djgppdos/i_sound.c | 12 +----------- src/dummy/i_sound.c | 7 +------ src/sdl/sdl_sound.c | 7 +------ src/win32/win_snd.c | 22 ++++++++++------------ 5 files changed, 14 insertions(+), 41 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index f4ec1c563..0bb47d5cf 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -92,7 +92,7 @@ boolean I_LoadSong(char *data, size_t len) return -1; } -void I_SetMIDIMusicVolume(INT32 volume) +void I_SetMusicVolume(INT32 volume) { (void)volume; } @@ -120,11 +120,6 @@ void I_UnloadSong(void) UINT8 digmusic_started = 0; -void I_SetDigMusicVolume(INT32 volume) -{ - (void)volume; -} - boolean I_SetSongSpeed(float speed) { (void)speed; diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 51b97ccce..d924a6560 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -140,7 +140,7 @@ void I_SetSfxVolume(INT32 volume) set_volume (Volset(volume),-1); } -void I_SetMIDIMusicVolume(INT32 volume) +void I_SetMusicVolume(INT32 volume) { if (nomidimusic) return; @@ -503,16 +503,6 @@ boolean I_LoadSong(char *data, size_t len) return 1; } -void I_SetDigMusicVolume(INT32 volume) -{ - volume = 0; - if (nodigimusic) - return; - - // Now set volume on output device. -// CONS_Printf("Digital music not yet supported under DOS.\n"); -} - boolean I_SetSongSpeed(float speed) { (void)speed; diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index c3c971552..6a01787d9 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -70,7 +70,7 @@ void I_InitMusic(void){} void I_ShutdownMusic(void){} -void I_SetMIDIMusicVolume(UINT8 volume) +void I_SetMusicVolume(UINT8 volume) { (void)volume; } @@ -117,11 +117,6 @@ void I_UnloadSong(void) // DIGMUSIC I/O // -void I_SetDigMusicVolume(UINT8 volume) -{ - (void)volume; -} - boolean I_SetSongSpeed(float speed) { (void)speed; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 3e0902101..23cce94d9 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1702,7 +1702,7 @@ boolean I_LoadSong(char *data, size_t len) return false; } -void I_SetMIDIMusicVolume(UINT8 volume) +void I_SetMusicVolume(UINT8 volume) { #ifdef HAVE_MIXER if ((nomidimusic && nodigimusic) || !musicStarted) @@ -1951,11 +1951,6 @@ static void I_StopGME(void) #endif } -void I_SetDigMusicVolume(UINT8 volume) -{ - I_SetMIDIMusicVolume(volume); -} - boolean I_SetSongSpeed(float speed) { diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index fd44b3570..9bfd1297f 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -713,14 +713,6 @@ boolean I_LoadSong(char *data, size_t len) return true; } -void I_SetDigMusicVolume(UINT8 volume) -{ - // volume is 0 to 31. - music_volume = volume; - if (I_GetMusicType() != MU_MID && music_stream) - FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); -} - boolean I_SetSongSpeed(float speed) { FMOD_RESULT e; @@ -803,12 +795,18 @@ boolean I_SetSongTrack(INT32 track) // Fuck MIDI. ... Okay fine, you can have your silly D_-only mode. // -void I_SetMIDIMusicVolume(UINT8 volume) +void I_SetMusicVolume(UINT8 volume) { + if (!music_stream) + return; + // volume is 0 to 31. - midi_volume = volume; - if (I_GetMusicType() != MU_MID && music_stream) - FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); + if (I_GetMusicType() == MU_MID) + music_volume = 31; // windows bug hack + else + music_volume = volume; + + FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); } boolean I_PlaySong(boolean looping) From f5f0b5e76c2fd405c8cc895dde653c5ed2652622 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:30:47 -0400 Subject: [PATCH 15/30] Refactoring, music statues * S_Init -> S_InitSfxChannels because it did mostly SFX anyway * S_MusicPlaying, S_MusicPaused, S_MusicName, S_MusicExists new status methods * I_MusicPlaying, I_MusicPaused --- src/d_main.c | 4 +- src/i_sound.h | 2 + src/m_menu.c | 6 +- src/s_sound.c | 182 +++++++++++++++++++++--------------------- src/s_sound.h | 17 ++-- src/sdl/mixer_sound.c | 10 +++ 6 files changed, 121 insertions(+), 100 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 95af1f754..17fac0b0c 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1197,7 +1197,7 @@ void D_SRB2Main(void) } else { - CONS_Printf("S_Init(): Setting up sound.\n"); + CONS_Printf("S_InitSfxChannels(): Setting up sound channels.\n"); } if (M_CheckParm("-nosound")) nosound = true; @@ -1212,7 +1212,7 @@ void D_SRB2Main(void) } I_StartupSound(); I_InitMusic(); - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_InitSfxChannels(cv_soundvolume.value); CONS_Printf("ST_Init(): Init status bar.\n"); ST_Init(); diff --git a/src/i_sound.h b/src/i_sound.h index 2045752de..8799449fe 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -125,6 +125,8 @@ void I_SetSfxVolume(UINT8 volume); // musictype_t I_GetMusicType(void); +boolean I_MusicPlaying(void); +boolean I_MusicPaused(void); /** \brief Init the music systems */ diff --git a/src/m_menu.c b/src/m_menu.c index fd3deab84..9a86d56e1 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9421,7 +9421,7 @@ static void M_ToggleSFX(INT32 choice) nosound = false; I_StartupSound(); if (nosound) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_InitSfxChannels(cv_soundvolume.value); S_StartSound(NULL, sfx_strpst); OP_SoundOptionsMenu[6].status = IT_STRING | IT_CVAR; //M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); @@ -9474,7 +9474,7 @@ static void M_ToggleDigital(INT32 choice) nodigimusic = false; I_InitMusic(); if (nodigimusic) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_InitSfxChannels(cv_soundvolume.value); S_StopMusic(); if (Playing()) P_RestoreMusic(&players[consoleplayer]); @@ -9531,7 +9531,7 @@ static void M_ToggleMIDI(INT32 choice) nomidimusic = false; I_InitMusic(); if (nomidimusic) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_InitSfxChannels(cv_soundvolume.value); if (Playing()) P_RestoreMusic(&players[consoleplayer]); else diff --git a/src/s_sound.c b/src/s_sound.c index f58db4145..077b798b8 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1283,6 +1283,43 @@ void S_StartSoundName(void *mo, const char *soundname) S_StartSound(mo, soundnum); } +// +// Initializes sound stuff, including volume +// Sets channels, SFX volume, +// allocates channel buffer, sets S_sfx lookup. +// +void S_InitSfxChannels(INT32 sfxVolume) +{ + INT32 i; + + if (dedicated) + return; + + S_SetSfxVolume(sfxVolume); + + SetChannelsNum(); + + // Note that sounds have not been cached (yet). + for (i = 1; i < NUMSFX; i++) + { + S_sfx[i].usefulness = -1; // for I_GetSfx() + S_sfx[i].lumpnum = LUMPERROR; + } + + // precache sounds if requested by cmdline, or precachesound var true + if (!nosound && (M_CheckParm("-precachesound") || precachesound.value)) + { + // Initialize external data (all sounds) at start, keep static. + CONS_Printf(M_GetText("Loading sounds... ")); + + for (i = 1; i < NUMSFX; i++) + if (S_sfx[i].name) + S_sfx[i].data = I_GetSfx(&S_sfx[i]); + + CONS_Printf(M_GetText(" pre-cached all sound data\n")); + } +} + /// ------------------------ /// Music /// ------------------------ @@ -1309,10 +1346,7 @@ const char *compat_special_music_slots[16] = }; #endif -#define music_playing (music_name[0]) // String is empty if no music is playing - static char music_name[7]; // up to 6-character name -static boolean mus_paused = 0; // whether songs are mus_paused /// ------------------------ /// Music Status @@ -1338,6 +1372,29 @@ boolean S_MusicDisabled() ); } +boolean S_MusicPlaying(void) +{ + return I_MusicPlaying(); +} + +boolean S_MusicPaused(void) +{ + return I_MusicPaused(); +} + +const char *S_MusicName(void) +{ + return music_name; +} + +boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi) +{ + return ( + (checkDigi ? W_CheckNumForName(va("O_%s", mname)) != LUMPERROR : false) + || (checkMIDI ? W_CheckNumForName(va("D_%s", mname)) != LUMPERROR : false) + ); +} + /// ------------------------ /// Music Properties /// ------------------------ @@ -1361,15 +1418,15 @@ static boolean S_LoadMusic(const char *mname) if (S_DigMusicDisabled()) { - if (W_CheckNumForName(va("d_%s", mname)) == LUMPERROR) + if (!S_MIDIExists(mname)) return false; mlumpnum = W_GetNumForName(va("d_%s", mname)); } else { - if (W_CheckNumForName(va("o_%s", mname)) != LUMPERROR) + if (S_DigExists(mname)) mlumpnum = W_GetNumForName(va("o_%s", mname)); - else if (W_CheckNumForName(va("d_%s", mname)) != LUMPERROR) + else if (S_MIDIExists(mname)) mlumpnum = W_GetNumForName(va("d_%s", mname)); else return false; @@ -1442,10 +1499,10 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) void S_StopMusic(void) { - if (!music_playing) + if (!I_MusicPlaying()) return; - if (mus_paused) + if (I_MusicPaused()) I_ResumeSong(); S_SpeedMusic(1.0f); @@ -1465,6 +1522,31 @@ void S_StopMusic(void) } } +// +// Stop and resume music, during game PAUSE. +// +void S_PauseAudio(void) +{ + if (I_MusicPlaying() && !I_MusicPaused()) + I_PauseSong(); + + // pause cd music +#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) + I_PauseCD(); +#else + I_StopCD(); +#endif +} + +void S_ResumeAudio(void) +{ + if (I_MusicPlaying() && I_MusicPaused()) + I_ResumeSong(); + + // resume cd music + I_ResumeCD(); +} + void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) { if (digvolume < 0) @@ -1477,7 +1559,7 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) CV_SetValue(&cv_digmusicvolume, digvolume&31); actualdigmusicvolume = cv_digmusicvolume.value; //check for change of var - if (digvolume < 0 || digvolume > 31) + if (seqvolume < 0 || seqvolume > 31) CONS_Alert(CONS_WARNING, "midimusicvolume should be between 0-31\n"); CV_SetValue(&cv_midimusicvolume, seqvolume&31); actualmidimusicvolume = cv_midimusicvolume.value; //check for change of var @@ -1497,52 +1579,11 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) } } + /// ------------------------ /// Init & Others /// ------------------------ -// -// Initializes sound stuff, including volume -// Sets channels, SFX and music volume, -// allocates channel buffer, sets S_sfx lookup. -// -void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume) -{ - INT32 i; - - if (dedicated) - return; - - S_SetSfxVolume(sfxVolume); - S_SetMusicVolume(digMusicVolume, midiMusicVolume); - - SetChannelsNum(); - - // no sounds are playing, and they are not mus_paused - mus_paused = 0; - - // Note that sounds have not been cached (yet). - for (i = 1; i < NUMSFX; i++) - { - S_sfx[i].usefulness = -1; // for I_GetSfx() - S_sfx[i].lumpnum = LUMPERROR; - } - - // precache sounds if requested by cmdline, or precachesound var true - if (!nosound && (M_CheckParm("-precachesound") || precachesound.value)) - { - // Initialize external data (all sounds) at start, keep static. - CONS_Printf(M_GetText("Loading sounds... ")); - - for (i = 1; i < NUMSFX; i++) - if (S_sfx[i].name) - S_sfx[i].data = I_GetSfx(&S_sfx[i]); - - CONS_Printf(M_GetText(" pre-cached all sound data\n")); - } -} - - // // Per level startup code. // Kills playing sounds at start of level, @@ -1557,46 +1598,7 @@ void S_Start(void) mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); } - mus_paused = 0; - if (cv_resetmusic.value) S_StopMusic(); S_ChangeMusic(mapmusname, mapmusflags, true); } - -// -// Stop and resume music, during game PAUSE. -// -void S_PauseAudio(void) -{ - if (!nodigimusic) - I_PauseSong(); - - if (music_playing && !mus_paused) - { - I_PauseSong(); - mus_paused = true; - } - - // pause cd music -#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) - I_PauseCD(); -#else - I_StopCD(); -#endif -} - -void S_ResumeAudio(void) -{ - if (!nodigimusic) - I_ResumeSong(); - else - if (music_playing && mus_paused) - { - I_ResumeSong(); - mus_paused = false; - } - - // resume cd music - I_ResumeCD(); -} diff --git a/src/s_sound.h b/src/s_sound.h index 891254b4c..730dfd8d6 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -97,9 +97,9 @@ void S_RegisterSoundStuff(void); // // Initializes sound stuff, including volume -// Sets channels, SFX and music volume, allocates channel buffer, sets S_sfx lookup. +// Sets channels, SFX, allocates channel buffer, sets S_sfx lookup. // -void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume); +void S_InitSfxChannels(INT32 sfxVolume); // // Per level startup code. @@ -129,9 +129,16 @@ void S_StopSound(void *origin); // Music Status // -boolean S_DigMusicDisabled(); -boolean S_MIDIMusicDisabled(); -boolean S_MusicDisabled(); +boolean S_DigMusicDisabled(void); +boolean S_MIDIMusicDisabled(void); +boolean S_MusicDisabled(void); +boolean S_MusicPlaying(void); +boolean S_MusicPaused(void); +const char *S_MusicName(void); +boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi); +#define S_DigExists(a) S_MusicExists(a, false, true) +#define S_MIDIExists(a) S_MusicExists(a, true, false) + // // Music Properties diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 2ebc5750d..8f40cd175 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -453,6 +453,16 @@ musictype_t I_GetMusicType(void) return (musictype_t)Mix_GetMusicType(music); } +boolean I_MusicPlaying(void) +{ + return (boolean)music; +} + +boolean I_MusicPaused(void) +{ + return songpaused; +} + // Music hooks static void music_loop(void) { From d5ec38815968e267aceb59a48a6cb6d3292c0b69 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:31:01 -0400 Subject: [PATCH 16/30] I_MusicPlaying, I_MusicPaused other targets --- src/android/i_sound.c | 10 ++++++++++ src/djgppdos/i_sound.c | 17 +++++++++++++++-- src/dummy/i_sound.c | 10 ++++++++++ src/sdl/sdl_sound.c | 10 ++++++++++ src/win32/win_snd.c | 13 +++++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 0bb47d5cf..3ce02b419 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -65,6 +65,16 @@ musictype_t I_GetMusicType(void) return MU_NONE; } +boolean I_MusicPlaying(void) +{ + return false; +} + +boolean I_MusicPaused(void) +{ + return false; +} + void I_InitMusic(void){} void I_ShutdownMusic(void){} diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index d924a6560..ed681f7dd 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -321,6 +321,7 @@ static MIDI* currsong; //im assuming only 1 song will be played at once static int islooping=0; static int musicdies=-1; UINT8 music_started=0; +boolean songpaused=false; musictype_t I_GetMusicType(void) { @@ -330,6 +331,16 @@ musictype_t I_GetMusicType(void) return MU_NONE; } +boolean I_MusicPlaying() +{ + return (boolean)currsong; +} + +boolean I_MusicPaused() +{ + return songpaused; +} + /* load_midi_mem: * Loads a standard MIDI file from memory, returning a pointer to * a MIDI structure, * or NULL on error. @@ -403,6 +414,7 @@ void I_InitMusic(void) I_AddExitFunc(I_ShutdownMusic); music_started = true; + songpaused = false; } void I_ShutdownMusic(void) @@ -433,8 +445,8 @@ void I_PauseSong (INT32 handle) handle = 0; if (nomidimusic) return; - midi_pause(); + songpaused = true; } void I_ResumeSong (INT32 handle) @@ -442,8 +454,8 @@ void I_ResumeSong (INT32 handle) handle = 0; if (nomidimusic) return; - midi_resume(); + songpaused = false; } void I_StopSong(void) @@ -455,6 +467,7 @@ void I_StopSong(void) islooping = 0; musicdies = 0; stop_midi(); + songpaused = false; } // Is the song playing? diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 6a01787d9..6afbecf76 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -66,6 +66,16 @@ musictype_t I_GetMusicType(void) return MU_NONE; } +boolean I_MusicPlaying(void) +{ + return false; +} + +boolean I_MusicPaused(void) +{ + return false; +} + void I_InitMusic(void){} void I_ShutdownMusic(void){} diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 23cce94d9..53db7dd26 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1336,6 +1336,16 @@ musictype_t I_GetMusicType(void) #endif } +boolean I_MusicPlaying(void) +{ + return music_started; +} + +boolean I_MusicPaused(void) +{ + return Mix_PausedMusic(); +} + #ifdef HAVE_LIBGME static void I_ShutdownGMEMusic(void) { diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 9bfd1297f..d69562d41 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -478,6 +478,19 @@ musictype_t I_GetMusicType(void) return MU_NONE; } +boolean I_MusicPlaying(void) +{ + return (boolean)music_stream; +} + +boolean I_MusicPaused(void) +{ + boolean fmpaused = false; + if (music_stream) + FMOD_Channel_GetPaused(music_channel, &fmpaused); + return fmpaused; +} + void I_InitMusic(void) { } From 07738fb0bcf640a4349337373f451fe68e024b2a Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:42:15 -0400 Subject: [PATCH 17/30] nodigimusic nomusic nosound -> digital_disabled midi_disabled sound_disabled --- src/d_main.c | 23 +++++++-------- src/doomstat.h | 5 +--- src/m_menu.c | 76 +++++++++++++++++--------------------------------- src/p_mobj.c | 2 +- src/s_sound.c | 27 ++++++++---------- 5 files changed, 48 insertions(+), 85 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 17fac0b0c..74d7236a5 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -112,13 +112,10 @@ INT32 postimgparam; postimg_t postimgtype2 = postimg_none; INT32 postimgparam2; -boolean nomidimusic = false, nosound = false; -boolean nodigimusic = false; // No fmod-based music - -// These variables are only true if -// the respective sound system is initialized -// and active, but no sounds/music should play. -boolean music_disabled = false; +// These variables are in effect +// whether the respective sound system is disabled +// or they're init'ed, but the player just toggled them +boolean midi_disabled = false; boolean sound_disabled = false; boolean digital_disabled = false; @@ -1192,23 +1189,23 @@ void D_SRB2Main(void) // setting up sound if (dedicated) { - nosound = true; - nomidimusic = nodigimusic = true; + sound_disabled = true; + midi_disabled = digital_disabled = true; } else { CONS_Printf("S_InitSfxChannels(): Setting up sound channels.\n"); } if (M_CheckParm("-nosound")) - nosound = true; + sound_disabled = true; if (M_CheckParm("-nomusic")) // combines -nomidimusic and -nodigmusic - nomidimusic = nodigimusic = true; + midi_disabled = digital_disabled = true; else { if (M_CheckParm("-nomidimusic")) - nomidimusic = true; ; // WARNING: DOS version initmusic in I_StartupSound + midi_disabled = true; ; // WARNING: DOS version initmusic in I_StartupSound if (M_CheckParm("-nodigmusic")) - nodigimusic = true; // WARNING: DOS version initmusic in I_StartupSound + digital_disabled = true; // WARNING: DOS version initmusic in I_StartupSound } I_StartupSound(); I_InitMusic(); diff --git a/src/doomstat.h b/src/doomstat.h index 24b9e5753..f960dcd80 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -90,10 +90,7 @@ extern boolean fromlevelselect; // Internal parameters for sound rendering. // ======================================== -extern boolean nomidimusic; // defined in d_main.c -extern boolean nosound; -extern boolean nodigimusic; -extern boolean music_disabled; +extern boolean midi_disabled; extern boolean sound_disabled; extern boolean digital_disabled; diff --git a/src/m_menu.c b/src/m_menu.c index 9a86d56e1..990354183 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9350,7 +9350,7 @@ static void M_SoundMenu(INT32 choice) { (void)choice; - OP_SoundOptionsMenu[6].status = ((nosound || sound_disabled) ? IT_GRAYEDOUT : (IT_STRING | IT_CVAR)); + OP_SoundOptionsMenu[6].status = (sound_disabled ? IT_GRAYEDOUT : (IT_STRING | IT_CVAR)); M_SetupNextMenu(&OP_SoundOptionsDef); } @@ -9363,25 +9363,25 @@ void M_DrawSoundMenu(void) V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y+currentMenu->menuitems[0].alphaKey, - (nosound ? V_REDMAP : V_YELLOWMAP), - ((nosound || sound_disabled) ? offstring : onstring)); + (sound_disabled ? V_REDMAP : V_YELLOWMAP), + (sound_disabled ? offstring : onstring)); V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y+currentMenu->menuitems[2].alphaKey, - (nodigimusic ? V_REDMAP : V_YELLOWMAP), - ((nodigimusic || digital_disabled) ? offstring : onstring)); + (digital_disabled ? V_REDMAP : V_YELLOWMAP), + (digital_disabled ? offstring : onstring)); V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y+currentMenu->menuitems[4].alphaKey, - (nomidimusic ? V_REDMAP : V_YELLOWMAP), - ((nomidimusic || music_disabled) ? offstring : onstring)); + (midi_disabled ? V_REDMAP : V_YELLOWMAP), + (midi_disabled ? offstring : onstring)); if (itemOn == 0) - lengthstring = ((nosound || sound_disabled) ? 3 : 2); + lengthstring = (sound_disabled ? 3 : 2); else if (itemOn == 2) - lengthstring = ((nodigimusic || digital_disabled) ? 3 : 2); + lengthstring = (digital_disabled ? 3 : 2); else if (itemOn == 4) - lengthstring = ((nomidimusic || music_disabled) ? 3 : 2); + lengthstring = (midi_disabled ? 3 : 2); else return; @@ -9416,11 +9416,11 @@ static void M_ToggleSFX(INT32 choice) break; } - if (nosound) + if (sound_disabled) { - nosound = false; + sound_disabled = false; I_StartupSound(); - if (nosound) return; + if (sound_disabled) return; S_InitSfxChannels(cv_soundvolume.value); S_StartSound(NULL, sfx_strpst); OP_SoundOptionsMenu[6].status = IT_STRING | IT_CVAR; @@ -9469,12 +9469,11 @@ static void M_ToggleDigital(INT32 choice) break; } - if (nodigimusic) + if (digital_disabled) { - nodigimusic = false; + digital_disabled = false; I_InitMusic(); - if (nodigimusic) return; - S_InitSfxChannels(cv_soundvolume.value); + if (digital_disabled) return; S_StopMusic(); if (Playing()) P_RestoreMusic(&players[consoleplayer]); @@ -9484,21 +9483,9 @@ static void M_ToggleDigital(INT32 choice) } else { - if (digital_disabled) - { - digital_disabled = false; - if (Playing()) - P_RestoreMusic(&players[consoleplayer]); - else - S_ChangeMusicInternal("_clear", false); - //M_StartMessage(M_GetText("Digital Music Enabled\n"), NULL, MM_NOTHING); - } - else - { - digital_disabled = true; - S_StopMusic(); - //M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING); - } + digital_disabled = true; + S_StopMusic(); + //M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING); } } @@ -9526,12 +9513,11 @@ static void M_ToggleMIDI(INT32 choice) break; } - if (nomidimusic) + if (midi_disabled) { - nomidimusic = false; + midi_disabled = false; I_InitMusic(); - if (nomidimusic) return; - S_InitSfxChannels(cv_soundvolume.value); + if (midi_disabled) return; if (Playing()) P_RestoreMusic(&players[consoleplayer]); else @@ -9540,21 +9526,9 @@ static void M_ToggleMIDI(INT32 choice) } else { - if (music_disabled) - { - music_disabled = false; - if (Playing()) - P_RestoreMusic(&players[consoleplayer]); - else - S_ChangeMusicInternal("_clear", false); - //M_StartMessage(M_GetText("MIDI Music Enabled\n"), NULL, MM_NOTHING); - } - else - { - music_disabled = true; - S_StopMusic(); - //M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING); - } + midi_disabled = true; + S_StopMusic(); + //M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING); } } diff --git a/src/p_mobj.c b/src/p_mobj.c index 4353e67c3..e1706bc5f 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -9172,7 +9172,7 @@ void P_PrecipitationEffects(void) if (!playeringame[displayplayer] || !players[displayplayer].mo) return; - if (nosound || sound_disabled) + if (sound_disabled) return; // Sound off? D'aw, no fun. if (players[displayplayer].mo->subsector->sector->ceilingpic == skyflatnum) diff --git a/src/s_sound.c b/src/s_sound.c index 077b798b8..e08c6f057 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -230,7 +230,7 @@ void S_RegisterSoundStuff(void) { if (dedicated) { - nosound = true; + sound_disabled = true; return; } @@ -494,7 +494,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) mobj_t *listenmobj = players[displayplayer].mo; mobj_t *listenmobj2 = NULL; - if (sound_disabled || !sound_started || nosound) + if (sound_disabled || !sound_started) return; // Don't want a sound? Okay then... @@ -824,7 +824,7 @@ void S_UpdateSounds(void) goto notinlevel; } - if (dedicated || nosound) + if (dedicated || sound_disabled) return; if (players[displayplayer].awayviewtics) @@ -1307,7 +1307,7 @@ void S_InitSfxChannels(INT32 sfxVolume) } // precache sounds if requested by cmdline, or precachesound var true - if (!nosound && (M_CheckParm("-precachesound") || precachesound.value)) + if (!sound_disabled && (M_CheckParm("-precachesound") || precachesound.value)) { // Initialize external data (all sounds) at start, keep static. CONS_Printf(M_GetText("Loading sounds... ")); @@ -1352,24 +1352,19 @@ static char music_name[7]; // up to 6-character name /// Music Status /// ------------------------ -boolean S_DigMusicDisabled() +boolean S_DigMusicDisabled(void) { - return (nodigimusic || digital_disabled); + return digital_disabled; } -boolean S_MIDIMusicDisabled() +boolean S_MIDIMusicDisabled(void) { - return (nomidimusic || music_disabled); + return midi_disabled; } -boolean S_MusicDisabled() +boolean S_MusicDisabled(void) { - return ( - (nodigimusic && nomidimusic) || - (music_disabled && digital_disabled) || - (nodigimusic && music_disabled) || - (nomidimusic && digital_disabled) - ); + return (midi_disabled && digital_disabled); } boolean S_MusicPlaying(void) @@ -1453,7 +1448,7 @@ static void S_UnloadMusic(void) static boolean S_PlayMusic(boolean looping) { - if (nodigimusic || digital_disabled) + if (S_DigMusicDisabled()) return false; // try midi if (!I_PlaySong(looping)) From 86f151db654beb14e8d6893cdff2adaa965e8e4b Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:43:38 -0400 Subject: [PATCH 18/30] nodigimusic nomusic nosound refactor other targets --- src/djgppdos/i_sound.c | 38 +++++++++++++++++----------------- src/hardware/hw3sound.c | 2 +- src/sdl/sdl_sound.c | 46 ++++++++++++++++++++--------------------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index ed681f7dd..1ba8d7bae 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -134,7 +134,7 @@ FUNCINLINE static ATTRINLINE int Volset(int vol) void I_SetSfxVolume(INT32 volume) { - if (nosound) + if (sound_disabled) return; set_volume (Volset(volume),-1); @@ -142,7 +142,7 @@ void I_SetSfxVolume(INT32 volume) void I_SetMusicVolume(INT32 volume) { - if (nomidimusic) + if (midi_disabled) return; // Now set volume on output device. @@ -169,7 +169,7 @@ INT32 I_StartSound ( sfxenum_t id, { int voice; - if (nosound) + if (sound_disabled) return 0; // UNUSED @@ -190,7 +190,7 @@ void I_StopSound (INT32 handle) // an setting the channel to zero. int voice=handle & (VIRTUAL_VOICES-1); - if (nosound) + if (sound_disabled) return; if (voice_check(voice)==S_sfx[handle>>VOICESSHIFT].data) @@ -199,7 +199,7 @@ void I_StopSound (INT32 handle) INT32 I_SoundIsPlaying(INT32 handle) { - if (nosound) + if (sound_disabled) return FALSE; if (voice_check(handle & (VIRTUAL_VOICES-1))==S_sfx[handle>>VOICESSHIFT].data) @@ -229,7 +229,7 @@ void I_UpdateSoundParams( INT32 handle, int voice=handle & (VIRTUAL_VOICES-1); int numsfx=handle>>VOICESSHIFT; - if (nosound) + if (sound_disabled) return; if (voice_check(voice)==S_sfx[numsfx].data) @@ -270,17 +270,17 @@ void I_StartupSound(void) char err[255]; #endif - if (nosound) + if (sound_disabled) sfxcard=DIGI_NONE; else sfxcard=DIGI_AUTODETECT; - if (nomidimusic) + if (midi_disabled) midicard=MIDI_NONE; else midicard=MIDI_AUTODETECT; //DetectMusicCard(); - nodigimusic=true; //Alam: No OGG/MP3/IT/MOD support + digital_disabled=true; //Alam: No OGG/MP3/IT/MOD support // Secure and configure sound device first. CONS_Printf("I_StartupSound: "); @@ -293,8 +293,8 @@ void I_StartupSound(void) { sprintf (err,"Sound init error : %s\n",allegro_error); CONS_Error (err); - nosound=true; - nomidimusic=true; + sound_disabled=true; + midi_disabled=true; } else { @@ -409,7 +409,7 @@ static MIDI *load_midi_mem(char *mempointer,int *e) void I_InitMusic(void) { - if (nomidimusic) + if (midi_disabled) return; I_AddExitFunc(I_ShutdownMusic); @@ -430,7 +430,7 @@ void I_ShutdownMusic(void) boolean I_PlaySong(boolean looping) { handle = 0; - if (nomidimusic) + if (midi_disabled) return false; islooping = looping; @@ -443,7 +443,7 @@ boolean I_PlaySong(boolean looping) void I_PauseSong (INT32 handle) { handle = 0; - if (nomidimusic) + if (midi_disabled) return; midi_pause(); songpaused = true; @@ -452,7 +452,7 @@ void I_PauseSong (INT32 handle) void I_ResumeSong (INT32 handle) { handle = 0; - if (nomidimusic) + if (midi_disabled) return; midi_resume(); songpaused = false; @@ -461,7 +461,7 @@ void I_ResumeSong (INT32 handle) void I_StopSong(void) { handle = 0; - if (nomidimusic) + if (midi_disabled) return; islooping = 0; @@ -474,7 +474,7 @@ void I_StopSong(void) #if 0 int I_QrySongPlaying(int handle) { - if (nomidimusic) + if (midi_disabled) return 0; //return islooping || musicdies > gametic; @@ -485,7 +485,7 @@ int I_QrySongPlaying(int handle) void I_UnloadSong(void) { handle = 0; - if (nomidimusic) + if (midi_disabled) return; //destroy_midi(currsong); @@ -494,7 +494,7 @@ void I_UnloadSong(void) boolean I_LoadSong(char *data, size_t len) { int e = len; //Alam: For error - if (nomidimusic) + if (midi_disabled) return 0; if (memcmp(data,"MThd",4)==0) // support mid file in WAD !!! diff --git a/src/hardware/hw3sound.c b/src/hardware/hw3sound.c index c68430921..f7c6e1da0 100644 --- a/src/hardware/hw3sound.c +++ b/src/hardware/hw3sound.c @@ -361,7 +361,7 @@ INT32 HW3S_I_StartSound(const void *origin_p, source3D_data_t *source_parm, chan if (splitscreen) listenmobj2 = players[secondarydisplayplayer].mo; - if (nosound) + if (sound_disabled) return -1; sfx = &S_sfx[sfx_id]; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 53db7dd26..24239f822 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -194,8 +194,8 @@ static srb2audio_t localdata; static void Snd_LockAudio(void) //Alam: Lock audio data and uninstall audio callback { if (Snd_Mutex) SDL_LockMutex(Snd_Mutex); - else if (nosound) return; - else if (nomidimusic && nodigimusic + else if (sound_disabled) return; + else if (midi_disabled && digital_disabled #ifdef HW3SOUND && hws_mode == HWS_DEFAULT_MODE #endif @@ -208,8 +208,8 @@ static void Snd_LockAudio(void) //Alam: Lock audio data and uninstall audio call static void Snd_UnlockAudio(void) //Alam: Unlock audio data and reinstall audio callback { if (Snd_Mutex) SDL_UnlockMutex(Snd_Mutex); - else if (nosound) return; - else if (nomidimusic && nodigimusic + else if (sound_disabled) return; + else if (midi_disabled && digital_disabled #ifdef HW3SOUND && hws_mode == HWS_DEFAULT_MODE #endif @@ -493,7 +493,7 @@ static inline void I_SetChannels(void) INT32 *steptablemid = steptable + 128; - if (nosound) + if (sound_disabled) return; // This table provides step widths for pitch parameters. @@ -609,7 +609,7 @@ INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priori (void)priority; (void)pitch; - if (nosound) + if (sound_disabled) return 0; if (S_sfx[id].data == NULL) return -1; @@ -1136,7 +1136,7 @@ static INT32 Init3DSDriver(const char *soName) void I_ShutdownSound(void) { - if (nosound || !sound_started) + if (sound_disabled || !sound_started) return; CONS_Printf("I_ShutdownSound: "); @@ -1150,7 +1150,7 @@ void I_ShutdownSound(void) } #endif - if (nomidimusic && nodigimusic) + if (midi_disabled && digital_disabled) SDL_CloseAudio(); CONS_Printf("%s", M_GetText("shut down\n")); sound_started = false; @@ -1170,7 +1170,7 @@ void I_StartupSound(void) const char *sdrv_name = NULL; #endif #ifndef HAVE_MIXER - nomidimusic = nodigimusic = true; + midi_disabled = digital_disabled = true; #endif memset(channels, 0, sizeof (channels)); //Alam: Clean it @@ -1213,7 +1213,7 @@ void I_StartupSound(void) audio.samples /= 2; } - if (nosound) + if (sound_disabled) return; #ifdef HW3SOUND @@ -1261,7 +1261,7 @@ void I_StartupSound(void) { snddev_t snddev; - //nosound = true; + //sound_disabled = true; //I_AddExitFunc(I_ShutdownSound); snddev.bps = 16; snddev.sample_rate = audio.freq; @@ -1288,7 +1288,7 @@ void I_StartupSound(void) if (!musicStarted && SDL_OpenAudio(&audio, &audio) < 0) { CONS_Printf("%s", M_GetText(" couldn't open audio with desired format\n")); - nosound = true; + sound_disabled = true; return; } else @@ -1452,7 +1452,7 @@ static boolean LoadSong(void *data, size_t lumplength, size_t selectpos) void I_ShutdownMusic(void) { #ifdef HAVE_MIXER - if ((nomidimusic && nodigimusic) || !musicStarted) + if ((midi_disabled && digital_disabled) || !musicStarted) return; CONS_Printf("%s", M_GetText("I_ShutdownMusic: ")); @@ -1543,7 +1543,7 @@ void I_InitMusic(void) if (Mix_OpenAudio(audio.freq, audio.format, audio.channels, audio.samples) < 0) //open_music(&audio) { CONS_Printf(M_GetText(" Unable to open music: %s\n"), Mix_GetError()); - nomidimusic = nodigimusic = true; + midi_disabled = digital_disabled = true; if (sound_started #ifdef HW3SOUND && hws_mode == HWS_DEFAULT_MODE @@ -1553,7 +1553,7 @@ void I_InitMusic(void) if (SDL_OpenAudio(&audio, NULL) < 0) //retry { CONS_Printf("%s", M_GetText(" couldn't open audio with desired format\n")); - nosound = true; + sound_disabled = true; sound_started = false; } else @@ -1588,7 +1588,7 @@ boolean I_PlaySong(INT32 handle, boolean looping) { (void)handle; #ifdef HAVE_MIXER - if (nomidimusic || !musicStarted || !music[handle]) + if (midi_disabled || !musicStarted || !music[handle]) return false; #ifdef MIXER_POS @@ -1621,7 +1621,7 @@ void I_PauseSong(void) (void)handle; I_PauseGME(); #ifdef HAVE_MIXER - if ((nomidimusic && nodigimusic) || !musicStarted) + if ((midi_disabled && digital_disabled) || !musicStarted) return; Mix_PauseMusic(); @@ -1641,7 +1641,7 @@ void I_ResumeSong(void) (void)handle; I_ResumeGME(); #ifdef HAVE_MIXER - if ((nomidimusic && nodigimusic) || !musicStarted) + if ((midi_disabled && digital_disabled) || !musicStarted) return; Mix_VolumeMusic(musicvol); @@ -1654,7 +1654,7 @@ void I_StopSong(void) { I_StopGME(); #ifdef HAVE_MIXER - if (nodigimusic) + if (digital_disabled) return; #ifdef MIXER_POS @@ -1676,7 +1676,7 @@ void I_UnloadSong(void) { #ifdef HAVE_MIXER - if (nomidimusic || !musicStarted) + if (midi_disabled || !musicStarted) return; Mix_HaltMusic(); @@ -1695,7 +1695,7 @@ void I_UnloadSong(void) boolean I_LoadSong(char *data, size_t len) { #ifdef HAVE_MIXER - if (nomidimusic || !musicStarted) + if (midi_disabled || !musicStarted) return false; if (!LoadSong(data, len, 0)) @@ -1715,7 +1715,7 @@ boolean I_LoadSong(char *data, size_t len) void I_SetMusicVolume(UINT8 volume) { #ifdef HAVE_MIXER - if ((nomidimusic && nodigimusic) || !musicStarted) + if ((midi_disabled && digital_disabled) || !musicStarted) return; if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); @@ -1802,7 +1802,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) return true; #ifdef HAVE_MIXER - if (nodigimusic) + if (digital_disabled) return false; snprintf(filename, sizeof filename, "o_%s", musicname); From 4aa100aa575cc7fc14a743085222c806ba2c714a Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:51:45 -0400 Subject: [PATCH 19/30] Toggle Digi/MIDI music in menu accurately; add S_MusicType --- src/m_menu.c | 6 ++++-- src/s_sound.c | 36 +++++++++++++++++++++--------------- src/s_sound.h | 2 ++ 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 990354183..52c36f442 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9484,7 +9484,8 @@ static void M_ToggleDigital(INT32 choice) else { digital_disabled = true; - S_StopMusic(); + if (S_MusicType() != MU_MID) + S_StopMusic(); //M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING); } } @@ -9527,7 +9528,8 @@ static void M_ToggleMIDI(INT32 choice) else { midi_disabled = true; - S_StopMusic(); + if (S_MusicType() == MU_MID) + S_StopMusic(); //M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING); } } diff --git a/src/s_sound.c b/src/s_sound.c index e08c6f057..17ecf3e3c 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1377,6 +1377,11 @@ boolean S_MusicPaused(void) return I_MusicPaused(); } +musictype_t S_MusicType(void) +{ + return I_GetMusicType(); +} + const char *S_MusicName(void) { return music_name; @@ -1411,20 +1416,24 @@ static boolean S_LoadMusic(const char *mname) if (S_MusicDisabled()) return false; - if (S_DigMusicDisabled()) - { - if (!S_MIDIExists(mname)) - return false; + if (!S_DigMusicDisabled() && S_DigExists(mname)) + mlumpnum = W_GetNumForName(va("o_%s", mname)); + else if (!S_MIDIMusicDisabled() && S_MIDIExists(mname)) mlumpnum = W_GetNumForName(va("d_%s", mname)); + else if (S_DigMusicDisabled() && S_DigExists(mname)) + { + CONS_Alert(CONS_NOTICE, "Digital music is disabled!\n"); + return false; + } + else if (S_MIDIMusicDisabled() && S_MIDIExists(mname)) + { + CONS_Alert(CONS_NOTICE, "MIDI music is disabled!\n"); + return false; } else { - if (S_DigExists(mname)) - mlumpnum = W_GetNumForName(va("o_%s", mname)); - else if (S_MIDIExists(mname)) - mlumpnum = W_GetNumForName(va("d_%s", mname)); - else - return false; + CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mname); + return false; } // load & register it @@ -1448,8 +1457,8 @@ static void S_UnloadMusic(void) static boolean S_PlayMusic(boolean looping) { - if (S_DigMusicDisabled()) - return false; // try midi + if (S_MusicDisabled()) + return false; if (!I_PlaySong(looping)) { @@ -1478,10 +1487,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) S_StopMusic(); // shutdown old music if (!S_LoadMusic(mmusic)) - { - CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic); return; - } if (!S_PlayMusic(looping)) { diff --git a/src/s_sound.h b/src/s_sound.h index 730dfd8d6..89b6b4592 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -14,6 +14,7 @@ #ifndef __S_SOUND__ #define __S_SOUND__ +#include "i_sound.h" // musictype_t #include "sounds.h" #include "m_fixed.h" #include "command.h" @@ -134,6 +135,7 @@ boolean S_MIDIMusicDisabled(void); boolean S_MusicDisabled(void); boolean S_MusicPlaying(void); boolean S_MusicPaused(void); +musictype_t S_MusicType(void); const char *S_MusicName(void); boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi); #define S_DigExists(a) S_MusicExists(a, false, true) From f6ec93198f0dcfa1d053cca88172c3e3c7ba310c Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 16:46:40 -0400 Subject: [PATCH 20/30] Play the opposite type music (Digital/MIDI) when toggling between them in menu * S_MusicInfo method to retrieve name, flags, and looping --- src/m_menu.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- src/s_sound.c | 19 +++++++++++++++++-- src/s_sound.h | 2 +- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 52c36f442..532de9a45 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9485,7 +9485,24 @@ static void M_ToggleDigital(INT32 choice) { digital_disabled = true; if (S_MusicType() != MU_MID) - S_StopMusic(); + { + if (midi_disabled) + S_StopMusic(); + else + { + char mmusic[7]; + UINT16 mflags; + boolean looping; + + if (S_MusicInfo(mmusic, &mflags, &looping) && S_MIDIExists(mmusic)) + { + S_StopMusic(); + S_ChangeMusic(mmusic, mflags, looping); + } + else + S_StopMusic(); + } + } //M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING); } } @@ -9504,6 +9521,12 @@ static void M_ToggleMIDI(INT32 choice) itemOn--; return; + case KEY_LEFTARROW: + case KEY_RIGHTARROW: + if (S_MusicType() != MU_MID && S_MusicType() != MU_NONE) + S_StartSound(NULL, sfx_menu1); + break; + case KEY_ESCAPE: if (currentMenu->prevMenu) M_SetupNextMenu(currentMenu->prevMenu); @@ -9529,7 +9552,24 @@ static void M_ToggleMIDI(INT32 choice) { midi_disabled = true; if (S_MusicType() == MU_MID) - S_StopMusic(); + { + if (digital_disabled) + S_StopMusic(); + else + { + char mmusic[7]; + UINT16 mflags; + boolean looping; + + if (S_MusicInfo(mmusic, &mflags, &looping) && S_DigExists(mmusic)) + { + S_StopMusic(); + S_ChangeMusic(mmusic, mflags, looping); + } + else + S_StopMusic(); + } + } //M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING); } } diff --git a/src/s_sound.c b/src/s_sound.c index 17ecf3e3c..15e5cf638 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1347,6 +1347,8 @@ const char *compat_special_music_slots[16] = #endif static char music_name[7]; // up to 6-character name +static UINT16 music_flags; +static boolean music_looping; /// ------------------------ /// Music Status @@ -1382,9 +1384,17 @@ musictype_t S_MusicType(void) return I_GetMusicType(); } -const char *S_MusicName(void) +boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping) { - return music_name; + if (!I_MusicPlaying()) + return false; + + strncpy(mname, music_name, 7); + mname[6] = 0; + *mflags = music_flags; + *looping = music_looping; + + return (boolean)mname[0]; } boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi) @@ -1453,6 +1463,8 @@ static void S_UnloadMusic(void) { I_UnloadSong(); music_name[0] = 0; + music_flags = 0; + music_looping = false; } static boolean S_PlayMusic(boolean looping) @@ -1489,6 +1501,9 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) if (!S_LoadMusic(mmusic)) return; + music_flags = mflags; + music_looping = looping; + if (!S_PlayMusic(looping)) { CONS_Alert(CONS_ERROR, "Music cannot be played!\n"); diff --git a/src/s_sound.h b/src/s_sound.h index 89b6b4592..c94ae6652 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -136,7 +136,7 @@ boolean S_MusicDisabled(void); boolean S_MusicPlaying(void); boolean S_MusicPaused(void); musictype_t S_MusicType(void); -const char *S_MusicName(void); +boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping); boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi); #define S_DigExists(a) S_MusicExists(a, false, true) #define S_MIDIExists(a) S_MusicExists(a, true, false) From a7d51bf81030c228937a8e759f8f43b85817fce6 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 17:05:37 -0400 Subject: [PATCH 21/30] Minor refactoring and reordering * I_GetMusicType() -> I_MusicType() * Wrap MIDI volume hack in #ifdef _WIN32 --- src/i_sound.h | 93 +++++++++-------- src/s_sound.c | 8 +- src/sdl/mixer_sound.c | 238 +++++++++++++++++++++++------------------- 3 files changed, 180 insertions(+), 159 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 8799449fe..7959b9a51 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -66,9 +66,9 @@ void I_StartupSound(void); */ void I_ShutdownSound(void); -// -// SFX I/O -// +/// ------------------------ +/// SFX I/O +/// ------------------------ /** \brief Starts a sound in a particular sound channel. \param id sfxid @@ -120,13 +120,9 @@ void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep, UINT8 pitch); */ void I_SetSfxVolume(UINT8 volume); -// -// MUSIC I/O -// - -musictype_t I_GetMusicType(void); -boolean I_MusicPlaying(void); -boolean I_MusicPaused(void); +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ /** \brief Init the music systems */ @@ -136,33 +132,23 @@ void I_InitMusic(void); */ void I_ShutdownMusic(void); -/** \brief PAUSE game handling. +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ - \param handle song handle +musictype_t I_MusicType(void); +boolean I_MusicPlaying(void); +boolean I_MusicPaused(void); - \return void -*/ -void I_PauseSong(void); +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ -/** \brief RESUME game handling +boolean I_SetSongSpeed(float speed); - \param handle song handle - - \return void -*/ -void I_ResumeSong(void); - -// -// MIDI I/O -// - -/** \brief The I_SetMusicVolume function - - \param volume volume to set at - - \return void -*/ -void I_SetMusicVolume(UINT8 volume); +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ /** \brief Registers a song handle to song data. @@ -175,6 +161,15 @@ void I_SetMusicVolume(UINT8 volume); */ boolean I_LoadSong(char *data, size_t len); +/** \brief See ::I_LoadSong, then think backwards + + \param handle song handle + + \sa I_LoadSong + \todo remove midi handle +*/ +void I_UnloadSong(void); + /** \brief Called by anything that wishes to start music \param handle Song handle @@ -195,27 +190,35 @@ boolean I_PlaySong(boolean looping); */ void I_StopSong(void); -/** \brief See ::I_LoadSong, then think backwards +/** \brief PAUSE game handling. \param handle song handle - \sa I_LoadSong - \todo remove midi handle + \return void */ -void I_UnloadSong(void); +void I_PauseSong(void); -// -// DIGMUSIC I/O -// +/** \brief RESUME game handling -boolean I_SetSongSpeed(float speed); + \param handle song handle + + \return void +*/ +void I_ResumeSong(void); + +/** \brief The I_SetMusicVolume function + + \param volume volume to set at + + \return void +*/ +void I_SetMusicVolume(UINT8 volume); boolean I_SetSongTrack(INT32 track); -// -// CD MUSIC I/O -// - +/// ------------------------ +// CD MUSIC I/O +/// ------------------------ /** \brief cd music interface */ diff --git a/src/s_sound.c b/src/s_sound.c index 15e5cf638..2d45a363b 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1381,7 +1381,7 @@ boolean S_MusicPaused(void) musictype_t S_MusicType(void) { - return I_GetMusicType(); + return I_MusicType(); } boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping) @@ -1406,7 +1406,7 @@ boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi) } /// ------------------------ -/// Music Properties +/// Music Effects /// ------------------------ boolean S_SpeedMusic(float speed) @@ -1415,7 +1415,7 @@ boolean S_SpeedMusic(float speed) } /// ------------------------ -/// Music Routines +/// Music Playback /// ------------------------ static boolean S_LoadMusic(const char *mname) @@ -1584,7 +1584,7 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) digvolume = seqvolume = 31; #endif - switch(I_GetMusicType()) + switch(I_MusicType()) { case MU_MID: case MU_MOD: diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 8f40cd175..97341d5ad 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -72,6 +72,10 @@ static Music_Emu *gme; static INT32 current_track; #endif +/// ------------------------ +/// Audio System +/// ------------------------ + void I_StartupSound(void) { I_Assert(!sound_started); @@ -128,6 +132,10 @@ FUNCMATH void I_UpdateSound(void) { } +/// ------------------------ +/// SFX +/// ------------------------ + // this is as fast as I can possibly make it. // sorry. more asm needed. static Mix_Chunk *ds2chunk(void *stream) @@ -430,11 +438,72 @@ void I_SetSfxVolume(UINT8 volume) sfx_volume = volume; } -// -// Music -// +/// ------------------------ +/// Music Hooks +/// ------------------------ -musictype_t I_GetMusicType(void) +static void music_loop(void) +{ + Mix_PlayMusic(music, 0); + Mix_SetMusicPosition(loop_point); +} + +#ifdef HAVE_LIBGME +static void mix_gme(void *udata, Uint8 *stream, int len) +{ + int i; + short *p; + + (void)udata; + + // no gme? no music. + if (!gme || gme_track_ended(gme) || songpaused) + return; + + // play gme into stream + gme_play(gme, len/2, (short *)stream); + + // apply volume to stream + for (i = 0, p = (short *)stream; i < len/2; i++, p++) + *p = ((INT32)*p) * music_volume*2 / 42; +} +#endif + + +/// ------------------------ +/// Music System +/// ------------------------ + +FUNCMATH void I_InitMusic(void) +{ +#ifdef HAVE_LIBGME + gme = NULL; + current_track = -1; +#endif +} + +void I_ShutdownMusic(void) +{ +#ifdef HAVE_LIBGME + if (gme) + { + Mix_HookMusic(NULL, NULL); + gme_delete(gme); + gme = NULL; + } +#endif + if (!music) + return; + Mix_HookMusicFinished(NULL); + Mix_FreeMusic(music); + music = NULL; +} + +/// ------------------------ +/// Music Properties +/// ------------------------ + +musictype_t I_MusicType(void) { #ifdef HAVE_LIBGME if (gme) @@ -463,74 +532,9 @@ boolean I_MusicPaused(void) return songpaused; } -// Music hooks -static void music_loop(void) -{ - Mix_PlayMusic(music, 0); - Mix_SetMusicPosition(loop_point); -} - -#ifdef HAVE_LIBGME -static void mix_gme(void *udata, Uint8 *stream, int len) -{ - int i; - short *p; - - (void)udata; - - // no gme? no music. - if (!gme || gme_track_ended(gme) || songpaused) - return; - - // play gme into stream - gme_play(gme, len/2, (short *)stream); - - // apply volume to stream - for (i = 0, p = (short *)stream; i < len/2; i++, p++) - *p = ((INT32)*p) * music_volume*2 / 42; -} -#endif - -FUNCMATH void I_InitMusic(void) -{ -#ifdef HAVE_LIBGME - gme = NULL; - current_track = -1; -#endif -} - -void I_ShutdownMusic(void) -{ -#ifdef HAVE_LIBGME - if (gme) - { - Mix_HookMusic(NULL, NULL); - gme_delete(gme); - gme = NULL; - } -#endif - if (!music) - return; - Mix_HookMusicFinished(NULL); - Mix_FreeMusic(music); - music = NULL; -} - -void I_PauseSong(void) -{ - Mix_PauseMusic(); - songpaused = true; -} - -void I_ResumeSong(void) -{ - Mix_ResumeMusic(); - songpaused = false; -} - -// -// Digital Music -// +/// ------------------------ +/// Music Effects +/// ------------------------ boolean I_SetSongSpeed(float speed) { @@ -550,40 +554,9 @@ boolean I_SetSongSpeed(float speed) return false; } -boolean I_SetSongTrack(int track) -{ -#ifdef HAVE_LIBGME - if (current_track == track) - return false; - - // If the specified track is within the number of tracks playing, then change it - if (gme) - { - SDL_LockAudio(); - if (track >= 0 - && track < gme_track_count(gme)) - { - gme_err_t gme_e = gme_start_track(gme, track); - if (gme_e != NULL) - { - CONS_Alert(CONS_ERROR, "GME error: %s\n", gme_e); - return false; - } - current_track = track; - SDL_UnlockAudio(); - return true; - } - SDL_UnlockAudio(); - return false; - } -#endif - (void)track; - return false; -} - -// -// MIDI Music -// +/// ------------------------ +/// Music Playback +/// ------------------------ boolean I_LoadSong(char *data, size_t len) { @@ -731,6 +704,12 @@ boolean I_LoadSong(char *data, size_t len) return true; } +void I_UnloadSong(void) +{ + Mix_FreeMusic(music); + music = NULL; +} + boolean I_PlaySong(boolean looping) { if (!music) @@ -775,25 +754,64 @@ void I_StopSong(void) music = NULL; } +void I_PauseSong(void) +{ + Mix_PauseMusic(); + songpaused = true; +} + +void I_ResumeSong(void) +{ + Mix_ResumeMusic(); + songpaused = false; +} + void I_SetMusicVolume(UINT8 volume) { if (!music) return; - if (I_GetMusicType() == MU_MID) +#ifdef _WIN32 + if (I_MusicType() == MU_MID) // HACK: Until we stop using native MIDI, // disable volume changes music_volume = 31; else +#endif music_volume = volume; Mix_VolumeMusic((UINT32)music_volume*128/31); } -void I_UnloadSong(void) +boolean I_SetSongTrack(int track) { - Mix_FreeMusic(music); - music = NULL; +#ifdef HAVE_LIBGME + if (current_track == track) + return false; + + // If the specified track is within the number of tracks playing, then change it + if (gme) + { + SDL_LockAudio(); + if (track >= 0 + && track < gme_track_count(gme)) + { + gme_err_t gme_e = gme_start_track(gme, track); + if (gme_e != NULL) + { + CONS_Alert(CONS_ERROR, "GME error: %s\n", gme_e); + return false; + } + current_track = track; + SDL_UnlockAudio(); + return true; + } + SDL_UnlockAudio(); + return false; + } +#endif + (void)track; + return false; } #endif From cf065e106f68fb8af3b0568eba188c8235b1656e Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 17:05:47 -0400 Subject: [PATCH 22/30] Refactoring and reordering other targets --- src/android/i_sound.c | 64 +++++------ src/djgppdos/i_sound.c | 196 +++++++++++++++++++--------------- src/dummy/i_sound.c | 64 +++++------ src/sdl/sdl_sound.c | 237 +++++++++++++++++++++++------------------ src/win32/win_snd.c | 218 +++++++++++++++++++------------------ 5 files changed, 426 insertions(+), 353 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 3ce02b419..bf54c9ff0 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -55,12 +55,22 @@ void I_SetSfxVolume(INT32 volume) (void)volume; } -// -// MUSIC I/O -// -UINT8 music_started = 0; +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ -musictype_t I_GetMusicType(void) +UINT8 music_started = 0; +UINT8 digmusic_started = 0; + +void I_InitMusic(void){} + +void I_ShutdownMusic(void){} + +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ + +musictype_t I_MusicType(void) { return MU_NONE; } @@ -75,23 +85,19 @@ boolean I_MusicPaused(void) return false; } -void I_InitMusic(void){} +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ -void I_ShutdownMusic(void){} - -void I_PauseSong(void) +boolean I_SetSongSpeed(float speed) { - (void)handle; + (void)speed; + return false; } -void I_ResumeSong(void) -{ - (void)handle; -} - -// -// MIDI I/O -// +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ UINT8 midimusic_started = 0; @@ -102,9 +108,9 @@ boolean I_LoadSong(char *data, size_t len) return -1; } -void I_SetMusicVolume(INT32 volume) +void I_UnloadSong() { - (void)volume; + } boolean I_PlaySong(boolean looping) @@ -119,19 +125,17 @@ void I_StopSong(void) (void)handle; } -void I_UnloadSong(void) +void I_PauseSong(void) { (void)handle; } -// -// DIGMUSIC I/O -// - -UINT8 digmusic_started = 0; - -boolean I_SetSongSpeed(float speed) +void I_ResumeSong(void) { - (void)speed; - return false; + (void)handle; +} + +void I_SetMusicVolume(INT32 volume) +{ + (void)volume; } diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 1ba8d7bae..339b469d3 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -140,15 +140,6 @@ void I_SetSfxVolume(INT32 volume) set_volume (Volset(volume),-1); } -void I_SetMusicVolume(INT32 volume) -{ - if (midi_disabled) - return; - - // Now set volume on output device. - set_volume (-1, Volset(volume)); -} - // // Starting a sound means adding it // to the current list of active sounds @@ -323,23 +314,9 @@ static int musicdies=-1; UINT8 music_started=0; boolean songpaused=false; -musictype_t I_GetMusicType(void) -{ - if (currsong) - return MU_MID; - else - return MU_NONE; -} - -boolean I_MusicPlaying() -{ - return (boolean)currsong; -} - -boolean I_MusicPaused() -{ - return songpaused; -} +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ /* load_midi_mem: * Loads a standard MIDI file from memory, returning a pointer to @@ -427,69 +404,41 @@ void I_ShutdownMusic(void) music_started=false; } -boolean I_PlaySong(boolean looping) -{ - handle = 0; - if (midi_disabled) - return false; +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ - islooping = looping; - musicdies = gametic + NEWTICRATE*30; - if (play_midi(currsong,looping)==0) - return true; +musictype_t I_MusicType(void) +{ + if (currsong) + return MU_MID; + else + return MU_NONE; +} + +boolean I_MusicPlaying() +{ + return (boolean)currsong; +} + +boolean I_MusicPaused() +{ + return songpaused; +} + +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ + +boolean I_SetSongSpeed(float speed) +{ + (void)speed; return false; } -void I_PauseSong (INT32 handle) -{ - handle = 0; - if (midi_disabled) - return; - midi_pause(); - songpaused = true; -} - -void I_ResumeSong (INT32 handle) -{ - handle = 0; - if (midi_disabled) - return; - midi_resume(); - songpaused = false; -} - -void I_StopSong(void) -{ - handle = 0; - if (midi_disabled) - return; - - islooping = 0; - musicdies = 0; - stop_midi(); - songpaused = false; -} - -// Is the song playing? -#if 0 -int I_QrySongPlaying(int handle) -{ - if (midi_disabled) - return 0; - - //return islooping || musicdies > gametic; - return (midi_pos==-1); -} -#endif - -void I_UnloadSong(void) -{ - handle = 0; - if (midi_disabled) - return; - - //destroy_midi(currsong); -} +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ boolean I_LoadSong(char *data, size_t len) { @@ -516,8 +465,81 @@ boolean I_LoadSong(char *data, size_t len) return 1; } -boolean I_SetSongSpeed(float speed) +void I_UnloadSong(void) { - (void)speed; + handle = 0; + if (midi_disabled) + return; + + //destroy_midi(currsong); +} + +boolean I_PlaySong(boolean looping) +{ + handle = 0; + if (midi_disabled) + return false; + + islooping = looping; + musicdies = gametic + NEWTICRATE*30; + if (play_midi(currsong,looping)==0) + return true; return false; } + +void I_StopSong(void) +{ + handle = 0; + if (midi_disabled) + return; + + islooping = 0; + musicdies = 0; + stop_midi(); + songpaused = false; +} + +void I_PauseSong (INT32 handle) +{ + handle = 0; + if (midi_disabled) + return; + midi_pause(); + songpaused = true; +} + +void I_ResumeSong (INT32 handle) +{ + handle = 0; + if (midi_disabled) + return; + midi_resume(); + songpaused = false; +} + +void I_SetMusicVolume(INT32 volume) +{ + if (midi_disabled) + return; + + // Now set volume on output device. + set_volume (-1, Volset(volume)); +} + +boolean I_SetSongTrack(INT32 track) +{ + (void)track; + return false; +} + +// Is the song playing? +#if 0 +int I_QrySongPlaying(int handle) +{ + if (midi_disabled) + return 0; + + //return islooping || musicdies > gametic; + return (midi_pos==-1); +} +#endif diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 6afbecf76..cab64e692 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -57,11 +57,19 @@ void I_SetSfxVolume(UINT8 volume) (void)volume; } -// -// MUSIC I/O -// +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ -musictype_t I_GetMusicType(void) +void I_InitMusic(void){} + +void I_ShutdownMusic(void){} + +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ + +musictype_t I_MusicType(void) { return MU_NONE; } @@ -76,28 +84,19 @@ boolean I_MusicPaused(void) return false; } -void I_InitMusic(void){} +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ -void I_ShutdownMusic(void){} - -void I_SetMusicVolume(UINT8 volume) +boolean I_SetSongSpeed(float speed) { - (void)volume; + (void)speed; + return false; } -void I_PauseSong(void) -{ - (void)handle; -} - -void I_ResumeSong(void) -{ - (void)handle; -} - -// -// MIDI I/O -// +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ boolean I_LoadSong(char *data, size_t len) { @@ -106,6 +105,11 @@ boolean I_LoadSong(char *data, size_t len) return -1; } +void I_UnloadSong(void) +{ + (void)handle; +} + boolean I_PlaySong(boolean looping) { (void)handle; @@ -118,19 +122,19 @@ void I_StopSong(void) (void)handle; } -void I_UnloadSong(void) +void I_PauseSong(void) { (void)handle; } -// -// DIGMUSIC I/O -// - -boolean I_SetSongSpeed(float speed) +void I_ResumeSong(void) { - (void)speed; - return false; + (void)handle; +} + +void I_SetMusicVolume(UINT8 volume) +{ + (void)volume; } boolean I_SetSongTrack(int track) diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 24239f822..8af6ec686 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1313,7 +1313,7 @@ void I_StartupSound(void) // MUSIC API. // -musictype_t I_GetMusicType(void) +musictype_t I_MusicType(void) { #ifdef HAVE_MIXER #ifdef HAVE_LIBGME @@ -1448,28 +1448,9 @@ static boolean LoadSong(void *data, size_t lumplength, size_t selectpos) } #endif - -void I_ShutdownMusic(void) -{ -#ifdef HAVE_MIXER - if ((midi_disabled && digital_disabled) || !musicStarted) - return; - - CONS_Printf("%s", M_GetText("I_ShutdownMusic: ")); - - I_UnloadSong(); - I_StopSong(); - Mix_CloseAudio(); -#ifdef MIX_INIT - Mix_Quit(); -#endif - CONS_Printf("%s", M_GetText("shut down\n")); - musicStarted = SDL_FALSE; - if (Msc_Mutex) - SDL_DestroyMutex(Msc_Mutex); - Msc_Mutex = NULL; -#endif -} +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ void I_InitMusic(void) { @@ -1584,11 +1565,106 @@ void I_InitMusic(void) #endif } -boolean I_PlaySong(INT32 handle, boolean looping) +void I_ShutdownMusic(void) { - (void)handle; #ifdef HAVE_MIXER - if (midi_disabled || !musicStarted || !music[handle]) + if ((midi_disabled && digital_disabled) || !musicStarted) + return; + + CONS_Printf("%s", M_GetText("I_ShutdownMusic: ")); + + I_UnloadSong(); + I_StopSong(); + Mix_CloseAudio(); +#ifdef MIX_INIT + Mix_Quit(); +#endif + CONS_Printf("%s", M_GetText("shut down\n")); + musicStarted = SDL_FALSE; + if (Msc_Mutex) + SDL_DestroyMutex(Msc_Mutex); + Msc_Mutex = NULL; +#endif +} + +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ + +musictype_t I_MusicType(void) +{ + return MU_NONE; +} + +boolean I_MusicPlaying(void) +{ + return false; +} + +boolean I_MusicPaused(void) +{ + return false; +} + +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ + +boolean I_SetSongSpeed(float speed) +{ + (void)speed; + return false; +} + +/// ------------------------ +// MUSIC PLAYBACK +// \todo Merge Digital and MIDI +/// ------------------------ + +boolean I_LoadSong(char *data, size_t len) +{ +#ifdef HAVE_MIXER + if (midi_disabled || !musicStarted) + return false; + + if (!LoadSong(data, len, 0)) + return false; + + if (music[0]) + return true; + + CONS_Printf(M_GetText("Couldn't load MIDI: %s\n"), Mix_GetError()); +#else + (void)len; + (void)data; +#endif + return false; +} + +void I_UnloadSong(void) +{ +#ifdef HAVE_MIXER + + if (midi_disabled || !musicStarted) + return; + + Mix_HaltMusic(); + while (Mix_PlayingMusic()) + ; + + if (music[handle]) + Mix_FreeMusic(music[handle]); + music[handle] = NULL; + LoadSong(NULL, 0, handle); +#else + (void)handle; +#endif +} + +boolean I_PlaySong(boolean looping) +{ +#ifdef HAVE_MIXER + if (!musicStarted || !music[handle]) return false; #ifdef MIXER_POS @@ -1609,6 +1685,28 @@ boolean I_PlaySong(INT32 handle, boolean looping) return false; } +void I_StopSong(void) +{ + I_StopGME(); +#ifdef HAVE_MIXER + if (digital_disabled) + return; + +#ifdef MIXER_POS + if (canlooping) + Mix_HookMusicFinished(NULL); +#endif + + Mix_HaltMusic(); + while (Mix_PlayingMusic()) + ; + + if (music[1]) + Mix_FreeMusic(music[1]); + music[1] = NULL; + LoadSong(NULL, 0, 1); +} + static void I_PauseGME(void) { #ifdef HAVE_LIBGME @@ -1650,68 +1748,6 @@ void I_ResumeSong(void) #endif } -void I_StopSong(void) -{ - I_StopGME(); -#ifdef HAVE_MIXER - if (digital_disabled) - return; - -#ifdef MIXER_POS - if (canlooping) - Mix_HookMusicFinished(NULL); -#endif - - Mix_HaltMusic(); - while (Mix_PlayingMusic()) - ; - - if (music[1]) - Mix_FreeMusic(music[1]); - music[1] = NULL; - LoadSong(NULL, 0, 1); -} - -void I_UnloadSong(void) -{ -#ifdef HAVE_MIXER - - if (midi_disabled || !musicStarted) - return; - - Mix_HaltMusic(); - while (Mix_PlayingMusic()) - ; - - if (music[handle]) - Mix_FreeMusic(music[handle]); - music[handle] = NULL; - LoadSong(NULL, 0, handle); -#else - (void)handle; -#endif -} - -boolean I_LoadSong(char *data, size_t len) -{ -#ifdef HAVE_MIXER - if (midi_disabled || !musicStarted) - return false; - - if (!LoadSong(data, len, 0)) - return false; - - if (music[0]) - return true; - - CONS_Printf(M_GetText("Couldn't load MIDI: %s\n"), Mix_GetError()); -#else - (void)len; - (void)data; -#endif - return false; -} - void I_SetMusicVolume(UINT8 volume) { #ifdef HAVE_MIXER @@ -1727,6 +1763,18 @@ void I_SetMusicVolume(UINT8 volume) #endif } +boolean I_SetSongTrack(int track) +{ + (void)track; + return false; +} + +/// ------------------------ +// MUSIC LOADING AND CLEANUP +// \todo Split logic between loading and playing, +// then move to Playback section +/// ------------------------ + #ifdef HAVE_LIBGME static void I_CleanupGME(void *userdata) { @@ -1961,19 +2009,6 @@ static void I_StopGME(void) #endif } -boolean I_SetSongSpeed(float speed) -{ - - (void)speed; - return false; -} - -boolean I_SetSongTrack(int track) -{ - (void)track; - return false; -} - #ifdef MIXER_POS static void SDLCALL I_FinishMusic(void) { diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index d69562d41..3dbe6c572 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -439,11 +439,24 @@ void I_SetSfxVolume(UINT8 volume) sfx_volume = volume; } -// -// MUSIC -// +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ -musictype_t I_GetMusicType(void) +void I_InitMusic(void) +{ +} + +void I_ShutdownMusic(void) +{ + I_StopSong(); +} + +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ + +musictype_t I_MusicType(void) { #ifdef HAVE_LIBGME if (gme) @@ -491,28 +504,46 @@ boolean I_MusicPaused(void) return fmpaused; } -void I_InitMusic(void) +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ + +boolean I_SetSongSpeed(float speed) { + FMOD_RESULT e; + float frequency; + if (!music_stream) + return false; + if (speed > 250.0f) + speed = 250.0f; //limit speed up to 250x + +#ifdef HAVE_LIBGME + // Try to set GME speed + if (gme) + { + gme_set_tempo(gme, speed); + return true; + } +#endif + + // Try to set Mod/Midi speed + e = FMOD_Sound_SetMusicSpeed(music_stream, speed); + + if (e == FMOD_ERR_FORMAT) + { + // Just change pitch instead for Ogg/etc. + FMR(FMOD_Sound_GetDefaults(music_stream, &frequency, NULL, NULL, NULL)); + FMR_MUSIC(FMOD_Channel_SetFrequency(music_channel, speed*frequency)); + } + else + FMR_MUSIC(e); + + return true; } -void I_ShutdownMusic(void) -{ - I_StopSong(); -} - -void I_PauseSong(void) -{ - UNREFERENCED_PARAMETER(handle); - if (music_stream) - FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, true)); -} - -void I_ResumeSong(void) -{ - UNREFERENCED_PARAMETER(handle); - if (music_stream) - FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, false)); -} +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ boolean I_LoadSong(char *data, size_t len) { @@ -726,39 +757,79 @@ boolean I_LoadSong(char *data, size_t len) return true; } -boolean I_SetSongSpeed(float speed) +void I_UnloadSong(void) { - FMOD_RESULT e; - float frequency; - if (!music_stream) - return false; - if (speed > 250.0f) - speed = 250.0f; //limit speed up to 250x + UNREFERENCED_PARAMETER(handle); + if (music_stream) + FMR(FMOD_Sound_Release(music_stream)); + music_stream = NULL; +} +boolean I_PlaySong(boolean looping) +{ #ifdef HAVE_LIBGME - // Try to set GME speed if (gme) { - gme_set_tempo(gme, speed); + gme_start_track(gme, 0); + current_track = 0; + FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); + FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); + FMR(FMOD_Channel_SetPriority(music_channel, 0)); return true; } #endif - // Try to set Mod/Midi speed - e = FMOD_Sound_SetMusicSpeed(music_stream, speed); - - if (e == FMOD_ERR_FORMAT) - { - // Just change pitch instead for Ogg/etc. - FMR(FMOD_Sound_GetDefaults(music_stream, &frequency, NULL, NULL, NULL)); - FMR_MUSIC(FMOD_Channel_SetFrequency(music_channel, speed*frequency)); - } + FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); + if (I_MusicType() != MU_MID) + FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); else - FMR_MUSIC(e); + FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); + FMR(FMOD_Channel_SetPriority(music_channel, 0)); + current_track = 0; return true; } +void I_StopSong(void) +{ +#ifdef HAVE_LIBGME + if (gme) + gme_delete(gme); + gme = NULL; +#endif + current_track = -1; + + I_UnloadSong(); +} + +void I_PauseSong(void) +{ + UNREFERENCED_PARAMETER(handle); + if (music_stream) + FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, true)); +} + +void I_ResumeSong(void) +{ + UNREFERENCED_PARAMETER(handle); + if (music_stream) + FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, false)); +} + +void I_SetMusicVolume(UINT8 volume) +{ + if (!music_stream) + return; + + // volume is 0 to 31. + if (I_MusicType() == MU_MID) + music_volume = 31; // windows bug hack + else + music_volume = volume; + + FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); +} + boolean I_SetSongTrack(INT32 track) { if (track != current_track) // If the track's already playing, then why bother? @@ -803,66 +874,3 @@ boolean I_SetSongTrack(INT32 track) } return false; } - -// -// Fuck MIDI. ... Okay fine, you can have your silly D_-only mode. -// - -void I_SetMusicVolume(UINT8 volume) -{ - if (!music_stream) - return; - - // volume is 0 to 31. - if (I_GetMusicType() == MU_MID) - music_volume = 31; // windows bug hack - else - music_volume = volume; - - FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); -} - -boolean I_PlaySong(boolean looping) -{ -#ifdef HAVE_LIBGME - if (gme) - { - gme_start_track(gme, 0); - current_track = 0; - FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); - FMR(FMOD_Channel_SetPriority(music_channel, 0)); - return true; - } -#endif - - FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - if (I_GetMusicType() != MU_MID) - FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); - else - FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); - FMR(FMOD_Channel_SetPriority(music_channel, 0)); - current_track = 0; - - return true; -} - -void I_StopSong(void) -{ -#ifdef HAVE_LIBGME - if (gme) - gme_delete(gme); - gme = NULL; -#endif - current_track = -1; - - I_UnloadSong(); -} - -void I_UnloadSong(void) -{ - UNREFERENCED_PARAMETER(handle); - if (music_stream) - FMR(FMOD_Sound_Release(music_stream)); - music_stream = NULL; -} From 4b82de9e540d6dc0651bbe8db8e5e15cba39f650 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 20:14:46 -0400 Subject: [PATCH 23/30] Refactor I_MusicType MusicPlaying and MusicPaused -> I_SongType ... --- src/i_sound.h | 6 +++--- src/s_sound.c | 18 +++++++++--------- src/sdl/mixer_sound.c | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 7959b9a51..cbbc0b280 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -136,9 +136,9 @@ void I_ShutdownMusic(void); // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void); -boolean I_MusicPlaying(void); -boolean I_MusicPaused(void); +musictype_t I_SongType(void); +boolean I_SongPlaying(void); +boolean I_SongPaused(void); /// ------------------------ // MUSIC EFFECTS diff --git a/src/s_sound.c b/src/s_sound.c index 2d45a363b..78e3b345e 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1371,22 +1371,22 @@ boolean S_MusicDisabled(void) boolean S_MusicPlaying(void) { - return I_MusicPlaying(); + return I_SongPlaying(); } boolean S_MusicPaused(void) { - return I_MusicPaused(); + return I_SongPaused(); } musictype_t S_MusicType(void) { - return I_MusicType(); + return I_SongType(); } boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping) { - if (!I_MusicPlaying()) + if (!I_SongPlaying()) return false; strncpy(mname, music_name, 7); @@ -1515,10 +1515,10 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) void S_StopMusic(void) { - if (!I_MusicPlaying()) + if (!I_SongPlaying()) return; - if (I_MusicPaused()) + if (I_SongPaused()) I_ResumeSong(); S_SpeedMusic(1.0f); @@ -1543,7 +1543,7 @@ void S_StopMusic(void) // void S_PauseAudio(void) { - if (I_MusicPlaying() && !I_MusicPaused()) + if (I_SongPlaying() && !I_SongPaused()) I_PauseSong(); // pause cd music @@ -1556,7 +1556,7 @@ void S_PauseAudio(void) void S_ResumeAudio(void) { - if (I_MusicPlaying() && I_MusicPaused()) + if (I_SongPlaying() && I_SongPaused()) I_ResumeSong(); // resume cd music @@ -1584,7 +1584,7 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) digvolume = seqvolume = 31; #endif - switch(I_MusicType()) + switch(I_SongType()) { case MU_MID: case MU_MOD: diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 97341d5ad..7edf095ba 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -503,7 +503,7 @@ void I_ShutdownMusic(void) /// Music Properties /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { #ifdef HAVE_LIBGME if (gme) @@ -522,12 +522,12 @@ musictype_t I_MusicType(void) return (musictype_t)Mix_GetMusicType(music); } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return (boolean)music; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { return songpaused; } @@ -772,7 +772,7 @@ void I_SetMusicVolume(UINT8 volume) return; #ifdef _WIN32 - if (I_MusicType() == MU_MID) + if (I_SongType() == MU_MID) // HACK: Until we stop using native MIDI, // disable volume changes music_volume = 31; From 9e6eebeb8d6b4119d87e9678bb6b0687e3dc5217 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 20:14:56 -0400 Subject: [PATCH 24/30] Refactor I_MusicType MusicPlaying and MusicPaused other targets --- src/android/i_sound.c | 6 +++--- src/djgppdos/i_sound.c | 6 +++--- src/dummy/i_sound.c | 6 +++--- src/sdl/mixer_sound.c | 4 ++-- src/sdl/sdl_sound.c | 12 ++++++------ src/win32/win_snd.c | 10 +++++----- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index bf54c9ff0..1d16e4df3 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -70,17 +70,17 @@ void I_ShutdownMusic(void){} // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { return MU_NONE; } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return false; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { return false; } diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 339b469d3..5403aef17 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -408,7 +408,7 @@ void I_ShutdownMusic(void) // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { if (currsong) return MU_MID; @@ -416,12 +416,12 @@ musictype_t I_MusicType(void) return MU_NONE; } -boolean I_MusicPlaying() +boolean I_SongPlaying() { return (boolean)currsong; } -boolean I_MusicPaused() +boolean I_SongPaused() { return songpaused; } diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index cab64e692..e08d59d76 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -69,17 +69,17 @@ void I_ShutdownMusic(void){} // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { return MU_NONE; } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return false; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { return false; } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 7edf095ba..7fb72ac15 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -63,7 +63,7 @@ UINT8 sound_started = false; static Mix_Music *music; -static UINT8 music_volume, midi_volume, sfx_volume; +static UINT8 music_volume, sfx_volume; static float loop_point; static boolean songpaused; @@ -91,7 +91,7 @@ void I_StartupSound(void) } music = NULL; - music_volume = midi_volume = sfx_volume = 0; + music_volume = sfx_volume = 0; #if SDL_MIXER_VERSION_ATLEAST(1,2,11) Mix_Init(MIX_INIT_FLAC|MIX_INIT_MOD|MIX_INIT_MP3|MIX_INIT_OGG); diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 8af6ec686..78309091c 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1313,7 +1313,7 @@ void I_StartupSound(void) // MUSIC API. // -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { #ifdef HAVE_MIXER #ifdef HAVE_LIBGME @@ -1336,12 +1336,12 @@ musictype_t I_MusicType(void) #endif } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return music_started; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { return Mix_PausedMusic(); } @@ -1591,17 +1591,17 @@ void I_ShutdownMusic(void) // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { return MU_NONE; } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return false; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { return false; } diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 3dbe6c572..2960ff7d2 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -456,7 +456,7 @@ void I_ShutdownMusic(void) // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { #ifdef HAVE_LIBGME if (gme) @@ -491,12 +491,12 @@ musictype_t I_MusicType(void) return MU_NONE; } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return (boolean)music_stream; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { boolean fmpaused = false; if (music_stream) @@ -780,7 +780,7 @@ boolean I_PlaySong(boolean looping) #endif FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - if (I_MusicType() != MU_MID) + if (I_SongType() != MU_MID) FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); else FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); @@ -822,7 +822,7 @@ void I_SetMusicVolume(UINT8 volume) return; // volume is 0 to 31. - if (I_MusicType() == MU_MID) + if (I_SongType() == MU_MID) music_volume = 31; // windows bug hack else music_volume = volume; From 5f21bf230d9716b7cc5b52e4bf3591ebe01e9f3a Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 13:12:14 -0400 Subject: [PATCH 25/30] GME fix: play song in I_PlaySong, not I_LoadSong --- src/sdl/mixer_sound.c | 8 ++++---- src/win32/win_snd.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 97341d5ad..14601f9b2 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -656,7 +656,6 @@ boolean I_LoadSong(char *data, size_t len) { gme_equalizer_t eq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; gme_set_equalizer(gme, &eq); - Mix_HookMusic(mix_gme, gme); return true; } #endif @@ -712,16 +711,17 @@ void I_UnloadSong(void) boolean I_PlaySong(boolean looping) { - if (!music) - return false; -#ifdef HAVE_GME +#ifdef HAVE_LIBGME if (gme) { gme_start_track(gme, 0); current_track = 0; + Mix_HookMusic(mix_gme, gme); return true; } #endif + else if (!music) + return false; if (Mix_PlayMusic(music, looping && loop_point == 0.0f ? -1 : 0) == -1) { diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 3dbe6c572..8059cd9ce 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -675,7 +675,6 @@ boolean I_LoadSong(char *data, size_t len) fmt.decodebuffersize = (44100 * 2) / 35; fmt.pcmreadcallback = GMEReadCallback; fmt.userdata = gme; - FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); return true; } #endif @@ -772,6 +771,7 @@ boolean I_PlaySong(boolean looping) { gme_start_track(gme, 0); current_track = 0; + FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); FMR(FMOD_Channel_SetPriority(music_channel, 0)); From fb6f8c8a0752c229f5b7369729437c8fecb54d45 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 13:41:26 -0400 Subject: [PATCH 26/30] A word --- src/sdl/mixer_sound.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index ccd743519..2e5735ef9 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -719,8 +719,9 @@ boolean I_PlaySong(boolean looping) Mix_HookMusic(mix_gme, gme); return true; } + else #endif - else if (!music) + if (!music) return false; if (Mix_PlayMusic(music, looping && loop_point == 0.0f ? -1 : 0) == -1) From d39b7011c5b12e5b7abe3e493971e003469a1f3d Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 18:01:57 -0400 Subject: [PATCH 27/30] Volume fixes # Conflicts: # src/sdl/mixer_sound.c --- src/s_sound.c | 6 ++++-- src/sdl/mixer_sound.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 78e3b345e..e5285c321 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1587,11 +1587,13 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) switch(I_SongType()) { case MU_MID: - case MU_MOD: - case MU_GME: + //case MU_MOD: + //case MU_GME: I_SetMusicVolume(seqvolume&31); + break; default: I_SetMusicVolume(digvolume&31); + break; } } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 2e5735ef9..c5eb985fa 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -769,7 +769,7 @@ void I_ResumeSong(void) void I_SetMusicVolume(UINT8 volume) { - if (!music) + if (!I_SongPlaying()) return; #ifdef _WIN32 From eae5d3333f5001512c82f22f2b1433a955b3a6c3 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 18:02:46 -0400 Subject: [PATCH 28/30] Stub I_UnloadSong because we already unload in I_StopMusic * Stop-gap for now. Ideally the logic would be in the respective places. # Conflicts: # src/sdl/mixer_sound.c --- src/sdl/mixer_sound.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index c5eb985fa..b57a86819 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -705,8 +705,11 @@ boolean I_LoadSong(char *data, size_t len) void I_UnloadSong(void) { - Mix_FreeMusic(music); - music = NULL; + // \todo unhook looper + //var_cleanup(); + //Mix_FreeMusic(music); + //music = NULL; + I_StopSong(); } boolean I_PlaySong(boolean looping) From e88d1477616ca66472ecb50d371e37dc79c77c0f Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 18:00:18 -0400 Subject: [PATCH 29/30] I_SongPlaying detect GME properly --- src/sdl/mixer_sound.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index b57a86819..a0eec4460 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -524,7 +524,12 @@ musictype_t I_SongType(void) boolean I_SongPlaying(void) { - return (boolean)music; + return ( +#ifdef HAVE_LIBGME + (I_SongType() == MU_GME && gme) || +#endif + (boolean)music + ); } boolean I_SongPaused(void) From a7ae059949b320723727aea4468a370bc63c3910 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sat, 25 Aug 2018 21:42:39 -0400 Subject: [PATCH 30/30] Case-insensitive music_name comparison --- src/s_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index e5285c321..56f6b46c4 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1494,7 +1494,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) return; } - if (strncmp(music_name, mmusic, 6)) + if (strnicmp(music_name, newmusic, 6)) { S_StopMusic(); // shutdown old music