From b59aa2710433ca89744f4f9a91eb1e0dba727c6f Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 09:37:02 -0400 Subject: [PATCH 01/34] Loose ends other targets (cherry picked from commit 9a5fc5f66a31baf713c6f32f7a696b933da6907b) --- src/android/i_sound.c | 22 ++++----- src/djgppdos/i_sound.c | 28 +---------- src/dummy/i_sound.c | 15 ++---- src/sdl/sdl_sound.c | 6 +-- src/win32/win_main.c | 4 +- src/win32/win_snd.c | 106 +++++++++++++++++++++-------------------- 6 files changed, 74 insertions(+), 107 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index ecf96f2f0..1011dbb6a 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,23 +80,19 @@ void I_ResumeSong(INT32 handle) UINT8 midimusic_started = 0; -void I_InitMIDIMusic(void){} - -void I_ShutdownMIDIMusic(void){} - -void I_SetMIDIMusicVolume(INT32 volume) -{ - (void)volume; -} - -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(char *data, size_t len) { (void)data; (void)len; return -1; } -boolean I_PlaySong(INT32 handle, INT32 looping) +void I_SetMIDIMusicVolume(INT32 volume) +{ + (void)volume; +} + +boolean I_PlaySong(boolean looping) { (void)handle; (void)looping; diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 88fc807f4..105e8d67a 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -408,31 +408,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(boolean looping) { handle = 0; if (nomidimusic) @@ -495,7 +471,7 @@ void I_UnRegisterSong(INT32 handle) //destroy_midi(currsong); } -INT32 I_RegisterSong(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 51dbb610d..2f6f0001c 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -70,7 +70,7 @@ void I_PauseSong(INT32 handle) (void)handle; } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { (void)handle; } @@ -79,23 +79,14 @@ void I_ResumeSong(INT32 handle) // MIDI I/O // -void I_InitMIDIMusic(void){} - -void I_ShutdownMIDIMusic(void){} - -void I_SetMIDIMusicVolume(UINT8 volume) -{ - (void)volume; -} - -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(char *data, size_t len) { (void)data; (void)len; return -1; } -boolean I_PlaySong(INT32 handle, boolean looping) +boolean I_PlaySong(boolean looping) { (void)handle; (void)looping; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 6c70c163b..c714f675b 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1605,7 +1605,7 @@ static void I_PauseGME(void) #endif } -void I_PauseSong(INT32 handle) +void I_PauseSong(void) { (void)handle; I_PauseGME(); @@ -1625,7 +1625,7 @@ static void I_ResumeGME(void) #endif } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { (void)handle; I_ResumeGME(); @@ -1669,7 +1669,7 @@ void I_UnRegisterSong(INT32 handle) #endif } -INT32 I_RegisterSong(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 f168f1fe3..18c88d267 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -456,14 +456,14 @@ void I_ShutdownMusic(void) I_ShutdownMIDIMusic(); } -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) @@ -644,60 +644,64 @@ boolean I_StartDigSong(const char *musicname, boolean looping) current_track = 0; // 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; - } - - // 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, but we're playing so it's all good. @@ -825,7 +829,7 @@ void I_SetMIDIMusicVolume(UINT8 volume) FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); } -INT32 I_RegisterSong(void *data, size_t len) +boolean I_PlaySong(boolean looping) { FMOD_CREATESOUNDEXINFO fmt; memset(&fmt, 0, sizeof(FMOD_CREATESOUNDEXINFO)); From 06b73679414f3c52755ee407833b0d965f0ab761 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 10:18:38 -0400 Subject: [PATCH 02/34] Added I_GetMusicType and removed midimode variable * Revised S_PlayMusic arguments * Now music plays again! (cherry picked from commit 55f3803e4b9f8104c90cc6c769d54121e5bac0b8) --- src/i_sound.h | 18 +++++++++++++++ src/s_sound.c | 16 +++++++------ src/sdl/mixer_sound.c | 54 +++++++++++++++++++++++++++++++++---------- 3 files changed, 69 insertions(+), 19 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 084479ee1..0fe62d5eb 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 76ee4c649..279f0dc6d 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1227,7 +1227,7 @@ static boolean S_MIDIMusic(const char *mname, boolean looping) return true; } -static boolean S_DigMusic(const char *mname, boolean looping) +static boolean S_PlayMusic(boolean looping) { if (nodigimusic || digital_disabled) return false; // try midi @@ -1235,11 +1235,6 @@ static boolean S_DigMusic(const char *mname, boolean looping) if (!I_StartDigSong(mname, looping)) return false; - strncpy(music_name, mname, 7); - music_name[6] = 0; - music_lumpnum = LUMPERROR; - music_data = NULL; - music_handle = 0; return true; } @@ -1262,11 +1257,18 @@ 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)) { 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 5211efe0a..0888d5d31 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) { @@ -470,8 +487,19 @@ FUNCMATH void I_InitMusic(void) void I_ShutdownMusic(void) { - I_ShutdownDigMusic(); - I_ShutdownMIDIMusic(); +#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,7 +520,15 @@ void I_ResumeSong(INT32 handle) // Digital Music // -void I_InitDigMusic(void) +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) { #ifdef HAVE_LIBGME gme = NULL; @@ -691,8 +727,6 @@ boolean I_StartDigSong(const char *musicname, boolean looping) void I_StopDigSong(void) { - if (midimode) - return; #ifdef HAVE_LIBGME if (gme) { @@ -791,7 +825,7 @@ 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); } @@ -834,10 +868,6 @@ void I_StopSong(INT32 handle) void I_UnRegisterSong(INT32 handle) { - if (!midimode || !music) - return; - - (void)handle; Mix_FreeMusic(music); music = NULL; } From 46b53e8baeede0df6c75d93697301a027aeb8a70 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 10:19:04 -0400 Subject: [PATCH 03/34] Added I_GetMusicType and removed midimode variable: other targets (cherry picked from commit 14b393ab16736bb44dab6fd4a90b7bdd8ff782e0) --- src/android/i_sound.c | 24 ++---- src/djgppdos/i_sound.c | 33 ++++----- src/dummy/i_sound.c | 31 ++++---- src/sdl/sdl_sound.c | 98 +++++++++++-------------- src/win32/win_snd.c | 162 +++++++++++++++++++---------------------- 5 files changed, 155 insertions(+), 193 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 1011dbb6a..c3fc038e5 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){} @@ -99,12 +104,12 @@ boolean I_PlaySong(boolean 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; } @@ -115,19 +120,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; @@ -137,4 +129,4 @@ boolean I_SetSongSpeed(float speed) { (void)speed; return false; -} +} \ No newline at end of file diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 105e8d67a..4c8ceb20c 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 @@ -389,7 +396,7 @@ static MIDI *load_midi_mem(char *mempointer,int *e) return midi; } -void I_InitMIDIMusic(void) +void I_InitMusic(void) { if (nomidimusic) return; @@ -398,12 +405,12 @@ void I_InitMIDIMusic(void) music_started = true; } -void I_ShutdownMIDIMusic(void) +void I_ShutdownMusic(void) { if ( !music_started ) return; - I_StopSong(1); + I_StopSong(); music_started=false; } @@ -439,7 +446,7 @@ void I_ResumeSong (INT32 handle) midi_resume(); } -void I_StopSong(INT32 handle) +void I_StopSong(void) { handle = 0; if (nomidimusic) @@ -462,7 +469,7 @@ int I_QrySongPlaying(int handle) } #endif -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { handle = 0; if (nomidimusic) @@ -496,20 +503,6 @@ boolean I_LoadSong(char *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; @@ -524,4 +517,4 @@ boolean I_SetSongSpeed(float speed) { (void)speed; return false; -} +} \ No newline at end of file diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 2f6f0001c..60cf51f73 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -61,11 +61,21 @@ void I_SetSfxVolume(UINT8 volume) // MUSIC I/O // +musictype_t I_GetMusicType(void) +{ + return MU_NONE; +} + void I_InitMusic(void){} void I_ShutdownMusic(void){} -void I_PauseSong(INT32 handle) +void I_SetMIDIMusicVolume(UINT8 volume) +{ + (void)volume; +} + +void I_PauseSong(void) { (void)handle; } @@ -93,12 +103,12 @@ boolean I_PlaySong(boolean 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; } @@ -107,19 +117,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; @@ -135,4 +132,4 @@ boolean I_SetSongTrack(int track) { (void)track; return false; -} +} \ No newline at end of file diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index c714f675b..b729d4d89 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1313,10 +1313,27 @@ void I_StartupSound(void) // MUSIC API. // -void I_ShutdownMIDIMusic(void) +musictype_t I_GetMusicType(void) { - nomidimusic = false; - if (nodigimusic) I_ShutdownMusic(); +#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 @@ -1330,12 +1347,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 +1447,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 +1461,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 +1640,29 @@ void I_ResumeSong(void) #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 @@ -1714,7 +1727,7 @@ static void I_CleanupGME(void *userdata) static boolean I_StartGMESong(const char *musicname, boolean looping) { #ifdef HAVE_LIBGME - XBOXSTATIC char filename[9]; + char filename[9]; void *data; lumpnum_t lumpnum; size_t lumplength; @@ -1769,7 +1782,7 @@ static boolean I_StartGMESong(const char *musicname, boolean looping) boolean I_StartDigSong(const char *musicname, boolean looping) { #ifdef HAVE_MIXER - XBOXSTATIC char filename[9]; + char filename[9]; void *data; lumpnum_t lumpnum; size_t lumplength; @@ -1786,7 +1799,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) lumpnum = W_CheckNumForName(filename); - I_StopDigSong(); + I_StopSong(); if (lumpnum == LUMPERROR) { @@ -1811,7 +1824,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) { size_t scan; const char *dataum = data; - XBOXSTATIC char looplength[64]; + char looplength[64]; UINT32 loopstart = 0; UINT8 newcount = 0; @@ -1938,29 +1951,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) { I_SetMIDIMusicVolume(volume); @@ -1995,4 +1985,4 @@ static void SDLCALL I_FinishMusic(void) if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); } #endif -#endif //HAVE_SDL +#endif //HAVE_SDL \ No newline at end of file diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 18c88d267..295d68680 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -22,12 +22,10 @@ #define HAVE_ZLIB #ifndef _MSC_VER -#ifndef _WII #ifndef _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE #endif #endif -#endif #ifndef _LFS64_LARGEFILE #define _LFS64_LARGEFILE @@ -44,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; @@ -446,14 +443,48 @@ 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) { } void I_ShutdownMusic(void) { - I_ShutdownDigMusic(); - I_ShutdownMIDIMusic(); + I_StopSong(); } void I_PauseSong(void) @@ -470,17 +501,7 @@ void I_ResumeSong(void) 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; @@ -492,10 +513,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) 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); @@ -605,8 +623,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; @@ -616,32 +632,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) FMOD_RESULT e; @@ -704,28 +709,15 @@ boolean I_StartDigSong(const char *musicname, boolean looping) return true; } - // 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. music_volume = volume; - if (!midimode && music_stream) + if (I_GetMusicType() != MU_MID && music_stream) FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); } @@ -811,57 +803,55 @@ boolean I_SetSongTrack(INT32 track) // Fuck MIDI. ... Okay fine, you can have your silly D_-only mode. // -void I_InitMIDIMusic(void) -{ -} - -void I_ShutdownMIDIMusic(void) -{ - if (midimode) - I_StopSong(0); -} - 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)); } boolean I_PlaySong(boolean looping) { - 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 (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(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) FMR(FMOD_Sound_Release(music_stream)); music_stream = NULL; -} +} \ No newline at end of file From a7ed7b2c90e5dcc2b342adca4227a33a1432d38d Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 11:51:23 -0400 Subject: [PATCH 04/34] 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 (cherry picked from commit 701cc5a7dd1dfead87a42ec7558c9fa6a1deb193) --- src/d_netcmd.c | 4 +- src/i_sound.h | 47 ++----- src/s_sound.c | 161 +++++++++++++++-------- src/s_sound.h | 28 +++- src/sdl/mixer_sound.c | 298 +++++++++++++++--------------------------- 5 files changed, 242 insertions(+), 296 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index bf26ca61a..ab3201c5c 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3963,11 +3963,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 0fe62d5eb..1d4d6ff72 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -140,7 +140,7 @@ void I_ShutdownMusic(void); \return void */ -void I_PauseSong(INT32 handle); +void I_PauseSong(void); /** \brief RESUME game handling @@ -148,20 +148,12 @@ void I_PauseSong(INT32 handle); \return void */ -void I_ResumeSong(INT32 handle); +void I_ResumeSong(void); // // MIDI I/O // -/** \brief Startup the MIDI music system -*/ -void I_InitMIDIMusic(void); - -/** \brief Shutdown the MIDI music system -*/ -void I_ShutdownMIDIMusic(void); - /** \brief The I_SetMIDIMusicVolume function \param volume volume to set at @@ -179,7 +171,7 @@ void I_SetMIDIMusicVolume(UINT8 volume); \todo Remove this */ -INT32 I_RegisterSong(void *data, size_t len); +boolean I_LoadSong(char *data, size_t len); /** \brief Called by anything that wishes to start music @@ -190,7 +182,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(boolean looping); /** \brief Stops a song over 3 seconds @@ -199,46 +191,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 @@ -297,4 +268,4 @@ void I_PlayCD(UINT8 track, UINT8 looping); */ boolean I_SetVolumeCD(INT32 volume); -#endif +#endif \ No newline at end of file diff --git a/src/s_sound.c b/src/s_sound.c index 279f0dc6d..a1c53acd2 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1180,28 +1180,71 @@ 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_paused = 0; // whether songs are mus_paused +/// ------------------------ +/// Music Status +/// ------------------------ -static boolean S_MIDIMusic(const char *mname, boolean looping) +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; - INT32 mhandle; - if (nomidimusic || music_disabled) - return false; // didn't search. - - if (W_CheckNumForName(va("d_%s", mname)) == LUMPERROR) + if (S_MusicDisabled()) return false; - mlumpnum = W_GetNumForName(va("d_%s", mname)); + + if (S_DigMusicDisabled()) + { + 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) @@ -1215,16 +1258,20 @@ static boolean S_MIDIMusic(const char *mname, boolean looping) } #endif - // play it - if (!I_PlaySong(mhandle, looping)) + if (I_LoadSong(mdata, W_LumpLength(mlumpnum))) + { + strncpy(music_name, mname, 7); + music_name[6] = 0; + return true; + } + else return false; +} - strncpy(music_name, mname, 7); - music_name[6] = 0; - music_lumpnum = mlumpnum; - music_data = mdata; - music_handle = mhandle; - return true; +static void S_UnloadMusic(void) +{ + I_UnloadSong(); + music_name[0] = 0; } static boolean S_PlayMusic(boolean looping) @@ -1232,9 +1279,13 @@ static boolean S_PlayMusic(boolean looping) if (nodigimusic || digital_disabled) return false; // try midi - if (!I_StartDigSong(mname, looping)) + if (!I_PlaySong(looping)) + { + S_UnloadMusic(); return false; + } + S_InitMusicVolume(); // switch between digi and sequence volume return true; } @@ -1244,7 +1295,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) S_ClearSfx(); #endif - if ((nomidimusic || music_disabled) && (nodigimusic || digital_disabled)) + if (S_MusicDisabled()) return; // No Music (empty string) @@ -1273,60 +1324,55 @@ 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) return; if (mus_paused) - I_ResumeSong(music_handle); - - if (!nodigimusic) - I_StopDigSong(); + I_ResumeSong(); 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); #endif - music_data = NULL; music_name[0] = 0; } -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); + } } /// ------------------------ @@ -1346,8 +1392,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(); @@ -1403,11 +1448,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; } @@ -1422,11 +1467,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/s_sound.h b/src/s_sound.h index 39ec769a6..bce3ab8bb 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -97,6 +97,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 @@ -104,9 +123,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); @@ -121,9 +137,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 0888d5d31..457f74f95 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -483,6 +483,10 @@ 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) @@ -502,16 +506,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; } @@ -520,59 +522,66 @@ void I_ResumeSong(INT32 handle) // 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) { -#ifdef HAVE_LIBGME - gme = NULL; - current_track = -1; -#endif -} - -void I_ShutdownDigMusic(void) -{ - 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(char *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) @@ -663,8 +672,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; @@ -675,48 +682,62 @@ 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. 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(boolean looping) +{ + if (!music) + return false; +#ifdef HAVE_GME + if (gme) + { + gme_start_track(gme, 0); + current_track = 0; + 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); @@ -725,7 +746,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) return true; } -void I_StopDigSong(void) +void I_StopSong(void) { #ifdef HAVE_LIBGME if (gme) @@ -744,132 +765,25 @@ void I_StopDigSong(void) music = NULL; } -void I_SetDigMusicVolume(UINT8 volume) +void I_SetMusicVolume(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; -} - -void I_SetMIDIMusicVolume(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) - 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); 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(); + 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_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { Mix_FreeMusic(music); music = NULL; } -#endif +#endif \ No newline at end of file From e58a8f4fe18609531a5eb06e1d1b302b6cf6c197 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 11:54:58 -0400 Subject: [PATCH 05/34] Consolidate I_SetDigMusicVolume and I_SetMIDIMusicVolume other targets (cherry picked from commit 9fb9386f84b3739fe765a78bcb9683eb7e98bc36) --- 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 c3fc038e5..80b90d2f7 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 4c8ceb20c..e66bf8e23 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 60cf51f73..f82bf00da 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 b729d4d89..5f92cde10 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 295d68680..bfa43d087 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 011a043dbaaa5706be45f3e900a3d2f031239217 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:30:47 -0400 Subject: [PATCH 06/34] 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 (cherry picked from commit f5f0b5e76c2fd405c8cc895dde653c5ed2652622) --- 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 df3398752..f2da8586c 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1217,7 +1217,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; @@ -1232,7 +1232,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 1d4d6ff72..901e6c284 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 79ac6800b..82242c0c1 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6955,7 +6955,7 @@ static void M_ToggleSFX(void) nosound = false; I_StartupSound(); if (nosound) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_InitSfxChannels(cv_soundvolume.value); M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); } else @@ -6981,7 +6981,7 @@ static void M_ToggleDigital(void) nodigimusic = false; I_InitDigMusic(); if (nodigimusic) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_InitSfxChannels(cv_soundvolume.value); S_StopMusic(); S_ChangeMusicInternal("lclear", false); M_StartMessage(M_GetText("Digital Music Enabled\n"), NULL, MM_NOTHING); @@ -7009,7 +7009,7 @@ static void M_ToggleMIDI(void) nomidimusic = false; I_InitMIDIMusic(); if (nomidimusic) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_InitSfxChannels(cv_soundvolume.value); S_ChangeMusicInternal("lclear", false); M_StartMessage(M_GetText("MIDI Music Enabled\n"), NULL, MM_NOTHING); } diff --git a/src/s_sound.c b/src/s_sound.c index a1c53acd2..e035c4192 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1151,6 +1151,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 /// ------------------------ @@ -1177,10 +1214,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 @@ -1206,6 +1240,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 /// ------------------------ @@ -1229,15 +1286,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; @@ -1326,10 +1383,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); @@ -1343,6 +1400,31 @@ void S_StopMusic(void) music_name[0] = 0; } +// +// 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) @@ -1355,7 +1437,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 @@ -1375,52 +1457,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, @@ -1435,46 +1476,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 bce3ab8bb..9a3f2805c 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -69,9 +69,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. @@ -101,9 +101,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 457f74f95..1384f1da0 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 44557d9c9d6b6ea3df722987bf778f847193db90 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:31:01 -0400 Subject: [PATCH 07/34] I_MusicPlaying, I_MusicPaused other targets (cherry picked from commit d5ec38815968e267aceb59a48a6cb6d3292c0b69) --- 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 80b90d2f7..1cbc53fab 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 e66bf8e23..6e351b523 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 f82bf00da..ca90a7da3 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 5f92cde10..d8d3e0a95 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 bfa43d087..c6a74d999 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 a414ccf24ae6b59b1945cb0b9177bfaebbfb334e Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:42:15 -0400 Subject: [PATCH 08/34] nodigimusic nomusic nosound -> digital_disabled midi_disabled sound_disabled (cherry picked from commit 07738fb0bcf640a4349337373f451fe68e024b2a) --- src/d_main.c | 26 ++++++++++----------- src/doomstat.h | 5 +--- src/m_menu.c | 62 ++++++++++++++++++++------------------------------ src/p_mobj.c | 2 +- src/s_sound.c | 27 +++++++++------------- 5 files changed, 51 insertions(+), 71 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index f2da8586c..ed1b44684 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -122,17 +122,17 @@ postimg_t postimgtype2 = postimg_none; INT32 postimgparam2; #ifdef _XBOX -boolean nomidimusic = true, nosound = true; -boolean nodigimusic = true; +boolean midi_disabled = true, sound_disabled = true; +boolean digital_disabled = true; #else -boolean nomidimusic = false, nosound = false; -boolean nodigimusic = false; // No fmod-based music +boolean midi_disabled = false, sound_disabled = false; +boolean digital_disabled = false; // No fmod-based music #endif // These variables are only true if -// the respective sound system is initialized -// and active, but no sounds/music should play. -boolean music_disabled = false; +// 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; @@ -1212,23 +1212,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 8072a1552..27bd3fa19 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -85,10 +85,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 82242c0c1..7a5e78a7b 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6950,11 +6950,11 @@ static void M_ChangeControl(INT32 choice) // Toggles sound systems in-game. static void M_ToggleSFX(void) { - if (nosound) + if (sound_disabled) { - nosound = false; + sound_disabled = false; I_StartupSound(); - if (nosound) return; + if (sound_disabled) return; S_InitSfxChannels(cv_soundvolume.value); M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); } @@ -6976,56 +6976,44 @@ static void M_ToggleSFX(void) static void M_ToggleDigital(void) { - if (nodigimusic) + if (digital_disabled) { - nodigimusic = false; - I_InitDigMusic(); - if (nodigimusic) return; - S_InitSfxChannels(cv_soundvolume.value); + digital_disabled = false; + I_InitMusic(); + if (digital_disabled) return; S_StopMusic(); - S_ChangeMusicInternal("lclear", false); + if (Playing()) + P_RestoreMusic(&players[consoleplayer]); + else + S_ChangeMusicInternal("lclear", false); M_StartMessage(M_GetText("Digital Music Enabled\n"), NULL, MM_NOTHING); } else { - if (digital_disabled) - { - digital_disabled = 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); } } static void M_ToggleMIDI(void) { - if (nomidimusic) + if (midi_disabled) { - nomidimusic = false; - I_InitMIDIMusic(); - if (nomidimusic) return; - S_InitSfxChannels(cv_soundvolume.value); - S_ChangeMusicInternal("lclear", false); + midi_disabled = false; + I_InitMusic(); + if (midi_disabled) return; + if (Playing()) + P_RestoreMusic(&players[consoleplayer]); + else + S_ChangeMusicInternal("lclear", false); M_StartMessage(M_GetText("MIDI Music Enabled\n"), NULL, MM_NOTHING); } else { - if (music_disabled) - { - music_disabled = 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 5f85474c6..a55e5de26 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -8228,7 +8228,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 e035c4192..d1993bc87 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -226,7 +226,7 @@ void S_RegisterSoundStuff(void) { if (dedicated) { - nosound = true; + sound_disabled = true; return; } @@ -400,7 +400,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... @@ -716,7 +716,7 @@ void S_UpdateSounds(void) return; } - if (dedicated || nosound) + if (dedicated || sound_disabled) return; if (players[displayplayer].awayviewtics) @@ -1175,7 +1175,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... ")); @@ -1220,24 +1220,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) @@ -1333,7 +1328,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 17cf310b84ebeaa096b2172f55bb9a2fb5494e08 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:43:38 -0400 Subject: [PATCH 09/34] nodigimusic nomusic nosound refactor other targets (cherry picked from commit 86f151db654beb14e8d6893cdff2adaa965e8e4b) --- 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 6e351b523..d998016a2 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 d8d3e0a95..cf54d7d05 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 7e7899ae831e2203e0cf28b09b8178e66037c554 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:51:45 -0400 Subject: [PATCH 10/34] Toggle Digi/MIDI music in menu accurately; add S_MusicType (cherry picked from commit 4aa100aa575cc7fc14a743085222c806ba2c714a) --- 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 7a5e78a7b..2c82bf84f 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6991,7 +6991,8 @@ static void M_ToggleDigital(void) else { digital_disabled = true; - S_StopMusic(); + if (S_MusicType() != MU_MID) + S_StopMusic(); M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING); } } @@ -7012,7 +7013,8 @@ static void M_ToggleMIDI(void) 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 d1993bc87..54ffffc4c 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1245,6 +1245,11 @@ boolean S_MusicPaused(void) return I_MusicPaused(); } +musictype_t S_MusicType(void) +{ + return I_GetMusicType(); +} + const char *S_MusicName(void) { return music_name; @@ -1279,20 +1284,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 @@ -1328,8 +1337,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)) { @@ -1362,10 +1371,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 9a3f2805c..a0ac6c158 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" @@ -106,6 +107,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 8c78d86c3641675e6c5803afab052cf91055af03 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 16:46:40 -0400 Subject: [PATCH 11/34] Play the opposite type music (Digital/MIDI) when toggling between them in menu * S_MusicInfo method to retrieve name, flags, and looping (cherry picked from commit f6ec93198f0dcfa1d053cca88172c3e3c7ba310c) --- src/m_menu.c | 38 ++++++++++++++++++++++++++++++++++++-- src/s_sound.c | 19 +++++++++++++++++-- src/s_sound.h | 2 +- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 2c82bf84f..6a6875aad 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6992,7 +6992,24 @@ static void M_ToggleDigital(void) { 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); } } @@ -7014,7 +7031,24 @@ static void M_ToggleMIDI(void) { 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 54ffffc4c..32d9c7b06 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1215,6 +1215,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 @@ -1250,9 +1252,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) @@ -1333,6 +1343,8 @@ static void S_UnloadMusic(void) { I_UnloadSong(); music_name[0] = 0; + music_flags = 0; + music_looping = false; } static boolean S_PlayMusic(boolean looping) @@ -1373,6 +1385,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 a0ac6c158..a2d51a59b 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -108,7 +108,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 5bac836d4c805e37c1bf7d9d75cfa23c0933538f Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 17:05:37 -0400 Subject: [PATCH 12/34] Minor refactoring and reordering * I_GetMusicType() -> I_MusicType() * Wrap MIDI volume hack in #ifdef _WIN32 (cherry picked from commit a7d51bf81030c228937a8e759f8f43b85817fce6) --- src/i_sound.h | 89 ++++++++-------- src/s_sound.c | 8 +- src/sdl/mixer_sound.c | 238 +++++++++++++++++++++++------------------- 3 files changed, 174 insertions(+), 161 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 901e6c284..15126d695 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_SetMIDIMusicVolume function - - \param volume volume to set at - - \return void -*/ -void I_SetMIDIMusicVolume(UINT8 volume); +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ /** \brief Registers a song handle to song data. @@ -175,6 +161,15 @@ void I_SetMIDIMusicVolume(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,35 +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 -boolean I_SetSongTrack(INT32 track); + \return void +*/ +void I_ResumeSong(void); -/** \brief The I_SetDigMusicVolume function +/** \brief The I_SetMusicVolume function \param volume volume to set at \return void */ -void I_SetDigMusicVolume(UINT8 volume); +void I_SetMusicVolume(UINT8 volume); -// -// CD MUSIC I/O -// +boolean I_SetSongTrack(INT32 track); +/// ------------------------ +// CD MUSIC I/O +/// ------------------------ /** \brief cd music interface */ diff --git a/src/s_sound.c b/src/s_sound.c index 32d9c7b06..bd6022dfb 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1249,7 +1249,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) @@ -1274,7 +1274,7 @@ boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi) } /// ------------------------ -/// Music Properties +/// Music Effects /// ------------------------ boolean S_SpeedMusic(float speed) @@ -1283,7 +1283,7 @@ boolean S_SpeedMusic(float speed) } /// ------------------------ -/// Music Routines +/// Music Playback /// ------------------------ static boolean S_LoadMusic(const char *mname) @@ -1462,7 +1462,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 1384f1da0..9c46625fc 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 \ No newline at end of file From d535c14fc6b8d5fb25af05075c6804aaae68270c Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 17:05:47 -0400 Subject: [PATCH 13/34] Refactoring and reordering other targets (cherry picked from commit cf065e106f68fb8af3b0568eba188c8235b1656e) --- src/android/i_sound.c | 66 ++++++------ src/djgppdos/i_sound.c | 198 +++++++++++++++++++--------------- src/dummy/i_sound.c | 64 +++++------ src/sdl/sdl_sound.c | 237 +++++++++++++++++++++++------------------ src/win32/win_snd.c | 218 +++++++++++++++++++------------------ 5 files changed, 428 insertions(+), 355 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 1cbc53fab..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; -} \ No newline at end of file + (void)handle; +} + +void I_SetMusicVolume(INT32 volume) +{ + (void)volume; +} diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index d998016a2..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; -} \ No newline at end of file +} + +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 ca90a7da3..fb325c59e 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 cf54d7d05..6a79220c2 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 c6a74d999..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; -} \ No newline at end of file From eacf0ba00bc88eeff112b29fbf18f0a8d6ba2b52 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 20:14:46 -0400 Subject: [PATCH 14/34] Refactor I_MusicType MusicPlaying and MusicPaused -> I_SongType ... (cherry picked from commit 4b82de9e540d6dc0651bbe8db8e5e15cba39f650) --- 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 15126d695..1be970d2e 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 bd6022dfb..723401fb2 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1239,22 +1239,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); @@ -1399,10 +1399,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); @@ -1421,7 +1421,7 @@ void S_StopMusic(void) // void S_PauseAudio(void) { - if (I_MusicPlaying() && !I_MusicPaused()) + if (I_SongPlaying() && !I_SongPaused()) I_PauseSong(); // pause cd music @@ -1434,7 +1434,7 @@ void S_PauseAudio(void) void S_ResumeAudio(void) { - if (I_MusicPlaying() && I_MusicPaused()) + if (I_SongPlaying() && I_SongPaused()) I_ResumeSong(); // resume cd music @@ -1462,7 +1462,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 9c46625fc..521bcd033 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 4d61f00b865033a36af0ad246189345a4fa776f8 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 20:14:56 -0400 Subject: [PATCH 15/34] Refactor I_MusicType MusicPlaying and MusicPaused other targets (cherry picked from commit 9e6eebeb8d6b4119d87e9678bb6b0687e3dc5217) --- 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 fb325c59e..4bace7a41 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 521bcd033..9b84a1247 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 6a79220c2..887726ebb 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 b0c47e2fb12a234a1fa5c41eab54a5b72e734a43 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 13:12:14 -0400 Subject: [PATCH 16/34] GME fix: play song in I_PlaySong, not I_LoadSong (cherry picked from commit 5f21bf230d9716b7cc5b52e4bf3591ebe01e9f3a) --- 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 9b84a1247..ca22724b6 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 2960ff7d2..2e05c4f72 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 2fbe206ecb6c978f088f7398e970ecbad8b4b90b Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 13:41:26 -0400 Subject: [PATCH 17/34] A word (cherry picked from commit fb6f8c8a0752c229f5b7369729437c8fecb54d45) --- 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 ca22724b6..927065924 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 5f22b7d973002eb873551dff56a07a034c564a61 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 18:01:57 -0400 Subject: [PATCH 18/34] Volume fixes # Conflicts: # src/sdl/mixer_sound.c (cherry picked from commit d39b7011c5b12e5b7abe3e493971e003469a1f3d) --- 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 723401fb2..6b632687b 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1465,11 +1465,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 927065924..49905efd7 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 d94f7e3cb095b14bad42dc14e39fc40848ed86ee Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 18:02:46 -0400 Subject: [PATCH 19/34] 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 (cherry picked from commit eae5d3333f5001512c82f22f2b1433a955b3a6c3) --- 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 49905efd7..676bfc4db 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 8541963c613cfaaff38feef1e00b00a0d5c9ddbc Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 18:00:18 -0400 Subject: [PATCH 20/34] I_SongPlaying detect GME properly (cherry picked from commit e88d1477616ca66472ecb50d371e37dc79c77c0f) --- 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 676bfc4db..dd00d78f7 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 fac7d19637dd29e09622493281744fbfaa045dc0 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sat, 25 Aug 2018 21:42:39 -0400 Subject: [PATCH 21/34] Case-insensitive music_name comparison (cherry picked from commit a7ae059949b320723727aea4468a370bc63c3910) --- 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 6b632687b..53b8a9628 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1378,7 +1378,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 From 4b1bc53db13198c4746102cff6a0a90eab2e4d88 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 10:58:41 -0400 Subject: [PATCH 22/34] Compile fixes --- src/d_main.c | 11 ++++------- src/s_sound.c | 2 +- src/sdl/i_video.c | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index ed1b44684..9d2e1bccc 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -121,20 +121,17 @@ INT32 postimgparam; postimg_t postimgtype2 = postimg_none; INT32 postimgparam2; +// These variables are only true if +// whether the respective sound system is disabled +// or they're init'ed, but the player just toggled them #ifdef _XBOX boolean midi_disabled = true, sound_disabled = true; boolean digital_disabled = true; #else -boolean midi_disabled = false, sound_disabled = false; -boolean digital_disabled = false; // No fmod-based music -#endif - -// These variables are only true if -// 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; +#endif boolean advancedemo; #ifdef DEBUGFILE diff --git a/src/s_sound.c b/src/s_sound.c index 53b8a9628..969d9fdee 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1378,7 +1378,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) return; } - if (strnicmp(music_name, newmusic, 6)) + if (strnicmp(music_name, mmusic, 6)) { S_StopMusic(); // shutdown old music diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index ce84e86a6..30ef1b27b 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) { From 691de18fbbe502fe15fa30854a09c028897cc312 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 11:10:38 -0400 Subject: [PATCH 23/34] Menu sound toggle fixes (and add starpost sfx to menu) --- src/m_menu.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 6a6875aad..63794c529 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6954,23 +6954,15 @@ static void M_ToggleSFX(void) { sound_disabled = false; I_StartupSound(); - if (sound_disabled) return; S_InitSfxChannels(cv_soundvolume.value); + S_StartSound(NULL, sfx_strpst); M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); } else { - if (sound_disabled) - { - sound_disabled = false; - M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); - } - else - { - sound_disabled = true; - S_StopSounds(); - M_StartMessage(M_GetText("SFX Disabled\n"), NULL, MM_NOTHING); - } + sound_disabled = true; + S_StopSounds(); + M_StartMessage(M_GetText("SFX Disabled\n"), NULL, MM_NOTHING); } } @@ -6980,7 +6972,6 @@ static void M_ToggleDigital(void) { digital_disabled = false; I_InitMusic(); - if (digital_disabled) return; S_StopMusic(); if (Playing()) P_RestoreMusic(&players[consoleplayer]); @@ -7020,7 +7011,6 @@ static void M_ToggleMIDI(void) { midi_disabled = false; I_InitMusic(); - if (midi_disabled) return; if (Playing()) P_RestoreMusic(&players[consoleplayer]); else From 8e05de17f07e599ebb0e3030cb6d74a0b1f76e02 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 12:29:58 -0400 Subject: [PATCH 24/34] Bring back music_data handle, for srb2dd --- src/s_sound.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/s_sound.c b/src/s_sound.c index 969d9fdee..13b8beac1 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1215,6 +1215,7 @@ const char *compat_special_music_slots[16] = #endif static char music_name[7]; // up to 6-character name +static void *music_data; static UINT16 music_flags; static boolean music_looping; @@ -1333,6 +1334,7 @@ static boolean S_LoadMusic(const char *mname) { strncpy(music_name, mname, 7); music_name[6] = 0; + music_data = mdata; return true; } else @@ -1343,6 +1345,10 @@ static void S_UnloadMusic(void) { I_UnloadSong(); music_name[0] = 0; +#ifndef HAVE_SDL //SDL uses RWOPS + Z_ChangeTag(music_data, PU_CACHE); +#endif + music_data = NULL; music_flags = 0; music_looping = false; } From e72610a3dc0e7e1d18deb6375daa8bd5ef1e420f Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 12:47:33 -0400 Subject: [PATCH 25/34] Separate StopMusic and UnloadMusic --- src/s_sound.c | 12 ++++------- src/sdl/mixer_sound.c | 50 ++++++++++++++++++------------------------- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 13b8beac1..2b8e8e721 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1344,11 +1344,13 @@ static boolean S_LoadMusic(const char *mname) static void S_UnloadMusic(void) { I_UnloadSong(); - music_name[0] = 0; + #ifndef HAVE_SDL //SDL uses RWOPS Z_ChangeTag(music_data, PU_CACHE); #endif music_data = NULL; + + music_name[0] = 0; music_flags = 0; music_looping = false; } @@ -1413,13 +1415,7 @@ void S_StopMusic(void) S_SpeedMusic(1.0f); I_StopSong(); - I_UnloadSong(); - -#ifndef HAVE_SDL //SDL uses RWOPS - Z_ChangeTag(music_data, PU_CACHE); -#endif - - music_name[0] = 0; + S_UnloadMusic(); // for now, stopping also means you unload the song } // diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index dd00d78f7..99a379ea2 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -484,19 +484,7 @@ FUNCMATH void I_InitMusic(void) 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; + I_UnloadSong(); } /// ------------------------ @@ -565,10 +553,8 @@ boolean I_SetSongSpeed(float speed) boolean I_LoadSong(char *data, size_t len) { - I_Assert(!music); -#ifdef HAVE_LIBGME - I_Assert(!gme); -#endif + if (music || gme) + I_UnloadSong(); #ifdef HAVE_LIBGME if ((UINT8)data[0] == 0x1F @@ -710,11 +696,20 @@ boolean I_LoadSong(char *data, size_t len) void I_UnloadSong(void) { - // \todo unhook looper - //var_cleanup(); - //Mix_FreeMusic(music); - //music = NULL; I_StopSong(); + +#ifdef HAVE_LIBGME + if (gme) + { + gme_delete(gme); + gme = NULL; + } +#endif + if (music) + { + Mix_FreeMusic(music); + music = NULL; + } } boolean I_PlaySong(boolean looping) @@ -750,17 +745,14 @@ void I_StopSong(void) if (gme) { Mix_HookMusic(NULL, NULL); - gme_delete(gme); - gme = NULL; current_track = -1; - return; } #endif - if (!music) - return; - Mix_HookMusicFinished(NULL); - Mix_FreeMusic(music); - music = NULL; + if (music) + { + Mix_HookMusicFinished(NULL); + Mix_HaltMusic(); + } } void I_PauseSong(void) From 0999b0f8a8044eae0d8109ba3f0df102bb32c246 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 13:24:15 -0400 Subject: [PATCH 26/34] srb2dd music cleanup fixes --- src/win32/win_cd.c | 2 +- src/win32/win_snd.c | 76 +++++++++++++++++---------------------------- 2 files changed, 29 insertions(+), 49 deletions(-) diff --git a/src/win32/win_cd.c b/src/win32/win_cd.c index f6c430748..2586b8440 100644 --- a/src/win32/win_cd.c +++ b/src/win32/win_cd.c @@ -471,7 +471,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); + I_StopSong(); //faB: I don't use the notify message, I'm trying to minimize the delay mciPlay.dwCallback = (DWORD)((size_t)hWndMain); diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 2e05c4f72..36a5904a5 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -475,11 +475,11 @@ musictype_t I_SongType(void) return MU_WAV; case FMOD_SOUND_TYPE_MOD: return MU_MOD; - case FMOD_SOUND_TYPE_MID: + case FMOD_SOUND_TYPE_MIDI: return MU_MID; case FMOD_SOUND_TYPE_OGGVORBIS: return MU_OGG; - case FMOD_SOUND_TYPE_MP3: + case FMOD_SOUND_TYPE_MPEG: return MU_MP3; case FMOD_SOUND_TYPE_FLAC: return MU_FLAC; @@ -547,20 +547,13 @@ boolean I_SetSongSpeed(float speed) boolean I_LoadSong(char *data, size_t len) { - char *data; - size_t len; FMOD_CREATESOUNDEXINFO fmt; - lumpnum_t lumpnum = W_CheckNumForName(va("O_%s",musicname)); + FMOD_RESULT e; + FMOD_TAG tag; + unsigned int loopstart, loopend; - if (lumpnum == LUMPERROR) - { - lumpnum = W_CheckNumForName(va("D_%s",musicname)); - if (lumpnum == LUMPERROR) - return false; - } - - data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC); - len = W_LumpLength(lumpnum); + if (gme || music_stream) + I_UnloadSong(); memset(&fmt, 0, sizeof(FMOD_CREATESOUNDEXINFO)); fmt.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); @@ -595,8 +588,6 @@ boolean I_LoadSong(char *data, size_t len) gme_equalizer_t gmeq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; Z_Free(inflatedData); // GME supposedly makes a copy for itself, so we don't need this lying around Z_Free(data); // We don't need this, either. - gme_start_track(gme, 0); - current_track = 0; gme_set_equalizer(gme,&gmeq); fmt.format = FMOD_SOUND_FORMAT_PCM16; fmt.defaultfrequency = 44100; @@ -605,10 +596,7 @@ 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)); - 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)); + FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER, &fmt, &music_stream)); return true; } } @@ -675,26 +663,24 @@ 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, &fmt, &music_stream)); 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); + e = FMOD_System_CreateStream(fsys, data, FMOD_OPENMEMORY_POINT, &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)); + CONS_Alert(CONS_WARNING, "Failed to play music lump due to invalid format.\n"); else FMR(e); return false; } // Try to find a loop point in streaming music formats (ogg, mp3) - 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); @@ -708,13 +694,6 @@ boolean I_LoadSong(char *data, size_t len) 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) @@ -758,10 +737,19 @@ boolean I_LoadSong(char *data, size_t len) void I_UnloadSong(void) { - UNREFERENCED_PARAMETER(handle); + I_StopSong(); +#ifdef HAVE_LIBGME + if (gme) + { + gme_delete(gme); + gme = NULL; + } +#endif if (music_stream) + { FMR(FMOD_Sound_Release(music_stream)); - music_stream = NULL; + music_stream = NULL; + } } boolean I_PlaySong(boolean looping) @@ -771,7 +759,6 @@ 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)); @@ -779,6 +766,7 @@ boolean I_PlaySong(boolean looping) } #endif + FMR(FMOD_Sound_SetMode(music_stream, (looping ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF))); FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); if (I_SongType() != MU_MID) FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); @@ -792,33 +780,25 @@ boolean I_PlaySong(boolean looping) void I_StopSong(void) { -#ifdef HAVE_LIBGME - if (gme) - gme_delete(gme); - gme = NULL; -#endif - current_track = -1; - - I_UnloadSong(); + if (music_channel) + FMR_MUSIC(FMOD_Channel_Stop(music_channel)); } void I_PauseSong(void) { - UNREFERENCED_PARAMETER(handle); - if (music_stream) + if (music_channel) FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, true)); } void I_ResumeSong(void) { - UNREFERENCED_PARAMETER(handle); - if (music_stream) + if (music_channel) FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, false)); } void I_SetMusicVolume(UINT8 volume) { - if (!music_stream) + if (!music_channel) return; // volume is 0 to 31. From cb4e075137857a391005cfb12c25b294c4e96031 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 13:36:01 -0400 Subject: [PATCH 27/34] I_InitMusic SDL2: Don't unload GME indiscriminately --- src/sdl/mixer_sound.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 99a379ea2..f39d375ef 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -476,10 +476,6 @@ 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) From 76be77b93a2a655cd28983c1709fe058c5878859 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 14:52:24 -0400 Subject: [PATCH 28/34] Rip out SDL Mixer code from sdl_sound.c because superfluous * Mixer code has been in mixer_sound.c; this file is not invoked unless compiling with NOMIXER=1 * Remove everything under #ifdef HAVE_MIXER because this is never triggered * Comment out #ifdef HAVE_LIBGME because we don't support playing music anyway (but theoretically, it could have worked separately from Mixer) * Stub new music calls --- src/sdl/sdl_sound.c | 611 +++----------------------------------------- 1 file changed, 42 insertions(+), 569 deletions(-) diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 887726ebb..e29ac080b 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -989,7 +989,7 @@ FUNCINLINE static ATTRINLINE void I_UpdateStream16M(Uint8 *stream, int len) if (Snd_Mutex) SDL_UnlockMutex(Snd_Mutex); } -#ifdef HAVE_LIBGME +#if 0 //#ifdef HAVE_LIBGME static void I_UpdateSteamGME(Music_Emu *emu, INT16 *stream, int len, UINT8 looping) { #define GME_BUFFER_LEN 44100*2048 @@ -1049,14 +1049,16 @@ static void SDLCALL I_UpdateStream(void *userdata, Uint8 *stream, int len) else if (audio.channels == 2 && audio.format == AUDIO_S16SYS) { I_UpdateStream16S(stream, len); -#ifdef HAVE_LIBGME - if (userdata) - { - srb2audio_t *sa_userdata = userdata; - if (!sa_userdata->gme_pause) - I_UpdateSteamGME(sa_userdata->gme_emu, (INT16 *)stream, len/4, sa_userdata->gme_loop); - } -#endif + + // Crashes! But no matter; this build doesn't play music anyway... +// #ifdef HAVE_LIBGME +// if (userdata) +// { +// srb2audio_t *sa_userdata = userdata; +// if (!sa_userdata->gme_pause) +// I_UpdateSteamGME(sa_userdata->gme_emu, (INT16 *)stream, len/4, sa_userdata->gme_loop); +// } +// #endif } } @@ -1313,40 +1315,11 @@ void I_StartupSound(void) // MUSIC API. // -musictype_t I_SongType(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 -} +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ -boolean I_SongPlaying(void) -{ - return music_started; -} - -boolean I_SongPaused(void) -{ - return Mix_PausedMusic(); -} - -#ifdef HAVE_LIBGME +#if 0 //#ifdef HAVE_LIBGME static void I_ShutdownGMEMusic(void) { Snd_LockAudio(); @@ -1357,235 +1330,14 @@ static void I_ShutdownGMEMusic(void) } #endif -#ifdef HAVE_MIXER -static boolean LoadSong(void *data, size_t lumplength, size_t selectpos) -{ - FILE *midfile; - const char *tempname; -#ifdef USE_RWOPS - if (canuseRW) - { - SDL_RWops *SDLRW; - void *olddata = Smidi[selectpos]; //quick shortcut to set - - Z_Free(olddata); //free old memory - Smidi[selectpos] = NULL; - - if (!data) - return olddata != NULL; //was there old data? - - SDLRW = SDL_RWFromConstMem(data, (int)lumplength); //new RWops from Z_zone - if (!SDLRW) //ERROR while making RWops! - { - CONS_Printf(M_GetText("Couldn't load music lump: %s\n"), SDL_GetError()); - Z_Free(data); - return false; - } - - music[selectpos] = Mix_LoadMUS_RW(SDLRW); // new Mix_Chuck from RWops - if (music[selectpos]) - Smidi[selectpos] = data; //all done - else //ERROR while making Mix_Chuck - { - CONS_Printf(M_GetText("Couldn't load music data: %s\n"), Mix_GetError()); - Z_Free(data); - SDL_RWclose(SDLRW); - Smidi[selectpos] = NULL; - } - return true; - } -#endif - tempname = va("%s/%s", MIDI_PATH, fmidi[selectpos]); - - if (!data) - { - if (FIL_FileExists(tempname)) - return unlink(tempname)+1; -#ifdef MIDI_PATH2 - else if (FIL_FileExists(tempname = va("%s/%s", MIDI_PATH2, fmidi[selectpos]))) - return unlink(tempname)+1; -#endif - else - return false; - } - - midfile = fopen(tempname, "wb"); - -#ifdef MIDI_PATH2 - if (!midfile) - { - tempname = va("%s/%s", MIDI_PATH2, fmidi[selectpos]); - midfile = fopen(tempname, "wb"); - } -#endif - - if (!midfile) - { - CONS_Printf(M_GetText("Couldn't open file %s to write music in\n"), tempname); - Z_Free(data); - return false; - } - - if (fwrite(data, lumplength, 1, midfile) == 0) - { - CONS_Printf(M_GetText("Couldn't write music into file %s because %s\n"), tempname, strerror(ferror(midfile))); - Z_Free(data); - fclose(midfile); - return false; - } - - fclose(midfile); - - Z_Free(data); - - music[selectpos] = Mix_LoadMUS(tempname); - if (!music[selectpos]) //ERROR while making Mix_Chuck - { - CONS_Printf(M_GetText("Couldn't load music file %s: %s\n"), tempname, Mix_GetError()); - return false; - } - return true; -} -#endif - -/// ------------------------ -// MUSIC SYSTEM -/// ------------------------ - void I_InitMusic(void) { -#ifdef HAVE_MIXER - char ad[100]; - SDL_version MIXcompiled; - const SDL_version *MIXlinked; -#ifdef MIXER_INIT - const int mixstart = MIX_INIT_OGG; - int mixflags; -#endif -#endif -#ifdef HAVE_LIBGME +#if 0 //#ifdef HAVE_LIBGME I_AddExitFunc(I_ShutdownGMEMusic); #endif - -#ifdef HAVE_MIXER - MIX_VERSION(&MIXcompiled) - MIXlinked = Mix_Linked_Version(); - I_OutputMsg("Compiled for SDL_mixer version: %d.%d.%d\n", - MIXcompiled.major, MIXcompiled.minor, MIXcompiled.patch); -#ifdef MIXER_POS - if (MIXlinked->major == 1 && MIXlinked->minor == 2 && MIXlinked->patch < 7) - canlooping = SDL_FALSE; -#endif -#ifdef USE_RWOPS - if (M_CheckParm("-noRW")) - canuseRW = SDL_FALSE; -#endif - I_OutputMsg("Linked with SDL_mixer version: %d.%d.%d\n", - MIXlinked->major, MIXlinked->minor, MIXlinked->patch); - if (audio.freq < 44100 && !M_CheckParm ("-freq")) //I want atleast 44Khz - { - audio.samples = (Uint16)(audio.samples*(INT32)(44100/audio.freq)); - audio.freq = 44100; //Alam: to keep it around the same XX ms - } - - if (sound_started -#ifdef HW3SOUND - && hws_mode == HWS_DEFAULT_MODE -#endif - ) - { - I_OutputMsg("Temp Shutdown of SDL Audio System"); - SDL_CloseAudio(); - I_OutputMsg(" Done\n"); - } - - CONS_Printf("%s", M_GetText("I_InitMusic:")); - -#ifdef MIXER_INIT - mixflags = Mix_Init(mixstart); - if ((mixstart & MIX_INIT_FLAC) != (mixflags & MIX_INIT_FLAC)) - { - CONS_Printf("%s", M_GetText(" Unable to load FLAC support\n")); - } - if ((mixstart & MIX_INIT_MOD ) != (mixflags & MIX_INIT_MOD )) - { - CONS_Printf("%s", M_GetText(" Unable to load MOD support\n")); - } - if ((mixstart & MIX_INIT_MP3 ) != (mixflags & MIX_INIT_MP3 )) - { - CONS_Printf("%s", M_GetText(" Unable to load MP3 support\n")); - } - if ((mixstart & MIX_INIT_OGG ) != (mixflags & MIX_INIT_OGG )) - { - CONS_Printf("%s", M_GetText(" Unable to load OGG support\n")); - } -#endif - - 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()); - midi_disabled = digital_disabled = true; - if (sound_started -#ifdef HW3SOUND - && hws_mode == HWS_DEFAULT_MODE -#endif - ) - { - if (SDL_OpenAudio(&audio, NULL) < 0) //retry - { - CONS_Printf("%s", M_GetText(" couldn't open audio with desired format\n")); - sound_disabled = true; - sound_started = false; - } - else - { - CONS_Printf(M_GetText(" Starting with audio driver : %s\n"), SDL_AudioDriverName(ad, (int)sizeof ad)); - } - } - return; - } - else - CONS_Printf(M_GetText(" Starting up with audio driver : %s with SDL_Mixer\n"), SDL_AudioDriverName(ad, (int)sizeof ad)); - - samplecount = audio.samples; - CV_SetValue(&cv_samplerate, audio.freq); - if (sound_started -#ifdef HW3SOUND - && hws_mode == HWS_DEFAULT_MODE -#endif - ) - I_OutputMsg(" Reconfigured SDL Audio System"); - else I_OutputMsg(" Configured SDL_Mixer System"); - I_OutputMsg(" with %d samples/slice at %ikhz(%dms buffer)\n", samplecount, audio.freq/1000, (INT32) ((audio.samples * 1000.0f) / audio.freq)); - Mix_SetPostMix(audio.callback, audio.userdata); // after mixing music, add sound effects - Mix_Resume(-1); - CONS_Printf("%s", M_GetText("Music initialized\n")); - musicStarted = SDL_TRUE; - Msc_Mutex = SDL_CreateMutex(); -#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 -} +void I_ShutdownMusic(void) { } /// ------------------------ // MUSIC PROPERTIES @@ -1618,149 +1370,64 @@ boolean I_SetSongSpeed(float speed) /// ------------------------ // MUSIC PLAYBACK -// \todo Merge Digital and MIDI /// ------------------------ +#if 0 //#ifdef HAVE_LIBGME +static void I_StopGME(void) +{ + Snd_LockAudio(); + gme_seek(localdata.gme_emu, 0); + Snd_UnlockAudio(); +} + +static void I_PauseGME(void) +{ + localdata.gme_pause = true; +} + +static void I_ResumeGME(void) +{ + localdata.gme_pause = false; +} +#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_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 -} +void I_UnloadSong(void) { } boolean I_PlaySong(boolean looping) { -#ifdef HAVE_MIXER - if (!musicStarted || !music[handle]) - return false; - -#ifdef MIXER_POS - if (canlooping) - Mix_HookMusicFinished(NULL); -#endif - - if (Mix_FadeInMusic(music[handle], looping ? -1 : 0, MIDIfade) == -1) - CONS_Printf(M_GetText("Couldn't play song because %s\n"), Mix_GetError()); - else - { - Mix_VolumeMusic(musicvol); - return true; - } -#else (void)looping; -#endif return false; } void I_StopSong(void) { +#if 0 //#ifdef HAVE_LIBGME 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 - localdata.gme_pause = true; #endif } void I_PauseSong(void) { - (void)handle; +#if 0 //#ifdef HAVE_LIBGME I_PauseGME(); -#ifdef HAVE_MIXER - if ((midi_disabled && digital_disabled) || !musicStarted) - return; - - Mix_PauseMusic(); - //I_StopSong(handle); -#endif -} - -static void I_ResumeGME(void) -{ -#ifdef HAVE_LIBGME - localdata.gme_pause = false; #endif } void I_ResumeSong(void) { - (void)handle; +#if 0 I_ResumeGME(); -#ifdef HAVE_MIXER - if ((midi_disabled && digital_disabled) || !musicStarted) - return; - - Mix_VolumeMusic(musicvol); - Mix_ResumeMusic(); - //I_PlaySong(handle, true); #endif } void I_SetMusicVolume(UINT8 volume) { -#ifdef HAVE_MIXER - if ((midi_disabled && digital_disabled) || !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_SetSongTrack(int track) @@ -1775,16 +1442,14 @@ boolean I_SetSongTrack(int track) // then move to Playback section /// ------------------------ -#ifdef HAVE_LIBGME +#if 0 //#ifdef HAVE_LIBGME static void I_CleanupGME(void *userdata) { Z_Free(userdata); } -#endif static boolean I_StartGMESong(const char *musicname, boolean looping) { -#ifdef HAVE_LIBGME char filename[9]; void *data; lumpnum_t lumpnum; @@ -1830,199 +1495,7 @@ static boolean I_StartGMESong(const char *musicname, boolean looping) Snd_UnlockAudio(); return true; -#else - (void)musicname; - (void)looping; -#endif - return false; -} - -boolean I_StartDigSong(const char *musicname, boolean looping) -{ -#ifdef HAVE_MIXER - char filename[9]; - void *data; - lumpnum_t lumpnum; - size_t lumplength; -#endif - - if(I_StartGMESong(musicname, looping)) - return true; - -#ifdef HAVE_MIXER - if (digital_disabled) - return false; - - snprintf(filename, sizeof filename, "o_%s", musicname); - - lumpnum = W_CheckNumForName(filename); - - I_StopSong(); - - if (lumpnum == LUMPERROR) - { - // Alam_GBC: like in win32/win_snd.c: Graue 02-29-2004: don't worry about missing music, there might still be a MIDI - //I_OutputMsg("Music lump %s not found!\n", filename); - return false; // No music found. Oh well! - } - else - lumplength = W_LumpLength(lumpnum); - - data = W_CacheLumpNum(lumpnum, PU_MUSIC); - - if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); - -#ifdef MIXER_POS - if (canlooping && (loopingDig = looping) == SDL_TRUE && strcmp(data, "OggS") == 0) - looping = false; // Only on looping Ogg files, will we will do our own looping - - // Scan the Ogg Vorbis file for the COMMENT= field for a custom - // loop point - if (!looping && loopingDig) - { - size_t scan; - const char *dataum = data; - char looplength[64]; - UINT32 loopstart = 0; - UINT8 newcount = 0; - - Mix_HookMusicFinished(I_FinishMusic); - - for (scan = 0; scan < lumplength; scan++) - { - if (*dataum++ == 'C'){ - if (*dataum++ == 'O'){ - if (*dataum++ == 'M'){ - if (*dataum++ == 'M'){ - if (*dataum++ == 'E'){ - if (*dataum++ == 'N'){ - if (*dataum++ == 'T'){ - if (*dataum++ == '='){ - if (*dataum++ == 'L'){ - if (*dataum++ == 'O'){ - if (*dataum++ == 'O'){ - if (*dataum++ == 'P'){ - if (*dataum++ == 'P'){ - if (*dataum++ == 'O'){ - if (*dataum++ == 'I'){ - if (*dataum++ == 'N'){ - if (*dataum++ == 'T'){ - if (*dataum++ == '=') - { - - while (*dataum != 1 && newcount != 63) - looplength[newcount++] = *dataum++; - - looplength[newcount] = '\0'; - - loopstart = atoi(looplength); - - } - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - } - - if (loopstart > 0) - { - loopstartDig = (double)((44.1l+loopstart) / 44100.0l); //8 PCM chucks off and PCM to secs -//#ifdef PARANOIA - //I_OutputMsg("I_StartDigSong: setting looping point to %ul PCMs(%f seconds)\n", loopstart, loopstartDig); -//#endif - } - else - { - looping = true; // loopingDig true, but couldn't find start loop point - } - } - else - loopstartDig = 0.0l; -#else - if (looping && strcmp(data, "OggS") == 0) - I_OutputMsg("I_StartDigSong: SRB2 was not compiled with looping music support(no Mix_FadeInMusicPos)\n"); -#endif - - if (!LoadSong(data, lumplength, 1)) - { - if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); - return false; - } - - // Note: LoadSong() frees the data. Let's make sure - // we don't try to use the data again. - data = NULL; - - if (Mix_FadeInMusic(music[1], looping ? -1 : 0, Digfade) == -1) - { - if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); - I_OutputMsg("I_StartDigSong: Couldn't play song %s because %s\n", musicname, Mix_GetError()); - return false; - } - Mix_VolumeMusic(musicvol); - - if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); - return true; -#else - (void)looping; - (void)musicname; - return false; -#endif -} - -static void I_StopGME(void) -{ -#ifdef HAVE_LIBGME - Snd_LockAudio(); - gme_seek(localdata.gme_emu, 0); - Snd_UnlockAudio(); -#endif -} - -#ifdef MIXER_POS -static void SDLCALL I_FinishMusic(void) -{ - if (!music[1]) - return; - else if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); -// I_OutputMsg("I_FinishMusic: Loopping song to %g seconds\n", loopstartDig); - - if (Mix_FadeInMusicPos(music[1], loopstartDig ? 0 : -1, Digfade, loopstartDig) == 0) - Mix_VolumeMusic(musicvol); - else - I_OutputMsg("I_FinishMusic: Couldn't loop song because %s\n", Mix_GetError()); - - if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); } #endif + #endif //HAVE_SDL \ No newline at end of file From b330dc23946ecfae91301ababebbfddc97560c7e Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 16:39:10 -0400 Subject: [PATCH 29/34] Don't call I_StartupSound in SFX toggle * Mixer: make I_StartupSound return early if already set up * Restartaudio: Add StopSFX call --- src/d_netcmd.c | 1 + src/m_menu.c | 1 - src/sdl/mixer_sound.c | 5 ++++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index ab3201c5c..a58aff3fe 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3955,6 +3955,7 @@ static void Command_RestartAudio_f(void) return; S_StopMusic(); + S_StopSounds(); I_ShutdownMusic(); I_ShutdownSound(); I_StartupSound(); diff --git a/src/m_menu.c b/src/m_menu.c index 63794c529..c9adbfb9c 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6953,7 +6953,6 @@ static void M_ToggleSFX(void) if (sound_disabled) { sound_disabled = false; - I_StartupSound(); S_InitSfxChannels(cv_soundvolume.value); S_StartSound(NULL, sfx_strpst); M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index f39d375ef..72217482f 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -82,7 +82,10 @@ void I_StartupSound(void) // EE inits audio first so we're following along. if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO) - CONS_Printf("SDL Audio already started\n"); + { + CONS_Debug(DBG_DETAILED, "SDL Audio already started\n"); + return; + } else if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { CONS_Alert(CONS_ERROR, "Error initializing SDL Audio: %s\n", SDL_GetError()); From fdbe3e80f6eac3659093a79f8dabfb92df0b1c10 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 17:07:13 -0400 Subject: [PATCH 30/34] Fix compile errors on buildbots * Check SDL Mixer 2.0.3 for MUS_MODPLUG_UNUSED, MUS_MP3_MAD_UNUSED * Mixed D+C in I_LoadSong --- src/sdl/mixer_sound.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 72217482f..d496aa666 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -501,9 +501,17 @@ musictype_t I_SongType(void) 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) + else if (Mix_GetMusicType(music) == MUS_MOD +#if SDL_MIXER_VERSION_ATLEAST(2,0,3) + || Mix_GetMusicType(music) == MUS_MODPLUG_UNUSED +#endif + ) return MU_MOD; - else if (Mix_GetMusicType(music) == MUS_MP3 || Mix_GetMusicType(music) == MUS_MP3_MAD_UNUSED) + else if (Mix_GetMusicType(music) == MUS_MP3 +#if SDL_MIXER_VERSION_ATLEAST(2,0,3) + || Mix_GetMusicType(music) == MUS_MP3_MAD_UNUSED +#endif + ) return MU_MP3; else return (musictype_t)Mix_GetMusicType(music); @@ -552,6 +560,14 @@ boolean I_SetSongSpeed(float speed) boolean I_LoadSong(char *data, size_t 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; + if (music || gme) I_UnloadSong(); @@ -660,13 +676,6 @@ boolean I_LoadSong(char *data, size_t len) // Find the OGG loop point. loop_point = 0.0f; - 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)) From 17ec5d80220b472fe827e5e87b5c05f083a3cd24 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 17:27:00 -0400 Subject: [PATCH 31/34] Mixer: Better MODPLUG/MP3_MAD defines (cherry picked from commit 5b724e18b5268b0492b3f8b8980aadd2dd41e235) --- src/sdl/mixer_sound.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index d496aa666..e46da2755 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -34,6 +34,12 @@ (SDL_MIXER_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z)) #endif +// thanks alam for making the buildbots happy! +#if SDL_MIXER_VERSION_ATLEAST(2,0,3) +#define MUS_MP3_MAD MUS_MP3_MAD_UNUSED +#define MUS_MODPLUG MUS_MODPLUG_UNUSED +#endif + #ifdef HAVE_LIBGME #include "gme/gme.h" #define GME_TREBLE 5.0 @@ -501,17 +507,9 @@ musictype_t I_SongType(void) return MU_NONE; else if (Mix_GetMusicType(music) == MUS_MID) return MU_MID; - else if (Mix_GetMusicType(music) == MUS_MOD -#if SDL_MIXER_VERSION_ATLEAST(2,0,3) - || Mix_GetMusicType(music) == MUS_MODPLUG_UNUSED -#endif - ) + else if (Mix_GetMusicType(music) == MUS_MOD || Mix_GetMusicType(music) == MUS_MODPLUG) return MU_MOD; - else if (Mix_GetMusicType(music) == MUS_MP3 -#if SDL_MIXER_VERSION_ATLEAST(2,0,3) - || Mix_GetMusicType(music) == MUS_MP3_MAD_UNUSED -#endif - ) + else if (Mix_GetMusicType(music) == MUS_MP3 || Mix_GetMusicType(music) == MUS_MP3_MAD) return MU_MP3; else return (musictype_t)Mix_GetMusicType(music); From 9a5eb024590d5b98afa878a6ebd49eef4fcb28ed Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 17:47:04 -0400 Subject: [PATCH 32/34] Fix Windows buildbot for MP3_MAD/MODPLUG define (the header we use is 2.0.2) --- src/sdl/mixer_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index e46da2755..7d11c32c6 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -35,7 +35,7 @@ #endif // thanks alam for making the buildbots happy! -#if SDL_MIXER_VERSION_ATLEAST(2,0,3) +#if SDL_MIXER_VERSION_ATLEAST(2,0,2) #define MUS_MP3_MAD MUS_MP3_MAD_UNUSED #define MUS_MODPLUG MUS_MODPLUG_UNUSED #endif From 40a8c9c1ee4fc30e82a8ce3d84d309152a07a5a2 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sat, 15 Sep 2018 00:34:55 -0400 Subject: [PATCH 33/34] Mixer: HAVE_LIBGME ifdef in I_LoadSong --- src/sdl/mixer_sound.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 7d11c32c6..87f8fd671 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -566,7 +566,11 @@ boolean I_LoadSong(char *data, size_t len) const size_t key3len = strlen(key3); char *p = data; - if (music || gme) + if (music +#ifdef HAVE_LIBGME + || gme +#endif + ) I_UnloadSong(); #ifdef HAVE_LIBGME From 34e403afcb501ae5e456dc292b8a3632a7e5fab9 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Sep 2018 08:32:34 -0400 Subject: [PATCH 34/34] S_ChangeMusic: More specific load/play fail messages --- src/s_sound.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index 2b8e8e721..ea129a109 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1391,14 +1391,17 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) S_StopMusic(); // shutdown old music if (!S_LoadMusic(mmusic)) + { + CONS_Alert(CONS_ERROR, "Music %.6s could not be loaded!\n", mmusic); return; + } music_flags = mflags; music_looping = looping; if (!S_PlayMusic(looping)) { - CONS_Alert(CONS_ERROR, "Music cannot be played!\n"); + CONS_Alert(CONS_ERROR, "Music %.6s could not be played!\n", mmusic); return; } }