Loose ends from previous work

* Pause/ResumeSong remove handle argument
* LoadSong declare char *data argument
* Variable weirdness
This commit is contained in:
mazmazz 2018-08-23 09:36:51 -04:00
parent 3ec1a122e0
commit e89eccf78e
4 changed files with 49 additions and 59 deletions

View File

@ -122,7 +122,7 @@ void I_ShutdownMusic(void);
\return void
*/
void I_PauseSong(INT32 handle);
void I_PauseSong(void);
/** \brief RESUME game handling
@ -130,7 +130,7 @@ void I_PauseSong(INT32 handle);
\return void
*/
void I_ResumeSong(INT32 handle);
void I_ResumeSong(void);
//
// MIDI I/O
@ -153,7 +153,7 @@ void I_SetMIDIMusicVolume(UINT8 volume);
\todo Remove this
*/
boolean I_LoadSong(void *data, size_t len);
boolean I_LoadSong(char *data, size_t len);
/** \brief Called by anything that wishes to start music
@ -164,7 +164,7 @@ boolean I_LoadSong(void *data, size_t len);
\todo pass music name, not handle
*/
boolean I_PlaySong(void);
boolean I_PlaySong(boolean looping);
/** \brief Stops a song over 3 seconds

View File

@ -1316,11 +1316,10 @@ static char music_name[7]; // up to 6-character name
static boolean mus_forcemidi = 0; // force midi even when digital exists
static boolean mus_paused = 0; // whether songs are mus_paused
static boolean S_LoadMusic(const char *mname, boolean looping)
static boolean S_LoadMusic(const char *mname)
{
lumpnum_t mlumpnum;
void *mdata;
INT32 mhandle;
if (nomidimusic || music_disabled)
return false; // didn't search.
@ -1354,7 +1353,7 @@ static boolean S_LoadMusic(const char *mname, boolean looping)
return false;
}
static void S_UnloadSong(void)
static void S_UnloadMusic(void)
{
I_UnloadSong();
music_name[0] = 0;
@ -1365,12 +1364,9 @@ static boolean S_PlayMusic(const char *mname, boolean looping)
if (nodigimusic || digital_disabled)
return false; // try midi
if (!S_LoadSong(mname, looping))
return false;
if (!I_PlaySong())
if (!I_PlaySong(looping))
{
S_UnloadSong();
S_UnloadMusic();
return false;
}
@ -1394,7 +1390,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping)
if (strncmp(music_name, mmusic, 6))
{
S_StopMusic(); // shutdown old music
if (!S_LoadMusic(mmusic, looping) && !S_PlayMusic(mmusic, looping))
if (!S_LoadMusic(mmusic) && !S_PlayMusic(mmusic, looping))
{
CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic);
return;
@ -1414,7 +1410,7 @@ void S_StopMusic(void)
return;
if (mus_paused)
I_ResumeSong(music_handle);
I_ResumeSong();
S_SpeedMusic(1.0f);
I_StopSong();
@ -1424,7 +1420,6 @@ void S_StopMusic(void)
Z_ChangeTag(music_data, PU_CACHE);
#endif
music_data = NULL;
music_name[0] = 0;
if (cv_closedcaptioning.value)
@ -1434,7 +1429,7 @@ void S_StopMusic(void)
}
}
void S_SetMusicVolume(INT32 volume)
void S_SetDigMusicVolume(INT32 volume)
{
if (volume < 0 || volume > 31)
CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n");
@ -1536,11 +1531,11 @@ void S_Start(void)
void S_PauseAudio(void)
{
if (!nodigimusic)
I_PauseSong(0);
I_PauseSong();
if (music_playing && !mus_paused)
{
I_PauseSong(music_handle);
I_PauseSong();
mus_paused = true;
}
@ -1555,11 +1550,11 @@ void S_PauseAudio(void)
void S_ResumeAudio(void)
{
if (!nodigimusic)
I_ResumeSong(0);
I_ResumeSong();
else
if (music_playing && mus_paused)
{
I_ResumeSong(music_handle);
I_ResumeSong();
mus_paused = false;
}

View File

@ -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)
{

View File

@ -491,16 +491,14 @@ void I_ShutdownMusic(void)
music = NULL;
}
void I_PauseSong(INT32 handle)
void I_PauseSong(void)
{
(void)handle;
Mix_PauseMusic();
songpaused = true;
}
void I_ResumeSong(INT32 handle)
void I_ResumeSong(void)
{
(void)handle;
Mix_ResumeMusic();
songpaused = false;
}
@ -570,7 +568,7 @@ boolean I_SetSongTrack(int track)
// MIDI Music
//
boolean I_LoadSong(void *data, size_t len)
boolean I_LoadSong(char *data, size_t len)
{
I_Assert(!music);
#ifdef HAVE_LIBGME
@ -667,6 +665,8 @@ boolean I_LoadSong(void *data, size_t len)
else if (!gme_open_data(data, len, &gme, 44100))
{
gme_equalizer_t eq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0};
gme_set_equalizer(gme, &eq);
Mix_HookMusic(mix_gme, gme);
return true;
}
#endif
@ -680,43 +680,41 @@ boolean I_LoadSong(void *data, size_t len)
// Find the OGG loop point.
loop_point = 0.0f;
if (looping)
const char *key1 = "LOOP";
const char *key2 = "POINT=";
const char *key3 = "MS=";
const size_t key1len = strlen(key1);
const size_t key2len = strlen(key2);
const size_t key3len = strlen(key3);
char *p = data;
while ((UINT32)(p - data) < len)
{
const char *key1 = "LOOP";
const char *key2 = "POINT=";
const char *key3 = "MS=";
const size_t key1len = strlen(key1);
const size_t key2len = strlen(key2);
const size_t key3len = strlen(key3);
char *p = data;
while ((UINT32)(p - data) < len)
if (strncmp(p++, key1, key1len))
continue;
p += key1len-1; // skip OOP (the L was skipped in strncmp)
if (!strncmp(p, key2, key2len)) // is it LOOPPOINT=?
{
if (strncmp(p++, key1, key1len))
continue;
p += key1len-1; // skip OOP (the L was skipped in strncmp)
if (!strncmp(p, key2, key2len)) // is it LOOPPOINT=?
{
p += key2len; // skip POINT=
loop_point = (float)((44.1L+atoi(p)) / 44100.0L); // LOOPPOINT works by sample count.
// because SDL_Mixer is USELESS and can't even tell us
// something simple like the frequency of the streaming music,
// we are unfortunately forced to assume that ALL MUSIC is 44100hz.
// This means a lot of tracks that are only 22050hz for a reasonable downloadable file size will loop VERY badly.
}
else if (!strncmp(p, key3, key3len)) // is it LOOPMS=?
{
p += key3len; // skip MS=
loop_point = (float)(atoi(p) / 1000.0L); // LOOPMS works by real time, as miliseconds.
// Everything that uses LOOPMS will work perfectly with SDL_Mixer.
}
// Neither?! Continue searching.
p += key2len; // skip POINT=
loop_point = (float)((44.1L+atoi(p)) / 44100.0L); // LOOPPOINT works by sample count.
// because SDL_Mixer is USELESS and can't even tell us
// something simple like the frequency of the streaming music,
// we are unfortunately forced to assume that ALL MUSIC is 44100hz.
// This means a lot of tracks that are only 22050hz for a reasonable downloadable file size will loop VERY badly.
}
else if (!strncmp(p, key3, key3len)) // is it LOOPMS=?
{
p += key3len; // skip MS=
loop_point = (float)(atoi(p) / 1000.0L); // LOOPMS works by real time, as miliseconds.
// Everything that uses LOOPMS will work perfectly with SDL_Mixer.
}
// Neither?! Continue searching.
}
return true;
}
boolean I_PlaySong(void)
boolean I_PlaySong(boolean looping)
{
if (!music)
return false;
@ -725,8 +723,6 @@ boolean I_PlaySong(void)
{
gme_start_track(gme, 0);
current_track = 0;
gme_set_equalizer(gme, &eq);
Mix_HookMusic(mix_gme, gme);
return true;
}
#endif
@ -782,7 +778,6 @@ void I_UnloadSong(void)
if (!midimode || !music)
return;
(void)handle;
Mix_FreeMusic(music);
music = NULL;
}