Minor refactoring and reordering

* I_GetMusicType() -> I_MusicType()
* Wrap MIDI volume hack in #ifdef _WIN32

(cherry picked from commit a7d51bf810)
This commit is contained in:
mazmazz 2018-08-23 17:05:37 -04:00
parent 8c78d86c36
commit 5bac836d4c
3 changed files with 174 additions and 161 deletions

View File

@ -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
*/

View File

@ -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:

View File

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