From 75cbfab8c6804f3f84e5c131601868e130bb7dac Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 09:06:31 -0400 Subject: [PATCH] Playback routines other targets --- src/android/i_sound.c | 25 ++------- src/djgppdos/i_sound.c | 50 ++--------------- src/dummy/i_sound.c | 25 ++------- src/sdl/sdl_sound.c | 75 +++++++------------------ src/win32/win_snd.c | 124 +++++++++++++++-------------------------- 5 files changed, 81 insertions(+), 218 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 24db3e21d..109faf57d 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -80,30 +80,26 @@ void I_ResumeSong(INT32 handle) UINT8 midimusic_started = 0; -void I_InitMIDIMusic(void){} - -void I_ShutdownMIDIMusic(void){} - -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(void *data, size_t len) { (void)data; (void)len; return -1; } -boolean I_PlaySong(INT32 handle, INT32 looping) +boolean I_PlaySong(void) { (void)handle; (void)looping; return false; } -void I_StopSong(INT32 handle) +void I_StopSong(void) { (void)handle; } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { (void)handle; } @@ -114,19 +110,6 @@ void I_UnRegisterSong(INT32 handle) UINT8 digmusic_started = 0; -void I_InitDigMusic(void){} - -void I_ShutdownDigMusic(void){} - -boolean I_StartDigSong(const char *musicname, INT32 looping) -{ - (void)musicname; - (void)looping; - return false; -} - -void I_StopDigSong(void){} - void I_SetDigMusicVolume(INT32 volume) { (void)volume; diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index dcf64fa69..993e164c9 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -380,7 +380,7 @@ static MIDI *load_midi_mem(char *mempointer,int *e) return midi; } -void I_InitMIDIMusic(void) +void I_InitMusic(void) { if (nomidimusic) return; @@ -389,7 +389,7 @@ void I_InitMIDIMusic(void) music_started = true; } -void I_ShutdownMIDIMusic(void) +void I_ShutdownMusic(void) { if ( !music_started ) return; @@ -399,31 +399,7 @@ void I_ShutdownMIDIMusic(void) music_started=false; } -void I_InitDigMusic(void) -{ -// CONS_Printf("Digital music not yet supported under DOS.\n"); -} - -void I_ShutdownDigMusic(void) -{ -// CONS_Printf("Digital music not yet supported under DOS.\n"); -} - -void I_InitMusic(void) -{ - if (!nodigimusic) - I_InitDigMusic(); - if (!nomidimusic) - I_InitMIDIMusic(); -} - -void I_ShutdownMusic(void) -{ - I_ShutdownMIDIMusic(); - I_ShutdownDigMusic(); -} - -boolean I_PlaySong(INT32 handle, INT32 looping) +boolean I_PlaySong(void) { handle = 0; if (nomidimusic) @@ -454,7 +430,7 @@ void I_ResumeSong (INT32 handle) midi_resume(); } -void I_StopSong(INT32 handle) +void I_StopSong(void) { handle = 0; if (nomidimusic) @@ -477,7 +453,7 @@ int I_QrySongPlaying(int handle) } #endif -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { handle = 0; if (nomidimusic) @@ -486,7 +462,7 @@ void I_UnRegisterSong(INT32 handle) //destroy_midi(currsong); } -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(void *data, size_t len) { int e = len; //Alam: For error if (nomidimusic) @@ -511,20 +487,6 @@ INT32 I_RegisterSong(void *data, size_t len) return 1; } -/// \todo Add OGG/MP3 support for dos -boolean I_StartDigSong(const char *musicname, INT32 looping) -{ - musicname = NULL; - looping = 0; - //CONS_Printf("I_StartDigSong: Not yet supported under DOS.\n"); - return false; -} - -void I_StopDigSong(void) -{ -// CONS_Printf("I_StopDigSong: Not yet supported under DOS.\n"); -} - void I_SetDigMusicVolume(INT32 volume) { volume = 0; diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 89ccc2b6a..ef186d5f3 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -79,30 +79,26 @@ void I_ResumeSong(INT32 handle) // MIDI I/O // -void I_InitMIDIMusic(void){} - -void I_ShutdownMIDIMusic(void){} - -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(void *data, size_t len) { (void)data; (void)len; return -1; } -boolean I_PlaySong(INT32 handle, boolean looping) +boolean I_PlaySong(void) { (void)handle; (void)looping; return false; } -void I_StopSong(INT32 handle) +void I_StopSong(void) { (void)handle; } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { (void)handle; } @@ -111,19 +107,6 @@ void I_UnRegisterSong(INT32 handle) // DIGMUSIC I/O // -void I_InitDigMusic(void){} - -void I_ShutdownDigMusic(void){} - -boolean I_StartDigSong(const char *musicname, boolean looping) -{ - (void)musicname; - (void)looping; - return false; -} - -void I_StopDigSong(void){} - void I_SetDigMusicVolume(UINT8 volume) { (void)volume; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index e43afcb57..fb4c301ae 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1313,12 +1313,6 @@ void I_StartupSound(void) // MUSIC API. // -void I_ShutdownMIDIMusic(void) -{ - nomidimusic = false; - if (nodigimusic) I_ShutdownMusic(); -} - #ifdef HAVE_LIBGME static void I_ShutdownGMEMusic(void) { @@ -1330,12 +1324,6 @@ static void I_ShutdownGMEMusic(void) } #endif -void I_ShutdownDigMusic(void) -{ - nodigimusic = false; - if (nomidimusic) I_ShutdownMusic(); -} - #ifdef HAVE_MIXER static boolean LoadSong(void *data, size_t lumplength, size_t selectpos) { @@ -1436,8 +1424,8 @@ void I_ShutdownMusic(void) CONS_Printf("%s", M_GetText("I_ShutdownMusic: ")); - I_UnRegisterSong(0); - I_StopDigSong(); + I_UnloadSong(); + I_StopSong(); Mix_CloseAudio(); #ifdef MIX_INIT Mix_Quit(); @@ -1450,16 +1438,6 @@ void I_ShutdownMusic(void) #endif } -void I_InitMIDIMusic(void) -{ - if (nodigimusic) I_InitMusic(); -} - -void I_InitDigMusic(void) -{ - if (nomidimusic) I_InitMusic(); -} - void I_InitMusic(void) { #ifdef HAVE_MIXER @@ -1639,17 +1617,29 @@ void I_ResumeSong(INT32 handle) #endif } -void I_StopSong(INT32 handle) +void I_StopSong(void) { - (void)handle; + I_StopGME(); #ifdef HAVE_MIXER - if (nomidimusic || !musicStarted) + if (nodigimusic) return; - Mix_FadeOutMusic(MIDIfade); + +#ifdef MIXER_POS + if (canlooping) + Mix_HookMusicFinished(NULL); #endif + + Mix_HaltMusic(); + while (Mix_PlayingMusic()) + ; + + if (music[1]) + Mix_FreeMusic(music[1]); + music[1] = NULL; + LoadSong(NULL, 0, 1); } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { #ifdef HAVE_MIXER @@ -1669,7 +1659,7 @@ void I_UnRegisterSong(INT32 handle) #endif } -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(void *data, size_t len) { #ifdef HAVE_MIXER if (nomidimusic || !musicStarted) @@ -1771,7 +1761,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) lumpnum = W_CheckNumForName(filename); - I_StopDigSong(); + I_StopSong(); if (lumpnum == LUMPERROR) { @@ -1923,29 +1913,6 @@ static void I_StopGME(void) #endif } -void I_StopDigSong(void) -{ - I_StopGME(); -#ifdef HAVE_MIXER - if (nodigimusic) - return; - -#ifdef MIXER_POS - if (canlooping) - Mix_HookMusicFinished(NULL); -#endif - - Mix_HaltMusic(); - while (Mix_PlayingMusic()) - ; - - if (music[1]) - Mix_FreeMusic(music[1]); - music[1] = NULL; - LoadSong(NULL, 0, 1); -#endif -} - void I_SetDigMusicVolume(UINT8 volume) { #ifdef HAVE_MIXER diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 281f48ea7..559feb2ae 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -450,8 +450,7 @@ void I_InitMusic(void) void I_ShutdownMusic(void) { - I_ShutdownDigMusic(); - I_ShutdownMIDIMusic(); + I_StopSong(); } void I_PauseSong(INT32 handle) @@ -468,17 +467,7 @@ void I_ResumeSong(INT32 handle) FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, false)); } -void I_InitDigMusic(void) -{ -} - -void I_ShutdownDigMusic(void) -{ - if (!midimode) - I_StopDigSong(); -} - -boolean I_StartDigSong(const char *musicname, boolean looping) +boolean I_LoadSong(char *data, size_t len) { char *data; size_t len; @@ -603,8 +592,6 @@ boolean I_StartDigSong(const char *musicname, boolean looping) { gme_equalizer_t gmeq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; Z_Free(data); // We don't need this anymore. - gme_start_track(gme, 0); - current_track = 0; gme_set_equalizer(gme,&gmeq); fmt.format = FMOD_SOUND_FORMAT_PCM16; fmt.defaultfrequency = 44100; @@ -614,32 +601,21 @@ boolean I_StartDigSong(const char *musicname, boolean looping) fmt.pcmreadcallback = GMEReadCallback; fmt.userdata = gme; FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); - FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); - FMR(FMOD_Channel_SetPriority(music_channel, 0)); return true; } #endif fmt.length = len; + + FMOD_RESULT e = FMOD_System_CreateStream(fsys, data, FMOD_OPENMEMORY_POINT|(looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream); + if (e != FMOD_OK) { - FMOD_RESULT e = FMOD_System_CreateStream(fsys, data, FMOD_OPENMEMORY_POINT|(looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream); - if (e != FMOD_OK) - { - if (e == FMOD_ERR_FORMAT) - CONS_Alert(CONS_WARNING, "Failed to play music lump %s due to invalid format.\n", W_CheckNameForNum(lumpnum)); - else - FMR(e); - return false; - } + if (e == FMOD_ERR_FORMAT) + CONS_Alert(CONS_WARNING, "Failed to play music lump %s due to invalid format.\n", W_CheckNameForNum(lumpnum)); + else + FMR(e); + return false; } - FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - if (midimode) - FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); - else - FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); - FMR(FMOD_Channel_SetPriority(music_channel, 0)); - current_track = 0; // Try to find a loop point in streaming music formats (ogg, mp3) if (looping) @@ -660,6 +636,13 @@ boolean I_StartDigSong(const char *musicname, boolean looping) return true; } + // todo + // if(music type == MIDI) + // { + // FMR(FMOD_Sound_SetMode(music_stream, FMOD_LOOP_NORMAL)); + // return true; + // } + // Use LOOPMS for time in miliseconds. e = FMOD_Sound_GetTag(music_stream, "LOOPMS", 0, &tag); if (e != FMOD_ERR_TAGNOTFOUND) @@ -698,23 +681,10 @@ boolean I_StartDigSong(const char *musicname, boolean looping) } } - // No special loop point, but we're playing so it's all good. + // No special loop point return true; } -void I_StopDigSong(void) -{ - if (music_stream) - FMR(FMOD_Sound_Release(music_stream)); - music_stream = NULL; -#ifdef HAVE_LIBGME - if (gme) - gme_delete(gme); - gme = NULL; -#endif - current_track = -1; -} - void I_SetDigMusicVolume(UINT8 volume) { // volume is 0 to 31. @@ -805,46 +775,44 @@ boolean I_SetSongTrack(INT32 track) // Fuck MIDI. ... Okay fine, you can have your silly D_-only mode. // -void I_InitMIDIMusic(void) +boolean I_PlaySong(void) { -} - -void I_ShutdownMIDIMusic(void) -{ - if (midimode) - I_StopSong(0); -} - -INT32 I_RegisterSong(void *data, size_t len) -{ - FMOD_CREATESOUNDEXINFO fmt; - memset(&fmt, 0, sizeof(FMOD_CREATESOUNDEXINFO)); - fmt.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); - fmt.length = len; - FMR(FMOD_System_CreateStream(fsys, (char *)data, FMOD_OPENMEMORY_POINT, &fmt, &music_stream)); - return 1337; -} - -boolean I_PlaySong(INT32 handle, boolean looping) -{ - if (1337 == handle) +#ifdef HAVE_LIBGME + if (gme) { - midimode = true; - if (looping) - FMR(FMOD_Sound_SetMode(music_stream, FMOD_LOOP_NORMAL)); + gme_start_track(gme, 0); + current_track = 0; FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); - FMR_MUSIC(FMOD_Channel_SetPriority(music_channel, 0)); + FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); + FMR(FMOD_Channel_SetPriority(music_channel, 0)); + return true; } +#endif + + FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); + if (midimode) + FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); + else + FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); + FMR(FMOD_Channel_SetPriority(music_channel, 0)); + current_track = 0; + return true; } -void I_StopSong(INT32 handle) +void I_StopSong(void) { - I_UnRegisterSong(handle); +#ifdef HAVE_LIBGME + if (gme) + gme_delete(gme); + gme = NULL; +#endif + current_track = -1; + + I_UnloadSong(); } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { UNREFERENCED_PARAMETER(handle); if (music_stream)