mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-11-15 01:01:43 +00:00
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)
This commit is contained in:
parent
46b53e8bae
commit
a7ed7b2c90
5 changed files with 242 additions and 296 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
161
src/s_sound.c
161
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -97,6 +97,25 @@ void S_StartSoundAtVolume(const void *origin, sfxenum_t sound_id, INT32 volume);
|
|||
// Stop sound for thing at <origin>
|
||||
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);
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue