Minor refactoring and reordering

* I_GetMusicType() -> I_MusicType()
* Wrap MIDI volume hack in #ifdef _WIN32
This commit is contained in:
mazmazz 2018-08-23 17:05:37 -04:00
parent f6ec93198f
commit a7d51bf810
3 changed files with 180 additions and 159 deletions

View File

@ -66,9 +66,9 @@ void I_StartupSound(void);
*/ */
void I_ShutdownSound(void); void I_ShutdownSound(void);
// /// ------------------------
// SFX I/O /// SFX I/O
// /// ------------------------
/** \brief Starts a sound in a particular sound channel. /** \brief Starts a sound in a particular sound channel.
\param id sfxid \param id sfxid
@ -120,13 +120,9 @@ void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep, UINT8 pitch);
*/ */
void I_SetSfxVolume(UINT8 volume); void I_SetSfxVolume(UINT8 volume);
// /// ------------------------
// MUSIC I/O // MUSIC SYSTEM
// /// ------------------------
musictype_t I_GetMusicType(void);
boolean I_MusicPlaying(void);
boolean I_MusicPaused(void);
/** \brief Init the music systems /** \brief Init the music systems
*/ */
@ -136,33 +132,23 @@ void I_InitMusic(void);
*/ */
void I_ShutdownMusic(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 /// ------------------------
*/ // MUSIC EFFECTS
void I_PauseSong(void); /// ------------------------
/** \brief RESUME game handling boolean I_SetSongSpeed(float speed);
\param handle song handle /// ------------------------
// MUSIC PLAYBACK
\return void /// ------------------------
*/
void I_ResumeSong(void);
//
// MIDI I/O
//
/** \brief The I_SetMusicVolume function
\param volume volume to set at
\return void
*/
void I_SetMusicVolume(UINT8 volume);
/** \brief Registers a song handle to song data. /** \brief Registers a song handle to song data.
@ -175,6 +161,15 @@ void I_SetMusicVolume(UINT8 volume);
*/ */
boolean I_LoadSong(char *data, size_t len); 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 /** \brief Called by anything that wishes to start music
\param handle Song handle \param handle Song handle
@ -195,27 +190,35 @@ boolean I_PlaySong(boolean looping);
*/ */
void I_StopSong(void); void I_StopSong(void);
/** \brief See ::I_LoadSong, then think backwards /** \brief PAUSE game handling.
\param handle song handle \param handle song handle
\sa I_LoadSong \return void
\todo remove midi handle
*/ */
void I_UnloadSong(void); void I_PauseSong(void);
// /** \brief RESUME game handling
// DIGMUSIC I/O
//
boolean I_SetSongSpeed(float speed); \param handle song handle
\return void
*/
void I_ResumeSong(void);
/** \brief The I_SetMusicVolume function
\param volume volume to set at
\return void
*/
void I_SetMusicVolume(UINT8 volume);
boolean I_SetSongTrack(INT32 track); boolean I_SetSongTrack(INT32 track);
// /// ------------------------
// CD MUSIC I/O // CD MUSIC I/O
// /// ------------------------
/** \brief cd music interface /** \brief cd music interface
*/ */

View File

@ -1381,7 +1381,7 @@ boolean S_MusicPaused(void)
musictype_t S_MusicType(void) musictype_t S_MusicType(void)
{ {
return I_GetMusicType(); return I_MusicType();
} }
boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping) boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping)
@ -1406,7 +1406,7 @@ boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi)
} }
/// ------------------------ /// ------------------------
/// Music Properties /// Music Effects
/// ------------------------ /// ------------------------
boolean S_SpeedMusic(float speed) boolean S_SpeedMusic(float speed)
@ -1415,7 +1415,7 @@ boolean S_SpeedMusic(float speed)
} }
/// ------------------------ /// ------------------------
/// Music Routines /// Music Playback
/// ------------------------ /// ------------------------
static boolean S_LoadMusic(const char *mname) static boolean S_LoadMusic(const char *mname)
@ -1584,7 +1584,7 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume)
digvolume = seqvolume = 31; digvolume = seqvolume = 31;
#endif #endif
switch(I_GetMusicType()) switch(I_MusicType())
{ {
case MU_MID: case MU_MID:
case MU_MOD: case MU_MOD:

View File

@ -72,6 +72,10 @@ static Music_Emu *gme;
static INT32 current_track; static INT32 current_track;
#endif #endif
/// ------------------------
/// Audio System
/// ------------------------
void I_StartupSound(void) void I_StartupSound(void)
{ {
I_Assert(!sound_started); I_Assert(!sound_started);
@ -128,6 +132,10 @@ FUNCMATH void I_UpdateSound(void)
{ {
} }
/// ------------------------
/// SFX
/// ------------------------
// this is as fast as I can possibly make it. // this is as fast as I can possibly make it.
// sorry. more asm needed. // sorry. more asm needed.
static Mix_Chunk *ds2chunk(void *stream) static Mix_Chunk *ds2chunk(void *stream)
@ -430,11 +438,72 @@ void I_SetSfxVolume(UINT8 volume)
sfx_volume = 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 #ifdef HAVE_LIBGME
if (gme) if (gme)
@ -463,74 +532,9 @@ boolean I_MusicPaused(void)
return songpaused; return songpaused;
} }
// Music hooks /// ------------------------
static void music_loop(void) /// Music Effects
{ /// ------------------------
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
//
boolean I_SetSongSpeed(float speed) boolean I_SetSongSpeed(float speed)
{ {
@ -550,40 +554,9 @@ boolean I_SetSongSpeed(float speed)
return false; return false;
} }
boolean I_SetSongTrack(int track) /// ------------------------
{ /// Music Playback
#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) boolean I_LoadSong(char *data, size_t len)
{ {
@ -731,6 +704,12 @@ boolean I_LoadSong(char *data, size_t len)
return true; return true;
} }
void I_UnloadSong(void)
{
Mix_FreeMusic(music);
music = NULL;
}
boolean I_PlaySong(boolean looping) boolean I_PlaySong(boolean looping)
{ {
if (!music) if (!music)
@ -775,25 +754,64 @@ void I_StopSong(void)
music = NULL; music = NULL;
} }
void I_PauseSong(void)
{
Mix_PauseMusic();
songpaused = true;
}
void I_ResumeSong(void)
{
Mix_ResumeMusic();
songpaused = false;
}
void I_SetMusicVolume(UINT8 volume) void I_SetMusicVolume(UINT8 volume)
{ {
if (!music) if (!music)
return; return;
if (I_GetMusicType() == MU_MID) #ifdef _WIN32
if (I_MusicType() == MU_MID)
// HACK: Until we stop using native MIDI, // HACK: Until we stop using native MIDI,
// disable volume changes // disable volume changes
music_volume = 31; music_volume = 31;
else else
#endif
music_volume = volume; music_volume = volume;
Mix_VolumeMusic((UINT32)music_volume*128/31); Mix_VolumeMusic((UINT32)music_volume*128/31);
} }
void I_UnloadSong(void) boolean I_SetSongTrack(int track)
{ {
Mix_FreeMusic(music); #ifdef HAVE_LIBGME
music = NULL; 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 #endif