Merge branch 'public-music-cleanup' into 'master'

Music Code Cleanup

See merge request STJr/SRB2!278
This commit is contained in:
Monster Iestyn 2018-10-20 09:12:09 -04:00
commit 445a6737ea
18 changed files with 1164 additions and 1608 deletions

View file

@ -56,90 +56,87 @@ void I_SetSfxVolume(INT32 volume)
(void)volume; (void)volume;
} }
// /// ------------------------
// MUSIC I/O // MUSIC SYSTEM
// /// ------------------------
UINT8 music_started = 0; UINT8 music_started = 0;
UINT8 digmusic_started = 0;
void I_InitMusic(void){} void I_InitMusic(void){}
void I_ShutdownMusic(void){} void I_ShutdownMusic(void){}
void I_PauseSong(INT32 handle) /// ------------------------
// MUSIC PROPERTIES
/// ------------------------
musictype_t I_SongType(void)
{ {
(void)handle; return MU_NONE;
} }
void I_ResumeSong(INT32 handle) boolean I_SongPlaying(void)
{ {
(void)handle; return false;
} }
// boolean I_SongPaused(void)
// MIDI I/O
//
UINT8 midimusic_started = 0;
void I_InitMIDIMusic(void){}
void I_ShutdownMIDIMusic(void){}
void I_SetMIDIMusicVolume(INT32 volume)
{ {
(void)volume; return false;
} }
INT32 I_RegisterSong(void *data, size_t len) /// ------------------------
{ // MUSIC EFFECTS
(void)data; /// ------------------------
(void)len;
return -1;
}
boolean I_PlaySong(INT32 handle, INT32 looping)
{
(void)handle;
(void)looping;
return false;
}
void I_StopSong(INT32 handle)
{
(void)handle;
}
void I_UnRegisterSong(INT32 handle)
{
(void)handle;
}
//
// DIGMUSIC I/O
//
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;
}
boolean I_SetSongSpeed(float speed) boolean I_SetSongSpeed(float speed)
{ {
(void)speed; (void)speed;
return false; return false;
} }
/// ------------------------
// MUSIC PLAYBACK
/// ------------------------
UINT8 midimusic_started = 0;
boolean I_LoadSong(char *data, size_t len)
{
(void)data;
(void)len;
return -1;
}
void I_UnloadSong()
{
}
boolean I_PlaySong(boolean looping)
{
(void)handle;
(void)looping;
return false;
}
void I_StopSong(void)
{
(void)handle;
}
void I_PauseSong(void)
{
(void)handle;
}
void I_ResumeSong(void)
{
(void)handle;
}
void I_SetMusicVolume(INT32 volume)
{
(void)volume;
}

View file

@ -121,20 +121,17 @@ INT32 postimgparam;
postimg_t postimgtype2 = postimg_none; postimg_t postimgtype2 = postimg_none;
INT32 postimgparam2; INT32 postimgparam2;
#ifdef _XBOX
boolean nomidimusic = true, nosound = true;
boolean nodigimusic = true;
#else
boolean nomidimusic = false, nosound = false;
boolean nodigimusic = false; // No fmod-based music
#endif
// These variables are only true if // These variables are only true if
// the respective sound system is initialized // whether the respective sound system is disabled
// and active, but no sounds/music should play. // or they're init'ed, but the player just toggled them
boolean music_disabled = false; #ifdef _XBOX
boolean midi_disabled = true, sound_disabled = true;
boolean digital_disabled = true;
#else
boolean midi_disabled = false;
boolean sound_disabled = false; boolean sound_disabled = false;
boolean digital_disabled = false; boolean digital_disabled = false;
#endif
boolean advancedemo; boolean advancedemo;
#ifdef DEBUGFILE #ifdef DEBUGFILE
@ -1211,27 +1208,27 @@ void D_SRB2Main(void)
// setting up sound // setting up sound
if (dedicated) if (dedicated)
{ {
nosound = true; sound_disabled = true;
nomidimusic = nodigimusic = true; midi_disabled = digital_disabled = true;
} }
else else
{ {
CONS_Printf("S_Init(): Setting up sound.\n"); CONS_Printf("S_InitSfxChannels(): Setting up sound channels.\n");
} }
if (M_CheckParm("-nosound")) if (M_CheckParm("-nosound"))
nosound = true; sound_disabled = true;
if (M_CheckParm("-nomusic")) // combines -nomidimusic and -nodigmusic if (M_CheckParm("-nomusic")) // combines -nomidimusic and -nodigmusic
nomidimusic = nodigimusic = true; midi_disabled = digital_disabled = true;
else else
{ {
if (M_CheckParm("-nomidimusic")) if (M_CheckParm("-nomidimusic"))
nomidimusic = true; ; // WARNING: DOS version initmusic in I_StartupSound midi_disabled = true; ; // WARNING: DOS version initmusic in I_StartupSound
if (M_CheckParm("-nodigmusic")) if (M_CheckParm("-nodigmusic"))
nodigimusic = true; // WARNING: DOS version initmusic in I_StartupSound digital_disabled = true; // WARNING: DOS version initmusic in I_StartupSound
} }
I_StartupSound(); I_StartupSound();
I_InitMusic(); I_InitMusic();
S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); S_InitSfxChannels(cv_soundvolume.value);
CONS_Printf("ST_Init(): Init status bar.\n"); CONS_Printf("ST_Init(): Init status bar.\n");
ST_Init(); ST_Init();

View file

@ -3955,6 +3955,7 @@ static void Command_RestartAudio_f(void)
return; return;
S_StopMusic(); S_StopMusic();
S_StopSounds();
I_ShutdownMusic(); I_ShutdownMusic();
I_ShutdownSound(); I_ShutdownSound();
I_StartupSound(); I_StartupSound();
@ -3963,11 +3964,9 @@ static void Command_RestartAudio_f(void)
// These must be called or no sound and music until manually set. // These must be called or no sound and music until manually set.
I_SetSfxVolume(cv_soundvolume.value); I_SetSfxVolume(cv_soundvolume.value);
I_SetDigMusicVolume(cv_digmusicvolume.value); S_SetMusicVolume(cv_digmusicvolume.value, cv_midimusicvolume.value);
I_SetMIDIMusicVolume(cv_midimusicvolume.value);
if (Playing()) // Gotta make sure the player is in a level if (Playing()) // Gotta make sure the player is in a level
P_RestoreMusic(&players[consoleplayer]); P_RestoreMusic(&players[consoleplayer]);
} }
/** Quits a game and returns to the title screen. /** Quits a game and returns to the title screen.

View file

@ -134,21 +134,12 @@ FUNCINLINE static ATTRINLINE int Volset(int vol)
void I_SetSfxVolume(INT32 volume) void I_SetSfxVolume(INT32 volume)
{ {
if (nosound) if (sound_disabled)
return; return;
set_volume (Volset(volume),-1); set_volume (Volset(volume),-1);
} }
void I_SetMIDIMusicVolume(INT32 volume)
{
if (nomidimusic)
return;
// Now set volume on output device.
set_volume (-1, Volset(volume));
}
// //
// Starting a sound means adding it // Starting a sound means adding it
// to the current list of active sounds // to the current list of active sounds
@ -171,7 +162,7 @@ INT32 I_StartSound ( sfxenum_t id,
int voice; int voice;
(void)channel; (void)channel;
if (nosound) if (sound_disabled)
return 0; return 0;
// UNUSED // UNUSED
@ -192,7 +183,7 @@ void I_StopSound (INT32 handle)
// an setting the channel to zero. // an setting the channel to zero.
int voice=handle & (VIRTUAL_VOICES-1); int voice=handle & (VIRTUAL_VOICES-1);
if (nosound) if (sound_disabled)
return; return;
if (voice_check(voice)==S_sfx[handle>>VOICESSHIFT].data) if (voice_check(voice)==S_sfx[handle>>VOICESSHIFT].data)
@ -201,7 +192,7 @@ void I_StopSound (INT32 handle)
INT32 I_SoundIsPlaying(INT32 handle) INT32 I_SoundIsPlaying(INT32 handle)
{ {
if (nosound) if (sound_disabled)
return FALSE; return FALSE;
if (voice_check(handle & (VIRTUAL_VOICES-1))==S_sfx[handle>>VOICESSHIFT].data) if (voice_check(handle & (VIRTUAL_VOICES-1))==S_sfx[handle>>VOICESSHIFT].data)
@ -231,7 +222,7 @@ void I_UpdateSoundParams( INT32 handle,
int voice=handle & (VIRTUAL_VOICES-1); int voice=handle & (VIRTUAL_VOICES-1);
int numsfx=handle>>VOICESSHIFT; int numsfx=handle>>VOICESSHIFT;
if (nosound) if (sound_disabled)
return; return;
if (voice_check(voice)==S_sfx[numsfx].data) if (voice_check(voice)==S_sfx[numsfx].data)
@ -272,17 +263,17 @@ void I_StartupSound(void)
char err[255]; char err[255];
#endif #endif
if (nosound) if (sound_disabled)
sfxcard=DIGI_NONE; sfxcard=DIGI_NONE;
else else
sfxcard=DIGI_AUTODETECT; sfxcard=DIGI_AUTODETECT;
if (nomidimusic) if (midi_disabled)
midicard=MIDI_NONE; midicard=MIDI_NONE;
else else
midicard=MIDI_AUTODETECT; //DetectMusicCard(); midicard=MIDI_AUTODETECT; //DetectMusicCard();
nodigimusic=true; //Alam: No OGG/MP3/IT/MOD support digital_disabled=true; //Alam: No OGG/MP3/IT/MOD support
// Secure and configure sound device first. // Secure and configure sound device first.
CONS_Printf("I_StartupSound: "); CONS_Printf("I_StartupSound: ");
@ -295,8 +286,8 @@ void I_StartupSound(void)
{ {
sprintf (err,"Sound init error : %s\n",allegro_error); sprintf (err,"Sound init error : %s\n",allegro_error);
CONS_Error (err); CONS_Error (err);
nosound=true; sound_disabled=true;
nomidimusic=true; midi_disabled=true;
} }
else else
{ {
@ -323,7 +314,11 @@ static MIDI* currsong; //im assuming only 1 song will be played at once
static int islooping=0; static int islooping=0;
static int musicdies=-1; static int musicdies=-1;
UINT8 music_started=0; UINT8 music_started=0;
boolean songpaused=false;
/// ------------------------
// MUSIC SYSTEM
/// ------------------------
/* load_midi_mem: /* load_midi_mem:
* Loads a standard MIDI file from memory, returning a pointer to * Loads a standard MIDI file from memory, returning a pointer to
@ -391,116 +386,66 @@ static MIDI *load_midi_mem(char *mempointer,int *e)
return midi; return midi;
} }
void I_InitMIDIMusic(void) void I_InitMusic(void)
{ {
if (nomidimusic) if (midi_disabled)
return; return;
I_AddExitFunc(I_ShutdownMusic); I_AddExitFunc(I_ShutdownMusic);
music_started = true; music_started = true;
} songpaused = false;
void I_ShutdownMIDIMusic(void)
{
if ( !music_started )
return;
I_StopSong(1);
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) void I_ShutdownMusic(void)
{ {
I_ShutdownMIDIMusic(); if ( !music_started )
I_ShutdownDigMusic(); return;
I_StopSong();
music_started=false;
} }
boolean I_PlaySong(INT32 handle, INT32 looping) /// ------------------------
{ // MUSIC PROPERTIES
handle = 0; /// ------------------------
if (nomidimusic)
return false;
islooping = looping; musictype_t I_SongType(void)
musicdies = gametic + NEWTICRATE*30; {
if (play_midi(currsong,looping)==0) if (currsong)
return true; return MU_MID;
else
return MU_NONE;
}
boolean I_SongPlaying()
{
return (boolean)currsong;
}
boolean I_SongPaused()
{
return songpaused;
}
/// ------------------------
// MUSIC EFFECTS
/// ------------------------
boolean I_SetSongSpeed(float speed)
{
(void)speed;
return false; return false;
} }
void I_PauseSong (INT32 handle) /// ------------------------
{ // MUSIC PLAYBACK
handle = 0; /// ------------------------
if (nomidimusic)
return;
midi_pause(); boolean I_LoadSong(char *data, size_t len)
}
void I_ResumeSong (INT32 handle)
{
handle = 0;
if (nomidimusic)
return;
midi_resume();
}
void I_StopSong(INT32 handle)
{
handle = 0;
if (nomidimusic)
return;
islooping = 0;
musicdies = 0;
stop_midi();
}
// Is the song playing?
#if 0
int I_QrySongPlaying(int handle)
{
if (nomidimusic)
return 0;
//return islooping || musicdies > gametic;
return (midi_pos==-1);
}
#endif
void I_UnRegisterSong(INT32 handle)
{
handle = 0;
if (nomidimusic)
return;
//destroy_midi(currsong);
}
INT32 I_RegisterSong(void *data, size_t len)
{ {
int e = len; //Alam: For error int e = len; //Alam: For error
if (nomidimusic) if (midi_disabled)
return 0; return 0;
if (memcmp(data,"MThd",4)==0) // support mid file in WAD !!! if (memcmp(data,"MThd",4)==0) // support mid file in WAD !!!
@ -522,32 +467,81 @@ INT32 I_RegisterSong(void *data, size_t len)
return 1; return 1;
} }
/// \todo Add OGG/MP3 support for dos void I_UnloadSong(void)
boolean I_StartDigSong(const char *musicname, INT32 looping)
{ {
musicname = NULL; handle = 0;
looping = 0; if (midi_disabled)
//CONS_Printf("I_StartDigSong: Not yet supported under DOS.\n"); return;
//destroy_midi(currsong);
}
boolean I_PlaySong(boolean looping)
{
handle = 0;
if (midi_disabled)
return false;
islooping = looping;
musicdies = gametic + NEWTICRATE*30;
if (play_midi(currsong,looping)==0)
return true;
return false; return false;
} }
void I_StopDigSong(void) void I_StopSong(void)
{ {
// CONS_Printf("I_StopDigSong: Not yet supported under DOS.\n"); handle = 0;
if (midi_disabled)
return;
islooping = 0;
musicdies = 0;
stop_midi();
songpaused = false;
} }
void I_SetDigMusicVolume(INT32 volume) void I_PauseSong (INT32 handle)
{ {
volume = 0; handle = 0;
if (nodigimusic) if (midi_disabled)
return;
midi_pause();
songpaused = true;
}
void I_ResumeSong (INT32 handle)
{
handle = 0;
if (midi_disabled)
return;
midi_resume();
songpaused = false;
}
void I_SetMusicVolume(INT32 volume)
{
if (midi_disabled)
return; return;
// Now set volume on output device. // Now set volume on output device.
// CONS_Printf("Digital music not yet supported under DOS.\n"); set_volume (-1, Volset(volume));
} }
boolean I_SetSongSpeed(float speed) boolean I_SetSongTrack(INT32 track)
{ {
(void)speed; (void)track;
return false; return false;
} }
// Is the song playing?
#if 0
int I_QrySongPlaying(int handle)
{
if (midi_disabled)
return 0;
//return islooping || musicdies > gametic;
return (midi_pos==-1);
}
#endif

View file

@ -85,10 +85,7 @@ extern boolean fromlevelselect;
// Internal parameters for sound rendering. // Internal parameters for sound rendering.
// ======================================== // ========================================
extern boolean nomidimusic; // defined in d_main.c extern boolean midi_disabled;
extern boolean nosound;
extern boolean nodigimusic;
extern boolean music_disabled;
extern boolean sound_disabled; extern boolean sound_disabled;
extern boolean digital_disabled; extern boolean digital_disabled;

View file

@ -58,82 +58,36 @@ void I_SetSfxVolume(UINT8 volume)
(void)volume; (void)volume;
} }
// /// ------------------------
// MUSIC I/O // MUSIC SYSTEM
// /// ------------------------
void I_InitMusic(void){} void I_InitMusic(void){}
void I_ShutdownMusic(void){} void I_ShutdownMusic(void){}
void I_PauseSong(INT32 handle) /// ------------------------
// MUSIC PROPERTIES
/// ------------------------
musictype_t I_SongType(void)
{ {
(void)handle; return MU_NONE;
} }
void I_ResumeSong(INT32 handle) boolean I_SongPlaying(void)
{ {
(void)handle;
}
//
// MIDI I/O
//
void I_InitMIDIMusic(void){}
void I_ShutdownMIDIMusic(void){}
void I_SetMIDIMusicVolume(UINT8 volume)
{
(void)volume;
}
INT32 I_RegisterSong(void *data, size_t len)
{
(void)data;
(void)len;
return -1;
}
boolean I_PlaySong(INT32 handle, boolean looping)
{
(void)handle;
(void)looping;
return false; return false;
} }
void I_StopSong(INT32 handle) boolean I_SongPaused(void)
{ {
(void)handle;
}
void I_UnRegisterSong(INT32 handle)
{
(void)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; return false;
} }
void I_StopDigSong(void){} /// ------------------------
// MUSIC EFFECTS
void I_SetDigMusicVolume(UINT8 volume) /// ------------------------
{
(void)volume;
}
boolean I_SetSongSpeed(float speed) boolean I_SetSongSpeed(float speed)
{ {
@ -141,6 +95,49 @@ boolean I_SetSongSpeed(float speed)
return false; return false;
} }
/// ------------------------
// MUSIC PLAYBACK
/// ------------------------
boolean I_LoadSong(char *data, size_t len)
{
(void)data;
(void)len;
return -1;
}
void I_UnloadSong(void)
{
(void)handle;
}
boolean I_PlaySong(boolean looping)
{
(void)handle;
(void)looping;
return false;
}
void I_StopSong(void)
{
(void)handle;
}
void I_PauseSong(void)
{
(void)handle;
}
void I_ResumeSong(void)
{
(void)handle;
}
void I_SetMusicVolume(UINT8 volume)
{
(void)volume;
}
boolean I_SetSongTrack(int track) boolean I_SetSongTrack(int track)
{ {
(void)track; (void)track;

View file

@ -361,7 +361,7 @@ INT32 HW3S_I_StartSound(const void *origin_p, source3D_data_t *source_parm, chan
if (splitscreen) listenmobj2 = players[secondarydisplayplayer].mo; if (splitscreen) listenmobj2 = players[secondarydisplayplayer].mo;
if (nosound) if (sound_disabled)
return -1; return -1;
sfx = &S_sfx[sfx_id]; sfx = &S_sfx[sfx_id];

View file

@ -18,6 +18,21 @@
#include "sounds.h" #include "sounds.h"
#include "command.h" #include "command.h"
// copied from SDL mixer, plus GME
typedef enum {
MU_NONE,
MU_CMD,
MU_WAV,
MU_MOD,
MU_MID,
MU_OGG,
MU_MP3,
MU_MP3_MAD_UNUSED, // use MU_MP3 instead
MU_FLAC,
MU_MODPLUG_UNUSED, // use MU_MOD instead
MU_GME
} musictype_t;
/** \brief Sound subsystem runing and waiting /** \brief Sound subsystem runing and waiting
*/ */
extern UINT8 sound_started; extern UINT8 sound_started;
@ -51,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
@ -105,9 +120,10 @@ 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
// /// ------------------------
/** \brief Init the music systems /** \brief Init the music systems
*/ */
void I_InitMusic(void); void I_InitMusic(void);
@ -116,41 +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_SongType(void);
boolean I_SongPlaying(void);
boolean I_SongPaused(void);
\return void /// ------------------------
*/ // MUSIC EFFECTS
void I_PauseSong(INT32 handle); /// ------------------------
/** \brief RESUME game handling boolean I_SetSongSpeed(float speed);
\param handle song handle /// ------------------------
// MUSIC PLAYBACK
\return void /// ------------------------
*/
void I_ResumeSong(INT32 handle);
//
// 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
\return void
*/
void I_SetMIDIMusicVolume(UINT8 volume);
/** \brief Registers a song handle to song data. /** \brief Registers a song handle to song data.
@ -161,7 +159,16 @@ void I_SetMIDIMusicVolume(UINT8 volume);
\todo Remove this \todo Remove this
*/ */
INT32 I_RegisterSong(void *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
@ -172,7 +179,7 @@ INT32 I_RegisterSong(void *data, size_t len);
\todo pass music name, not handle \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 /** \brief Stops a song over 3 seconds
@ -181,58 +188,37 @@ boolean I_PlaySong(INT32 handle, boolean looping);
/todo drop handle /todo drop handle
*/ */
void I_StopSong(INT32 handle); void I_StopSong(void);
/** \brief See ::I_RegisterSong, then think backwards /** \brief PAUSE game handling.
\param handle song handle \param handle song handle
\sa I_RegisterSong \return void
\todo remove midi handle
*/ */
void I_UnRegisterSong(INT32 handle); void I_PauseSong(void);
// /** \brief RESUME game handling
// DIGMUSIC I/O
//
/** \brief Startup the music system \param handle song handle
\return void
*/ */
void I_InitDigMusic(void); void I_ResumeSong(void);
/** \brief Shutdown the music system /** \brief The I_SetMusicVolume function
*/
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 \param volume volume to set at
\return void \return void
*/ */
void I_SetDigMusicVolume(UINT8 volume); void I_SetMusicVolume(UINT8 volume);
// boolean I_SetSongTrack(INT32 track);
// CD MUSIC I/O
//
/// ------------------------
// CD MUSIC I/O
/// ------------------------
/** \brief cd music interface /** \brief cd music interface
*/ */

View file

@ -6950,82 +6950,95 @@ static void M_ChangeControl(INT32 choice)
// Toggles sound systems in-game. // Toggles sound systems in-game.
static void M_ToggleSFX(void) static void M_ToggleSFX(void)
{ {
if (nosound) if (sound_disabled)
{ {
nosound = false; sound_disabled = false;
I_StartupSound(); S_InitSfxChannels(cv_soundvolume.value);
if (nosound) return; S_StartSound(NULL, sfx_strpst);
S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value);
M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING);
} }
else else
{ {
if (sound_disabled) sound_disabled = true;
{ S_StopSounds();
sound_disabled = false; M_StartMessage(M_GetText("SFX Disabled\n"), NULL, MM_NOTHING);
M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING);
}
else
{
sound_disabled = true;
S_StopSounds();
M_StartMessage(M_GetText("SFX Disabled\n"), NULL, MM_NOTHING);
}
} }
} }
static void M_ToggleDigital(void) static void M_ToggleDigital(void)
{ {
if (nodigimusic) if (digital_disabled)
{ {
nodigimusic = false; digital_disabled = false;
I_InitDigMusic(); I_InitMusic();
if (nodigimusic) return;
S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value);
S_StopMusic(); S_StopMusic();
S_ChangeMusicInternal("lclear", false); if (Playing())
P_RestoreMusic(&players[consoleplayer]);
else
S_ChangeMusicInternal("lclear", false);
M_StartMessage(M_GetText("Digital Music Enabled\n"), NULL, MM_NOTHING); M_StartMessage(M_GetText("Digital Music Enabled\n"), NULL, MM_NOTHING);
} }
else else
{ {
if (digital_disabled) digital_disabled = true;
if (S_MusicType() != MU_MID)
{ {
digital_disabled = false; if (midi_disabled)
M_StartMessage(M_GetText("Digital Music Enabled\n"), NULL, MM_NOTHING); S_StopMusic();
} else
else {
{ char mmusic[7];
digital_disabled = true; UINT16 mflags;
S_StopMusic(); boolean looping;
M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING);
if (S_MusicInfo(mmusic, &mflags, &looping) && S_MIDIExists(mmusic))
{
S_StopMusic();
S_ChangeMusic(mmusic, mflags, looping);
}
else
S_StopMusic();
}
} }
M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING);
} }
} }
static void M_ToggleMIDI(void) static void M_ToggleMIDI(void)
{ {
if (nomidimusic) if (midi_disabled)
{ {
nomidimusic = false; midi_disabled = false;
I_InitMIDIMusic(); I_InitMusic();
if (nomidimusic) return; if (Playing())
S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); P_RestoreMusic(&players[consoleplayer]);
S_ChangeMusicInternal("lclear", false); else
S_ChangeMusicInternal("lclear", false);
M_StartMessage(M_GetText("MIDI Music Enabled\n"), NULL, MM_NOTHING); M_StartMessage(M_GetText("MIDI Music Enabled\n"), NULL, MM_NOTHING);
} }
else else
{ {
if (music_disabled) midi_disabled = true;
if (S_MusicType() == MU_MID)
{ {
music_disabled = false; if (digital_disabled)
M_StartMessage(M_GetText("MIDI Music Enabled\n"), NULL, MM_NOTHING); S_StopMusic();
} else
else {
{ char mmusic[7];
music_disabled = true; UINT16 mflags;
S_StopMusic(); boolean looping;
M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING);
if (S_MusicInfo(mmusic, &mflags, &looping) && S_DigExists(mmusic))
{
S_StopMusic();
S_ChangeMusic(mmusic, mflags, looping);
}
else
S_StopMusic();
}
} }
M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING);
} }
} }

View file

@ -8231,7 +8231,7 @@ void P_PrecipitationEffects(void)
if (!playeringame[displayplayer] || !players[displayplayer].mo) if (!playeringame[displayplayer] || !players[displayplayer].mo)
return; return;
if (nosound || sound_disabled) if (sound_disabled)
return; // Sound off? D'aw, no fun. return; // Sound off? D'aw, no fun.
if (players[displayplayer].mo->subsector->sector->ceilingpic == skyflatnum) if (players[displayplayer].mo->subsector->sector->ceilingpic == skyflatnum)

View file

@ -226,7 +226,7 @@ void S_RegisterSoundStuff(void)
{ {
if (dedicated) if (dedicated)
{ {
nosound = true; sound_disabled = true;
return; return;
} }
@ -400,7 +400,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume)
mobj_t *listenmobj = players[displayplayer].mo; mobj_t *listenmobj = players[displayplayer].mo;
mobj_t *listenmobj2 = NULL; mobj_t *listenmobj2 = NULL;
if (sound_disabled || !sound_started || nosound) if (sound_disabled || !sound_started)
return; return;
// Don't want a sound? Okay then... // Don't want a sound? Okay then...
@ -716,7 +716,7 @@ void S_UpdateSounds(void)
return; return;
} }
if (dedicated || nosound) if (dedicated || sound_disabled)
return; return;
if (players[displayplayer].awayviewtics) if (players[displayplayer].awayviewtics)
@ -1151,6 +1151,43 @@ void S_StartSoundName(void *mo, const char *soundname)
S_StartSound(mo, soundnum); S_StartSound(mo, soundnum);
} }
//
// Initializes sound stuff, including volume
// Sets channels, SFX volume,
// allocates channel buffer, sets S_sfx lookup.
//
void S_InitSfxChannels(INT32 sfxVolume)
{
INT32 i;
if (dedicated)
return;
S_SetSfxVolume(sfxVolume);
SetChannelsNum();
// Note that sounds have not been cached (yet).
for (i = 1; i < NUMSFX; i++)
{
S_sfx[i].usefulness = -1; // for I_GetSfx()
S_sfx[i].lumpnum = LUMPERROR;
}
// precache sounds if requested by cmdline, or precachesound var true
if (!sound_disabled && (M_CheckParm("-precachesound") || precachesound.value))
{
// Initialize external data (all sounds) at start, keep static.
CONS_Printf(M_GetText("Loading sounds... "));
for (i = 1; i < NUMSFX; i++)
if (S_sfx[i].name)
S_sfx[i].data = I_GetSfx(&S_sfx[i]);
CONS_Printf(M_GetText(" pre-cached all sound data\n"));
}
}
/// ------------------------ /// ------------------------
/// Music /// Music
/// ------------------------ /// ------------------------
@ -1177,31 +1214,109 @@ const char *compat_special_music_slots[16] =
}; };
#endif #endif
#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 char music_name[7]; // up to 6-character name
static lumpnum_t music_lumpnum; // lump number of music (used??) static void *music_data;
static void *music_data; // music raw data static UINT16 music_flags;
static INT32 music_handle; // once registered, the handle for the music static boolean music_looping;
static boolean mus_paused = 0; // whether songs are mus_paused /// ------------------------
/// Music Status
/// ------------------------
static boolean S_MIDIMusic(const char *mname, boolean looping) boolean S_DigMusicDisabled(void)
{
return digital_disabled;
}
boolean S_MIDIMusicDisabled(void)
{
return midi_disabled;
}
boolean S_MusicDisabled(void)
{
return (midi_disabled && digital_disabled);
}
boolean S_MusicPlaying(void)
{
return I_SongPlaying();
}
boolean S_MusicPaused(void)
{
return I_SongPaused();
}
musictype_t S_MusicType(void)
{
return I_SongType();
}
boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping)
{
if (!I_SongPlaying())
return false;
strncpy(mname, music_name, 7);
mname[6] = 0;
*mflags = music_flags;
*looping = music_looping;
return (boolean)mname[0];
}
boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi)
{
return (
(checkDigi ? W_CheckNumForName(va("O_%s", mname)) != LUMPERROR : false)
|| (checkMIDI ? W_CheckNumForName(va("D_%s", mname)) != LUMPERROR : false)
);
}
/// ------------------------
/// Music Effects
/// ------------------------
boolean S_SpeedMusic(float speed)
{
return I_SetSongSpeed(speed);
}
/// ------------------------
/// Music Playback
/// ------------------------
static boolean S_LoadMusic(const char *mname)
{ {
lumpnum_t mlumpnum; lumpnum_t mlumpnum;
void *mdata; void *mdata;
INT32 mhandle;
if (nomidimusic || music_disabled) if (S_MusicDisabled())
return false; // didn't search.
if (W_CheckNumForName(va("d_%s", mname)) == LUMPERROR)
return false; return false;
mlumpnum = W_GetNumForName(va("d_%s", mname));
if (!S_DigMusicDisabled() && S_DigExists(mname))
mlumpnum = W_GetNumForName(va("o_%s", mname));
else if (!S_MIDIMusicDisabled() && S_MIDIExists(mname))
mlumpnum = W_GetNumForName(va("d_%s", mname));
else if (S_DigMusicDisabled() && S_DigExists(mname))
{
CONS_Alert(CONS_NOTICE, "Digital music is disabled!\n");
return false;
}
else if (S_MIDIMusicDisabled() && S_MIDIExists(mname))
{
CONS_Alert(CONS_NOTICE, "MIDI music is disabled!\n");
return false;
}
else
{
CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mname);
return false;
}
// load & register it // load & register it
mdata = W_CacheLumpNum(mlumpnum, PU_MUSIC); mdata = W_CacheLumpNum(mlumpnum, PU_MUSIC);
mhandle = I_RegisterSong(mdata, W_LumpLength(mlumpnum));
#ifdef MUSSERV #ifdef MUSSERV
if (msg_id != -1) if (msg_id != -1)
@ -1215,31 +1330,43 @@ static boolean S_MIDIMusic(const char *mname, boolean looping)
} }
#endif #endif
// play it if (I_LoadSong(mdata, W_LumpLength(mlumpnum)))
if (!I_PlaySong(mhandle, looping)) {
strncpy(music_name, mname, 7);
music_name[6] = 0;
music_data = mdata;
return true;
}
else
return false; return false;
strncpy(music_name, mname, 7);
music_name[6] = 0;
music_lumpnum = mlumpnum;
music_data = mdata;
music_handle = mhandle;
return true;
} }
static boolean S_DigMusic(const char *mname, boolean looping) static void S_UnloadMusic(void)
{ {
if (nodigimusic || digital_disabled) I_UnloadSong();
return false; // try midi
if (!I_StartDigSong(mname, looping)) #ifndef HAVE_SDL //SDL uses RWOPS
Z_ChangeTag(music_data, PU_CACHE);
#endif
music_data = NULL;
music_name[0] = 0;
music_flags = 0;
music_looping = false;
}
static boolean S_PlayMusic(boolean looping)
{
if (S_MusicDisabled())
return false; return false;
strncpy(music_name, mname, 7); if (!I_PlaySong(looping))
music_name[6] = 0; {
music_lumpnum = LUMPERROR; S_UnloadMusic();
music_data = NULL; return false;
music_handle = 0; }
S_InitMusicVolume(); // switch between digi and sequence volume
return true; return true;
} }
@ -1249,7 +1376,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping)
S_ClearSfx(); S_ClearSfx();
#endif #endif
if ((nomidimusic || music_disabled) && (nodigimusic || digital_disabled)) if (S_MusicDisabled())
return; return;
// No Music (empty string) // No Music (empty string)
@ -1259,121 +1386,105 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping)
return; return;
} }
if (strncmp(music_name, mmusic, 6)) if (strnicmp(music_name, mmusic, 6))
{ {
S_StopMusic(); // shutdown old music S_StopMusic(); // shutdown old music
if (!S_DigMusic(mmusic, looping) && !S_MIDIMusic(mmusic, looping))
if (!S_LoadMusic(mmusic))
{ {
CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic); CONS_Alert(CONS_ERROR, "Music %.6s could not be loaded!\n", mmusic);
return;
}
music_flags = mflags;
music_looping = looping;
if (!S_PlayMusic(looping))
{
CONS_Alert(CONS_ERROR, "Music %.6s could not be played!\n", mmusic);
return; return;
} }
} }
I_SetSongTrack(mflags & MUSIC_TRACKMASK); I_SetSongTrack(mflags & MUSIC_TRACKMASK);
} }
boolean S_SpeedMusic(float speed)
{
return I_SetSongSpeed(speed);
}
void S_StopMusic(void) void S_StopMusic(void)
{ {
if (!music_playing) if (!I_SongPlaying())
return; return;
if (mus_paused) if (I_SongPaused())
I_ResumeSong(music_handle); I_ResumeSong();
if (!nodigimusic)
I_StopDigSong();
S_SpeedMusic(1.0f); S_SpeedMusic(1.0f);
I_StopSong(music_handle); I_StopSong();
I_UnRegisterSong(music_handle); S_UnloadMusic(); // for now, stopping also means you unload the song
#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) //
// Stop and resume music, during game PAUSE.
//
void S_PauseAudio(void)
{ {
if (volume < 0 || volume > 31) if (I_SongPlaying() && !I_SongPaused())
CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n"); I_PauseSong();
CV_SetValue(&cv_digmusicvolume, volume&31); // pause cd music
#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL)
I_PauseCD();
#else
I_StopCD();
#endif
}
void S_ResumeAudio(void)
{
if (I_SongPlaying() && I_SongPaused())
I_ResumeSong();
// resume cd music
I_ResumeCD();
}
void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume)
{
if (digvolume < 0)
digvolume = cv_digmusicvolume.value;
if (seqvolume < 0)
seqvolume = cv_midimusicvolume.value;
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 actualdigmusicvolume = cv_digmusicvolume.value; //check for change of var
#ifdef DJGPPDOS if (seqvolume < 0 || seqvolume > 31)
I_SetDigMusicVolume(31); // Trick for buggy dos drivers. Win32 doesn't need this. CONS_Alert(CONS_WARNING, "midimusicvolume should be between 0-31\n");
#endif CV_SetValue(&cv_midimusicvolume, seqvolume&31);
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);
actualmidimusicvolume = cv_midimusicvolume.value; //check for change of var actualmidimusicvolume = cv_midimusicvolume.value; //check for change of var
#ifdef DJGPPDOS #ifdef DJGPPDOS
I_SetMIDIMusicVolume(31); // Trick for buggy dos drivers. Win32 doesn't need this. digvolume = seqvolume = 31;
#endif #endif
I_SetMIDIMusicVolume(volume&0x1f);
switch(I_SongType())
{
case MU_MID:
//case MU_MOD:
//case MU_GME:
I_SetMusicVolume(seqvolume&31);
break;
default:
I_SetMusicVolume(digvolume&31);
break;
}
} }
/// ------------------------ /// ------------------------
/// Init & Others /// Init & Others
/// ------------------------ /// ------------------------
//
// Initializes sound stuff, including volume
// Sets channels, SFX and music volume,
// allocates channel buffer, sets S_sfx lookup.
//
void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume)
{
INT32 i;
if (dedicated)
return;
S_SetSfxVolume(sfxVolume);
S_SetDigMusicVolume(digMusicVolume);
S_SetMIDIMusicVolume(midiMusicVolume);
SetChannelsNum();
// no sounds are playing, and they are not mus_paused
mus_paused = 0;
// Note that sounds have not been cached (yet).
for (i = 1; i < NUMSFX; i++)
{
S_sfx[i].usefulness = -1; // for I_GetSfx()
S_sfx[i].lumpnum = LUMPERROR;
}
// precache sounds if requested by cmdline, or precachesound var true
if (!nosound && (M_CheckParm("-precachesound") || precachesound.value))
{
// Initialize external data (all sounds) at start, keep static.
CONS_Printf(M_GetText("Loading sounds... "));
for (i = 1; i < NUMSFX; i++)
if (S_sfx[i].name)
S_sfx[i].data = I_GetSfx(&S_sfx[i]);
CONS_Printf(M_GetText(" pre-cached all sound data\n"));
}
}
// //
// Per level startup code. // Per level startup code.
// Kills playing sounds at start of level, // Kills playing sounds at start of level,
@ -1388,46 +1499,7 @@ void S_Start(void)
mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK);
} }
mus_paused = 0;
if (cv_resetmusic.value) if (cv_resetmusic.value)
S_StopMusic(); S_StopMusic();
S_ChangeMusic(mapmusname, mapmusflags, true); S_ChangeMusic(mapmusname, mapmusflags, true);
} }
//
// Stop and resume music, during game PAUSE.
//
void S_PauseAudio(void)
{
if (!nodigimusic)
I_PauseSong(0);
if (music_playing && !mus_paused)
{
I_PauseSong(music_handle);
mus_paused = true;
}
// pause cd music
#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL)
I_PauseCD();
#else
I_StopCD();
#endif
}
void S_ResumeAudio(void)
{
if (!nodigimusic)
I_ResumeSong(0);
else
if (music_playing && mus_paused)
{
I_ResumeSong(music_handle);
mus_paused = false;
}
// resume cd music
I_ResumeCD();
}

View file

@ -14,6 +14,7 @@
#ifndef __S_SOUND__ #ifndef __S_SOUND__
#define __S_SOUND__ #define __S_SOUND__
#include "i_sound.h" // musictype_t
#include "sounds.h" #include "sounds.h"
#include "m_fixed.h" #include "m_fixed.h"
#include "command.h" #include "command.h"
@ -69,9 +70,9 @@ void S_RegisterSoundStuff(void);
// //
// Initializes sound stuff, including volume // Initializes sound stuff, including volume
// Sets channels, SFX and music volume, allocates channel buffer, sets S_sfx lookup. // Sets channels, SFX, allocates channel buffer, sets S_sfx lookup.
// //
void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume); void S_InitSfxChannels(INT32 sfxVolume);
// //
// Per level startup code. // Per level startup code.
@ -97,6 +98,33 @@ void S_StartSoundAtVolume(const void *origin, sfxenum_t sound_id, INT32 volume);
// Stop sound for thing at <origin> // Stop sound for thing at <origin>
void S_StopSound(void *origin); void S_StopSound(void *origin);
//
// Music Status
//
boolean S_DigMusicDisabled(void);
boolean S_MIDIMusicDisabled(void);
boolean S_MusicDisabled(void);
boolean S_MusicPlaying(void);
boolean S_MusicPaused(void);
musictype_t S_MusicType(void);
boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping);
boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi);
#define S_DigExists(a) S_MusicExists(a, false, true)
#define S_MIDIExists(a) S_MusicExists(a, true, false)
//
// Music Properties
//
// Set Speed of Music
boolean S_SpeedMusic(float speed);
//
// Music Routines
//
// Start music track, arbitrary, given its name, and set whether looping // 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) // note: music flags 12 bits for tracknum (gme, other formats with more than one track)
// 13-15 aren't used yet // 13-15 aren't used yet
@ -104,9 +132,6 @@ void S_StopSound(void *origin);
#define S_ChangeMusicInternal(a,b) S_ChangeMusic(a,0,b) #define S_ChangeMusicInternal(a,b) S_ChangeMusic(a,0,b)
void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping); void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping);
// Set Speed of Music
boolean S_SpeedMusic(float speed);
// Stops the music. // Stops the music.
void S_StopMusic(void); void S_StopMusic(void);
@ -121,9 +146,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); 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_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_OriginPlaying(void *origin);
INT32 S_IdPlaying(sfxenum_t id); INT32 S_IdPlaying(sfxenum_t id);

View file

@ -566,7 +566,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
// Tell game we got focus back, resume music if necessary // Tell game we got focus back, resume music if necessary
window_notinfocus = false; window_notinfocus = false;
if (!paused) if (!paused)
I_ResumeSong(0); //resume it I_ResumeSong(); //resume it
if (!firsttimeonmouse) if (!firsttimeonmouse)
{ {
@ -578,7 +578,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
{ {
// Tell game we lost focus, pause music // Tell game we lost focus, pause music
window_notinfocus = true; window_notinfocus = true;
I_PauseSong(0); I_PauseSong();
if (!disable_mouse) if (!disable_mouse)
{ {

View file

@ -34,6 +34,12 @@
(SDL_MIXER_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z)) (SDL_MIXER_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z))
#endif #endif
// thanks alam for making the buildbots happy!
#if SDL_MIXER_VERSION_ATLEAST(2,0,2)
#define MUS_MP3_MAD MUS_MP3_MAD_UNUSED
#define MUS_MODPLUG MUS_MODPLUG_UNUSED
#endif
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
#include "gme/gme.h" #include "gme/gme.h"
#define GME_TREBLE 5.0 #define GME_TREBLE 5.0
@ -60,9 +66,8 @@
UINT8 sound_started = false; UINT8 sound_started = false;
static boolean midimode;
static Mix_Music *music; static Mix_Music *music;
static UINT8 music_volume, midi_volume, sfx_volume; static UINT8 music_volume, sfx_volume;
static float loop_point; static float loop_point;
static boolean songpaused; static boolean songpaused;
@ -71,13 +76,20 @@ 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);
// EE inits audio first so we're following along. // EE inits audio first so we're following along.
if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO) if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO)
CONS_Printf("SDL Audio already started\n"); {
CONS_Debug(DBG_DETAILED, "SDL Audio already started\n");
return;
}
else if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) else if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
{ {
CONS_Alert(CONS_ERROR, "Error initializing SDL Audio: %s\n", SDL_GetError()); CONS_Alert(CONS_ERROR, "Error initializing SDL Audio: %s\n", SDL_GetError());
@ -85,9 +97,8 @@ void I_StartupSound(void)
return; return;
} }
midimode = false;
music = NULL; music = NULL;
music_volume = midi_volume = sfx_volume = 0; music_volume = sfx_volume = 0;
#if SDL_MIXER_VERSION_ATLEAST(1,2,11) #if SDL_MIXER_VERSION_ATLEAST(1,2,11)
Mix_Init(MIX_INIT_FLAC|MIX_INIT_MOD|MIX_INIT_MP3|MIX_INIT_OGG); Mix_Init(MIX_INIT_FLAC|MIX_INIT_MOD|MIX_INIT_MP3|MIX_INIT_OGG);
@ -128,6 +139,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)
@ -453,11 +468,10 @@ void I_SetSfxVolume(UINT8 volume)
sfx_volume = volume; sfx_volume = volume;
} }
// /// ------------------------
// Music /// Music Hooks
// /// ------------------------
// Music hooks
static void music_loop(void) static void music_loop(void)
{ {
Mix_PlayMusic(music, 0); Mix_PlayMusic(music, 0);
@ -485,79 +499,101 @@ static void mix_gme(void *udata, Uint8 *stream, int len)
} }
#endif #endif
/// ------------------------
/// Music System
/// ------------------------
FUNCMATH void I_InitMusic(void) FUNCMATH void I_InitMusic(void)
{ {
} }
void I_ShutdownMusic(void) void I_ShutdownMusic(void)
{ {
I_ShutdownDigMusic(); I_UnloadSong();
I_ShutdownMIDIMusic();
} }
void I_PauseSong(INT32 handle) /// ------------------------
{ /// Music Properties
(void)handle; /// ------------------------
Mix_PauseMusic();
songpaused = true;
}
void I_ResumeSong(INT32 handle) musictype_t I_SongType(void)
{
(void)handle;
Mix_ResumeMusic();
songpaused = false;
}
//
// Digital Music
//
void I_InitDigMusic(void)
{ {
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
gme = NULL; if (gme)
current_track = -1; return MU_GME;
else
#endif #endif
if (!music)
return MU_NONE;
else if (Mix_GetMusicType(music) == MUS_MID)
return MU_MID;
else if (Mix_GetMusicType(music) == MUS_MOD || Mix_GetMusicType(music) == MUS_MODPLUG)
return MU_MOD;
else if (Mix_GetMusicType(music) == MUS_MP3 || Mix_GetMusicType(music) == MUS_MP3_MAD)
return MU_MP3;
else
return (musictype_t)Mix_GetMusicType(music);
} }
void I_ShutdownDigMusic(void) boolean I_SongPlaying(void)
{ {
if (midimode) return (
return; #ifdef HAVE_LIBGME
(I_SongType() == MU_GME && gme) ||
#endif
(boolean)music
);
}
boolean I_SongPaused(void)
{
return songpaused;
}
/// ------------------------
/// Music Effects
/// ------------------------
boolean I_SetSongSpeed(float speed)
{
if (speed > 250.0f)
speed = 250.0f; //limit speed up to 250x
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
if (gme) if (gme)
{ {
Mix_HookMusic(NULL, NULL); SDL_LockAudio();
gme_delete(gme); gme_set_tempo(gme, speed);
gme = NULL; SDL_UnlockAudio();
return true;
} }
#else
(void)speed;
#endif #endif
if (!music) return false;
return;
Mix_HookMusicFinished(NULL);
Mix_FreeMusic(music);
music = NULL;
} }
boolean I_StartDigSong(const char *musicname, boolean looping) /// ------------------------
/// Music Playback
/// ------------------------
boolean I_LoadSong(char *data, size_t len)
{ {
char *data; const char *key1 = "LOOP";
size_t len; const char *key2 = "POINT=";
lumpnum_t lumpnum = W_CheckNumForName(va("O_%s",musicname)); 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;
SDL_RWops *rw; SDL_RWops *rw;
I_Assert(!music); if (music
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
I_Assert(!gme); || gme
#endif #endif
)
if (lumpnum == LUMPERROR) I_UnloadSong();
return false;
midimode = false;
data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC);
len = W_LumpLength(lumpnum);
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
if ((UINT8)data[0] == 0x1F if ((UINT8)data[0] == 0x1F
@ -650,10 +686,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
else if (!gme_open_data(data, len, &gme, 44100)) 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_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); gme_set_equalizer(gme, &eq);
Mix_HookMusic(mix_gme, gme);
return true; return true;
} }
#endif #endif
@ -666,48 +699,75 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
if (!music) if (!music)
{ {
CONS_Alert(CONS_ERROR, "Mix_LoadMUS_RW: %s\n", Mix_GetError()); CONS_Alert(CONS_ERROR, "Mix_LoadMUS_RW: %s\n", Mix_GetError());
return true; return false;
} }
// Find the OGG loop point. // Find the OGG loop point.
loop_point = 0.0f; loop_point = 0.0f;
if (looping)
while ((UINT32)(p - data) < len)
{ {
const char *key1 = "LOOP"; if (strncmp(p++, key1, key1len))
const char *key2 = "POINT="; continue;
const char *key3 = "MS="; p += key1len-1; // skip OOP (the L was skipped in strncmp)
const size_t key1len = strlen(key1); if (!strncmp(p, key2, key2len)) // is it LOOPPOINT=?
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)) p += key2len; // skip POINT=
continue; loop_point = (float)((44.1L+atoi(p)) / 44100.0L); // LOOPPOINT works by sample count.
p += key1len-1; // skip OOP (the L was skipped in strncmp) // because SDL_Mixer is USELESS and can't even tell us
if (!strncmp(p, key2, key2len)) // is it LOOPPOINT=? // something simple like the frequency of the streaming music,
{ // we are unfortunately forced to assume that ALL MUSIC is 44100hz.
p += key2len; // skip POINT= // This means a lot of tracks that are only 22050hz for a reasonable downloadable file size will loop VERY badly.
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.
} }
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;
}
void I_UnloadSong(void)
{
I_StopSong();
#ifdef HAVE_LIBGME
if (gme)
{
gme_delete(gme);
gme = NULL;
}
#endif
if (music)
{
Mix_FreeMusic(music);
music = NULL;
}
}
boolean I_PlaySong(boolean looping)
{
#ifdef HAVE_LIBGME
if (gme)
{
gme_start_track(gme, 0);
current_track = 0;
Mix_HookMusic(mix_gme, gme);
return true;
}
else
#endif
if (!music)
return false;
if (Mix_PlayMusic(music, looping && loop_point == 0.0f ? -1 : 0) == -1) if (Mix_PlayMusic(music, looping && loop_point == 0.0f ? -1 : 0) == -1)
{ {
CONS_Alert(CONS_ERROR, "Mix_PlayMusic: %s\n", Mix_GetError()); CONS_Alert(CONS_ERROR, "Mix_PlayMusic: %s\n", Mix_GetError());
return true; return false;
} }
Mix_VolumeMusic((UINT32)music_volume*128/31); Mix_VolumeMusic((UINT32)music_volume*128/31);
@ -716,51 +776,49 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
return true; return true;
} }
void I_StopDigSong(void) void I_StopSong(void)
{ {
if (midimode)
return;
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
if (gme) if (gme)
{ {
Mix_HookMusic(NULL, NULL); Mix_HookMusic(NULL, NULL);
gme_delete(gme);
gme = NULL;
current_track = -1; current_track = -1;
return;
} }
#endif #endif
if (!music) if (music)
return;
Mix_HookMusicFinished(NULL);
Mix_FreeMusic(music);
music = NULL;
}
void I_SetDigMusicVolume(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(); Mix_HookMusicFinished(NULL);
gme_set_tempo(gme, speed); Mix_HaltMusic();
SDL_UnlockAudio();
return true;
} }
#else }
(void)speed;
void I_PauseSong(void)
{
Mix_PauseMusic();
songpaused = true;
}
void I_ResumeSong(void)
{
Mix_ResumeMusic();
songpaused = false;
}
void I_SetMusicVolume(UINT8 volume)
{
if (!I_SongPlaying())
return;
#ifdef _WIN32
if (I_SongType() == MU_MID)
// HACK: Until we stop using native MIDI,
// disable volume changes
music_volume = 31;
else
#endif #endif
return false; music_volume = volume;
Mix_VolumeMusic((UINT32)music_volume*128/31);
} }
boolean I_SetSongTrack(int track) boolean I_SetSongTrack(int track)
@ -794,83 +852,4 @@ boolean I_SetSongTrack(int track)
return false; 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 (!midimode || !music)
return;
Mix_VolumeMusic((UINT32)midi_volume*128/31);
}
INT32 I_RegisterSong(void *data, size_t len)
{
SDL_RWops *rw = SDL_RWFromMem(data, len);
if (rw != NULL)
{
music = Mix_LoadMUS_RW(rw, 1);
}
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();
}
void I_UnRegisterSong(INT32 handle)
{
if (!midimode || !music)
return;
(void)handle;
Mix_FreeMusic(music);
music = NULL;
}
#endif #endif

View file

@ -194,8 +194,8 @@ static srb2audio_t localdata;
static void Snd_LockAudio(void) //Alam: Lock audio data and uninstall audio callback static void Snd_LockAudio(void) //Alam: Lock audio data and uninstall audio callback
{ {
if (Snd_Mutex) SDL_LockMutex(Snd_Mutex); if (Snd_Mutex) SDL_LockMutex(Snd_Mutex);
else if (nosound) return; else if (sound_disabled) return;
else if (nomidimusic && nodigimusic else if (midi_disabled && digital_disabled
#ifdef HW3SOUND #ifdef HW3SOUND
&& hws_mode == HWS_DEFAULT_MODE && hws_mode == HWS_DEFAULT_MODE
#endif #endif
@ -208,8 +208,8 @@ static void Snd_LockAudio(void) //Alam: Lock audio data and uninstall audio call
static void Snd_UnlockAudio(void) //Alam: Unlock audio data and reinstall audio callback static void Snd_UnlockAudio(void) //Alam: Unlock audio data and reinstall audio callback
{ {
if (Snd_Mutex) SDL_UnlockMutex(Snd_Mutex); if (Snd_Mutex) SDL_UnlockMutex(Snd_Mutex);
else if (nosound) return; else if (sound_disabled) return;
else if (nomidimusic && nodigimusic else if (midi_disabled && digital_disabled
#ifdef HW3SOUND #ifdef HW3SOUND
&& hws_mode == HWS_DEFAULT_MODE && hws_mode == HWS_DEFAULT_MODE
#endif #endif
@ -493,7 +493,7 @@ static inline void I_SetChannels(void)
INT32 *steptablemid = steptable + 128; INT32 *steptablemid = steptable + 128;
if (nosound) if (sound_disabled)
return; return;
// This table provides step widths for pitch parameters. // This table provides step widths for pitch parameters.
@ -610,7 +610,7 @@ INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priori
(void)pitch; (void)pitch;
(void)channel; (void)channel;
if (nosound) if (sound_disabled)
return 0; return 0;
if (S_sfx[id].data == NULL) return -1; if (S_sfx[id].data == NULL) return -1;
@ -990,7 +990,7 @@ FUNCINLINE static ATTRINLINE void I_UpdateStream16M(Uint8 *stream, int len)
if (Snd_Mutex) SDL_UnlockMutex(Snd_Mutex); if (Snd_Mutex) SDL_UnlockMutex(Snd_Mutex);
} }
#ifdef HAVE_LIBGME #if 0 //#ifdef HAVE_LIBGME
static void I_UpdateSteamGME(Music_Emu *emu, INT16 *stream, int len, UINT8 looping) static void I_UpdateSteamGME(Music_Emu *emu, INT16 *stream, int len, UINT8 looping)
{ {
#define GME_BUFFER_LEN 44100*2048 #define GME_BUFFER_LEN 44100*2048
@ -1050,14 +1050,16 @@ static void SDLCALL I_UpdateStream(void *userdata, Uint8 *stream, int len)
else if (audio.channels == 2 && audio.format == AUDIO_S16SYS) else if (audio.channels == 2 && audio.format == AUDIO_S16SYS)
{ {
I_UpdateStream16S(stream, len); I_UpdateStream16S(stream, len);
#ifdef HAVE_LIBGME
if (userdata) // Crashes! But no matter; this build doesn't play music anyway...
{ // #ifdef HAVE_LIBGME
srb2audio_t *sa_userdata = userdata; // if (userdata)
if (!sa_userdata->gme_pause) // {
I_UpdateSteamGME(sa_userdata->gme_emu, (INT16 *)stream, len/4, sa_userdata->gme_loop); // srb2audio_t *sa_userdata = userdata;
} // if (!sa_userdata->gme_pause)
#endif // I_UpdateSteamGME(sa_userdata->gme_emu, (INT16 *)stream, len/4, sa_userdata->gme_loop);
// }
// #endif
} }
} }
@ -1137,7 +1139,7 @@ static INT32 Init3DSDriver(const char *soName)
void I_ShutdownSound(void) void I_ShutdownSound(void)
{ {
if (nosound || !sound_started) if (sound_disabled || !sound_started)
return; return;
CONS_Printf("I_ShutdownSound: "); CONS_Printf("I_ShutdownSound: ");
@ -1151,7 +1153,7 @@ void I_ShutdownSound(void)
} }
#endif #endif
if (nomidimusic && nodigimusic) if (midi_disabled && digital_disabled)
SDL_CloseAudio(); SDL_CloseAudio();
CONS_Printf("%s", M_GetText("shut down\n")); CONS_Printf("%s", M_GetText("shut down\n"));
sound_started = false; sound_started = false;
@ -1171,7 +1173,7 @@ void I_StartupSound(void)
const char *sdrv_name = NULL; const char *sdrv_name = NULL;
#endif #endif
#ifndef HAVE_MIXER #ifndef HAVE_MIXER
nomidimusic = nodigimusic = true; midi_disabled = digital_disabled = true;
#endif #endif
memset(channels, 0, sizeof (channels)); //Alam: Clean it memset(channels, 0, sizeof (channels)); //Alam: Clean it
@ -1214,7 +1216,7 @@ void I_StartupSound(void)
audio.samples /= 2; audio.samples /= 2;
} }
if (nosound) if (sound_disabled)
return; return;
#ifdef HW3SOUND #ifdef HW3SOUND
@ -1262,7 +1264,7 @@ void I_StartupSound(void)
{ {
snddev_t snddev; snddev_t snddev;
//nosound = true; //sound_disabled = true;
//I_AddExitFunc(I_ShutdownSound); //I_AddExitFunc(I_ShutdownSound);
snddev.bps = 16; snddev.bps = 16;
snddev.sample_rate = audio.freq; snddev.sample_rate = audio.freq;
@ -1289,7 +1291,7 @@ void I_StartupSound(void)
if (!musicStarted && SDL_OpenAudio(&audio, &audio) < 0) if (!musicStarted && SDL_OpenAudio(&audio, &audio) < 0)
{ {
CONS_Printf("%s", M_GetText(" couldn't open audio with desired format\n")); CONS_Printf("%s", M_GetText(" couldn't open audio with desired format\n"));
nosound = true; sound_disabled = true;
return; return;
} }
else else
@ -1314,13 +1316,11 @@ void I_StartupSound(void)
// MUSIC API. // MUSIC API.
// //
void I_ShutdownMIDIMusic(void) /// ------------------------
{ // MUSIC SYSTEM
nomidimusic = false; /// ------------------------
if (nodigimusic) I_ShutdownMusic();
}
#ifdef HAVE_LIBGME #if 0 //#ifdef HAVE_LIBGME
static void I_ShutdownGMEMusic(void) static void I_ShutdownGMEMusic(void)
{ {
Snd_LockAudio(); Snd_LockAudio();
@ -1331,391 +1331,127 @@ static void I_ShutdownGMEMusic(void)
} }
#endif #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)
{
FILE *midfile;
const char *tempname;
#ifdef USE_RWOPS
if (canuseRW)
{
SDL_RWops *SDLRW;
void *olddata = Smidi[selectpos]; //quick shortcut to set
Z_Free(olddata); //free old memory
Smidi[selectpos] = NULL;
if (!data)
return olddata != NULL; //was there old data?
SDLRW = SDL_RWFromConstMem(data, (int)lumplength); //new RWops from Z_zone
if (!SDLRW) //ERROR while making RWops!
{
CONS_Printf(M_GetText("Couldn't load music lump: %s\n"), SDL_GetError());
Z_Free(data);
return false;
}
music[selectpos] = Mix_LoadMUS_RW(SDLRW); // new Mix_Chuck from RWops
if (music[selectpos])
Smidi[selectpos] = data; //all done
else //ERROR while making Mix_Chuck
{
CONS_Printf(M_GetText("Couldn't load music data: %s\n"), Mix_GetError());
Z_Free(data);
SDL_RWclose(SDLRW);
Smidi[selectpos] = NULL;
}
return true;
}
#endif
tempname = va("%s/%s", MIDI_PATH, fmidi[selectpos]);
if (!data)
{
if (FIL_FileExists(tempname))
return unlink(tempname)+1;
#ifdef MIDI_PATH2
else if (FIL_FileExists(tempname = va("%s/%s", MIDI_PATH2, fmidi[selectpos])))
return unlink(tempname)+1;
#endif
else
return false;
}
midfile = fopen(tempname, "wb");
#ifdef MIDI_PATH2
if (!midfile)
{
tempname = va("%s/%s", MIDI_PATH2, fmidi[selectpos]);
midfile = fopen(tempname, "wb");
}
#endif
if (!midfile)
{
CONS_Printf(M_GetText("Couldn't open file %s to write music in\n"), tempname);
Z_Free(data);
return false;
}
if (fwrite(data, lumplength, 1, midfile) == 0)
{
CONS_Printf(M_GetText("Couldn't write music into file %s because %s\n"), tempname, strerror(ferror(midfile)));
Z_Free(data);
fclose(midfile);
return false;
}
fclose(midfile);
Z_Free(data);
music[selectpos] = Mix_LoadMUS(tempname);
if (!music[selectpos]) //ERROR while making Mix_Chuck
{
CONS_Printf(M_GetText("Couldn't load music file %s: %s\n"), tempname, Mix_GetError());
return false;
}
return true;
}
#endif
void I_ShutdownMusic(void)
{
#ifdef HAVE_MIXER
if ((nomidimusic && nodigimusic) || !musicStarted)
return;
CONS_Printf("%s", M_GetText("I_ShutdownMusic: "));
I_UnRegisterSong(0);
I_StopDigSong();
Mix_CloseAudio();
#ifdef MIX_INIT
Mix_Quit();
#endif
CONS_Printf("%s", M_GetText("shut down\n"));
musicStarted = SDL_FALSE;
if (Msc_Mutex)
SDL_DestroyMutex(Msc_Mutex);
Msc_Mutex = NULL;
#endif
}
void I_InitMIDIMusic(void)
{
if (nodigimusic) I_InitMusic();
}
void I_InitDigMusic(void)
{
if (nomidimusic) I_InitMusic();
}
void I_InitMusic(void) void I_InitMusic(void)
{ {
#ifdef HAVE_MIXER #if 0 //#ifdef HAVE_LIBGME
char ad[100];
SDL_version MIXcompiled;
const SDL_version *MIXlinked;
#ifdef MIXER_INIT
const int mixstart = MIX_INIT_OGG;
int mixflags;
#endif
#endif
#ifdef HAVE_LIBGME
I_AddExitFunc(I_ShutdownGMEMusic); I_AddExitFunc(I_ShutdownGMEMusic);
#endif #endif
#ifdef HAVE_MIXER
MIX_VERSION(&MIXcompiled)
MIXlinked = Mix_Linked_Version();
I_OutputMsg("Compiled for SDL_mixer version: %d.%d.%d\n",
MIXcompiled.major, MIXcompiled.minor, MIXcompiled.patch);
#ifdef MIXER_POS
if (MIXlinked->major == 1 && MIXlinked->minor == 2 && MIXlinked->patch < 7)
canlooping = SDL_FALSE;
#endif
#ifdef USE_RWOPS
if (M_CheckParm("-noRW"))
canuseRW = SDL_FALSE;
#endif
I_OutputMsg("Linked with SDL_mixer version: %d.%d.%d\n",
MIXlinked->major, MIXlinked->minor, MIXlinked->patch);
if (audio.freq < 44100 && !M_CheckParm ("-freq")) //I want atleast 44Khz
{
audio.samples = (Uint16)(audio.samples*(INT32)(44100/audio.freq));
audio.freq = 44100; //Alam: to keep it around the same XX ms
}
if (sound_started
#ifdef HW3SOUND
&& hws_mode == HWS_DEFAULT_MODE
#endif
)
{
I_OutputMsg("Temp Shutdown of SDL Audio System");
SDL_CloseAudio();
I_OutputMsg(" Done\n");
}
CONS_Printf("%s", M_GetText("I_InitMusic:"));
#ifdef MIXER_INIT
mixflags = Mix_Init(mixstart);
if ((mixstart & MIX_INIT_FLAC) != (mixflags & MIX_INIT_FLAC))
{
CONS_Printf("%s", M_GetText(" Unable to load FLAC support\n"));
}
if ((mixstart & MIX_INIT_MOD ) != (mixflags & MIX_INIT_MOD ))
{
CONS_Printf("%s", M_GetText(" Unable to load MOD support\n"));
}
if ((mixstart & MIX_INIT_MP3 ) != (mixflags & MIX_INIT_MP3 ))
{
CONS_Printf("%s", M_GetText(" Unable to load MP3 support\n"));
}
if ((mixstart & MIX_INIT_OGG ) != (mixflags & MIX_INIT_OGG ))
{
CONS_Printf("%s", M_GetText(" Unable to load OGG support\n"));
}
#endif
if (Mix_OpenAudio(audio.freq, audio.format, audio.channels, audio.samples) < 0) //open_music(&audio)
{
CONS_Printf(M_GetText(" Unable to open music: %s\n"), Mix_GetError());
nomidimusic = nodigimusic = true;
if (sound_started
#ifdef HW3SOUND
&& hws_mode == HWS_DEFAULT_MODE
#endif
)
{
if (SDL_OpenAudio(&audio, NULL) < 0) //retry
{
CONS_Printf("%s", M_GetText(" couldn't open audio with desired format\n"));
nosound = true;
sound_started = false;
}
else
{
CONS_Printf(M_GetText(" Starting with audio driver : %s\n"), SDL_AudioDriverName(ad, (int)sizeof ad));
}
}
return;
}
else
CONS_Printf(M_GetText(" Starting up with audio driver : %s with SDL_Mixer\n"), SDL_AudioDriverName(ad, (int)sizeof ad));
samplecount = audio.samples;
CV_SetValue(&cv_samplerate, audio.freq);
if (sound_started
#ifdef HW3SOUND
&& hws_mode == HWS_DEFAULT_MODE
#endif
)
I_OutputMsg(" Reconfigured SDL Audio System");
else I_OutputMsg(" Configured SDL_Mixer System");
I_OutputMsg(" with %d samples/slice at %ikhz(%dms buffer)\n", samplecount, audio.freq/1000, (INT32) ((audio.samples * 1000.0f) / audio.freq));
Mix_SetPostMix(audio.callback, audio.userdata); // after mixing music, add sound effects
Mix_Resume(-1);
CONS_Printf("%s", M_GetText("Music initialized\n"));
musicStarted = SDL_TRUE;
Msc_Mutex = SDL_CreateMutex();
#endif
} }
boolean I_PlaySong(INT32 handle, boolean looping) void I_ShutdownMusic(void) { }
/// ------------------------
// MUSIC PROPERTIES
/// ------------------------
musictype_t I_SongType(void)
{ {
(void)handle; return MU_NONE;
#ifdef HAVE_MIXER }
if (nomidimusic || !musicStarted || !music[handle])
return false;
#ifdef MIXER_POS boolean I_SongPlaying(void)
if (canlooping) {
Mix_HookMusicFinished(NULL);
#endif
if (Mix_FadeInMusic(music[handle], looping ? -1 : 0, MIDIfade) == -1)
CONS_Printf(M_GetText("Couldn't play song because %s\n"), Mix_GetError());
else
{
Mix_VolumeMusic(musicvol);
return true;
}
#else
(void)looping;
#endif
return false; return false;
} }
boolean I_SongPaused(void)
{
return false;
}
/// ------------------------
// MUSIC EFFECTS
/// ------------------------
boolean I_SetSongSpeed(float speed)
{
(void)speed;
return false;
}
/// ------------------------
// MUSIC PLAYBACK
/// ------------------------
#if 0 //#ifdef HAVE_LIBGME
static void I_StopGME(void)
{
Snd_LockAudio();
gme_seek(localdata.gme_emu, 0);
Snd_UnlockAudio();
}
static void I_PauseGME(void) static void I_PauseGME(void)
{ {
#ifdef HAVE_LIBGME
localdata.gme_pause = true; localdata.gme_pause = true;
#endif
}
void I_PauseSong(INT32 handle)
{
(void)handle;
I_PauseGME();
#ifdef HAVE_MIXER
if ((nomidimusic && nodigimusic) || !musicStarted)
return;
Mix_PauseMusic();
//I_StopSong(handle);
#endif
} }
static void I_ResumeGME(void) static void I_ResumeGME(void)
{ {
#ifdef HAVE_LIBGME
localdata.gme_pause = false; localdata.gme_pause = false;
#endif
} }
void I_ResumeSong(INT32 handle)
{
(void)handle;
I_ResumeGME();
#ifdef HAVE_MIXER
if ((nomidimusic && nodigimusic) || !musicStarted)
return;
Mix_VolumeMusic(musicvol);
Mix_ResumeMusic();
//I_PlaySong(handle, true);
#endif #endif
}
void I_StopSong(INT32 handle) boolean I_LoadSong(char *data, size_t len)
{ {
(void)handle;
#ifdef HAVE_MIXER
if (nomidimusic || !musicStarted)
return;
Mix_FadeOutMusic(MIDIfade);
#endif
}
void I_UnRegisterSong(INT32 handle)
{
#ifdef HAVE_MIXER
if (nomidimusic || !musicStarted)
return;
Mix_HaltMusic();
while (Mix_PlayingMusic())
;
if (music[handle])
Mix_FreeMusic(music[handle]);
music[handle] = NULL;
LoadSong(NULL, 0, handle);
#else
(void)handle;
#endif
}
INT32 I_RegisterSong(void *data, size_t len)
{
#ifdef HAVE_MIXER
if (nomidimusic || !musicStarted)
return false;
if (!LoadSong(data, len, 0))
return false;
if (music[0])
return true;
CONS_Printf(M_GetText("Couldn't load MIDI: %s\n"), Mix_GetError());
#else
(void)len;
(void)data;
#endif
return false; return false;
} }
void I_SetMIDIMusicVolume(UINT8 volume) void I_UnloadSong(void) { }
{
#ifdef HAVE_MIXER
if ((nomidimusic && nodigimusic) || !musicStarted)
return;
if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); boolean I_PlaySong(boolean looping)
musicvol = volume * 2; {
if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); (void)looping;
Mix_VolumeMusic(musicvol); return false;
#else }
(void)volume;
void I_StopSong(void)
{
#if 0 //#ifdef HAVE_LIBGME
I_StopGME();
#endif #endif
} }
#ifdef HAVE_LIBGME void I_PauseSong(void)
{
#if 0 //#ifdef HAVE_LIBGME
I_PauseGME();
#endif
}
void I_ResumeSong(void)
{
#if 0
I_ResumeGME();
#endif
}
void I_SetMusicVolume(UINT8 volume)
{
(void)volume;
}
boolean I_SetSongTrack(int track)
{
(void)track;
return false;
}
/// ------------------------
// MUSIC LOADING AND CLEANUP
// \todo Split logic between loading and playing,
// then move to Playback section
/// ------------------------
#if 0 //#ifdef HAVE_LIBGME
static void I_CleanupGME(void *userdata) static void I_CleanupGME(void *userdata)
{ {
Z_Free(userdata); Z_Free(userdata);
} }
#endif
static boolean I_StartGMESong(const char *musicname, boolean looping) static boolean I_StartGMESong(const char *musicname, boolean looping)
{ {
#ifdef HAVE_LIBGME char filename[9];
XBOXSTATIC char filename[9];
void *data; void *data;
lumpnum_t lumpnum; lumpnum_t lumpnum;
size_t lumplength; size_t lumplength;
@ -1760,240 +1496,7 @@ static boolean I_StartGMESong(const char *musicname, boolean looping)
Snd_UnlockAudio(); Snd_UnlockAudio();
return true; return true;
#else
(void)musicname;
(void)looping;
#endif
return false;
}
boolean I_StartDigSong(const char *musicname, boolean looping)
{
#ifdef HAVE_MIXER
XBOXSTATIC char filename[9];
void *data;
lumpnum_t lumpnum;
size_t lumplength;
#endif
if(I_StartGMESong(musicname, looping))
return true;
#ifdef HAVE_MIXER
if (nodigimusic)
return false;
snprintf(filename, sizeof filename, "o_%s", musicname);
lumpnum = W_CheckNumForName(filename);
I_StopDigSong();
if (lumpnum == LUMPERROR)
{
// Alam_GBC: like in win32/win_snd.c: Graue 02-29-2004: don't worry about missing music, there might still be a MIDI
//I_OutputMsg("Music lump %s not found!\n", filename);
return false; // No music found. Oh well!
}
else
lumplength = W_LumpLength(lumpnum);
data = W_CacheLumpNum(lumpnum, PU_MUSIC);
if (Msc_Mutex) SDL_LockMutex(Msc_Mutex);
#ifdef MIXER_POS
if (canlooping && (loopingDig = looping) == SDL_TRUE && strcmp(data, "OggS") == 0)
looping = false; // Only on looping Ogg files, will we will do our own looping
// Scan the Ogg Vorbis file for the COMMENT= field for a custom
// loop point
if (!looping && loopingDig)
{
size_t scan;
const char *dataum = data;
XBOXSTATIC char looplength[64];
UINT32 loopstart = 0;
UINT8 newcount = 0;
Mix_HookMusicFinished(I_FinishMusic);
for (scan = 0; scan < lumplength; scan++)
{
if (*dataum++ == 'C'){
if (*dataum++ == 'O'){
if (*dataum++ == 'M'){
if (*dataum++ == 'M'){
if (*dataum++ == 'E'){
if (*dataum++ == 'N'){
if (*dataum++ == 'T'){
if (*dataum++ == '='){
if (*dataum++ == 'L'){
if (*dataum++ == 'O'){
if (*dataum++ == 'O'){
if (*dataum++ == 'P'){
if (*dataum++ == 'P'){
if (*dataum++ == 'O'){
if (*dataum++ == 'I'){
if (*dataum++ == 'N'){
if (*dataum++ == 'T'){
if (*dataum++ == '=')
{
while (*dataum != 1 && newcount != 63)
looplength[newcount++] = *dataum++;
looplength[newcount] = '\0';
loopstart = atoi(looplength);
}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
else
dataum--;}
}
if (loopstart > 0)
{
loopstartDig = (double)((44.1l+loopstart) / 44100.0l); //8 PCM chucks off and PCM to secs
//#ifdef PARANOIA
//I_OutputMsg("I_StartDigSong: setting looping point to %ul PCMs(%f seconds)\n", loopstart, loopstartDig);
//#endif
}
else
{
looping = true; // loopingDig true, but couldn't find start loop point
}
}
else
loopstartDig = 0.0l;
#else
if (looping && strcmp(data, "OggS") == 0)
I_OutputMsg("I_StartDigSong: SRB2 was not compiled with looping music support(no Mix_FadeInMusicPos)\n");
#endif
if (!LoadSong(data, lumplength, 1))
{
if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex);
return false;
}
// Note: LoadSong() frees the data. Let's make sure
// we don't try to use the data again.
data = NULL;
if (Mix_FadeInMusic(music[1], looping ? -1 : 0, Digfade) == -1)
{
if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex);
I_OutputMsg("I_StartDigSong: Couldn't play song %s because %s\n", musicname, Mix_GetError());
return false;
}
Mix_VolumeMusic(musicvol);
if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex);
return true;
#else
(void)looping;
(void)musicname;
return false;
#endif
}
static void I_StopGME(void)
{
#ifdef HAVE_LIBGME
Snd_LockAudio();
gme_seek(localdata.gme_emu, 0);
Snd_UnlockAudio();
#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)
{
I_SetMIDIMusicVolume(volume);
}
boolean I_SetSongSpeed(float speed)
{
(void)speed;
return false;
}
boolean I_SetSongTrack(int track)
{
(void)track;
return false;
}
#ifdef MIXER_POS
static void SDLCALL I_FinishMusic(void)
{
if (!music[1])
return;
else if (Msc_Mutex) SDL_LockMutex(Msc_Mutex);
// I_OutputMsg("I_FinishMusic: Loopping song to %g seconds\n", loopstartDig);
if (Mix_FadeInMusicPos(music[1], loopstartDig ? 0 : -1, Digfade, loopstartDig) == 0)
Mix_VolumeMusic(musicvol);
else
I_OutputMsg("I_FinishMusic: Couldn't loop song because %s\n", Mix_GetError());
if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex);
} }
#endif #endif
#endif //HAVE_SDL #endif //HAVE_SDL

View file

@ -471,7 +471,7 @@ void I_PlayCD(UINT8 nTrack, UINT8 bLooping)
//faB: stop MIDI music, MIDI music will restart if volume is upped later //faB: stop MIDI music, MIDI music will restart if volume is upped later
cv_digmusicvolume.value = 0; cv_digmusicvolume.value = 0;
cv_midimusicvolume.value = 0; cv_midimusicvolume.value = 0;
I_StopSong (0); I_StopSong();
//faB: I don't use the notify message, I'm trying to minimize the delay //faB: I don't use the notify message, I'm trying to minimize the delay
mciPlay.dwCallback = (DWORD)((size_t)hWndMain); mciPlay.dwCallback = (DWORD)((size_t)hWndMain);

View file

@ -110,9 +110,9 @@ static LRESULT CALLBACK MainWndproc(HWND hWnd, UINT message, WPARAM wParam, LPAR
// pause music when alt-tab // pause music when alt-tab
if (appActive && !paused) if (appActive && !paused)
I_ResumeSong(0); I_ResumeSong();
else if (!paused) else if (!paused)
I_PauseSong(0); I_PauseSong();
{ {
HANDLE ci = GetStdHandle(STD_INPUT_HANDLE); HANDLE ci = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode; DWORD mode;

View file

@ -40,7 +40,6 @@
static FMOD_SYSTEM *fsys; static FMOD_SYSTEM *fsys;
static FMOD_SOUND *music_stream; static FMOD_SOUND *music_stream;
static FMOD_CHANNEL *music_channel; static FMOD_CHANNEL *music_channel;
static boolean midimode;
static UINT8 music_volume, midi_volume, sfx_volume; static UINT8 music_volume, midi_volume, sfx_volume;
static INT32 current_track; static INT32 current_track;
@ -439,9 +438,9 @@ void I_SetSfxVolume(UINT8 volume)
sfx_volume = volume; sfx_volume = volume;
} }
// /// ------------------------
// MUSIC // MUSIC SYSTEM
// /// ------------------------
void I_InitMusic(void) void I_InitMusic(void)
{ {
@ -449,53 +448,111 @@ void I_InitMusic(void)
void I_ShutdownMusic(void) void I_ShutdownMusic(void)
{ {
I_ShutdownDigMusic(); I_StopSong();
I_ShutdownMIDIMusic();
} }
void I_PauseSong(INT32 handle) /// ------------------------
{ // MUSIC PROPERTIES
UNREFERENCED_PARAMETER(handle); /// ------------------------
if (music_stream)
FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, true));
}
void I_ResumeSong(INT32 handle) musictype_t I_SongType(void)
{ {
UNREFERENCED_PARAMETER(handle); #ifdef HAVE_LIBGME
if (music_stream) if (gme)
FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, false)); return MU_GME;
} #endif
void I_InitDigMusic(void) if (!music_stream)
{ return MU_NONE;
}
void I_ShutdownDigMusic(void) FMOD_SOUND_TYPE type;
{ if (FMOD_Sound_GetFormat(music_stream, &type, NULL, NULL, NULL) == FMOD_OK)
if (!midimode)
I_StopDigSong();
}
boolean I_StartDigSong(const char *musicname, boolean looping)
{
char *data;
size_t len;
FMOD_CREATESOUNDEXINFO fmt;
lumpnum_t lumpnum = W_CheckNumForName(va("O_%s",musicname));
if (lumpnum == LUMPERROR)
{ {
lumpnum = W_CheckNumForName(va("D_%s",musicname)); switch(type)
if (lumpnum == LUMPERROR) {
return false; case FMOD_SOUND_TYPE_WAV:
midimode = true; return MU_WAV;
case FMOD_SOUND_TYPE_MOD:
return MU_MOD;
case FMOD_SOUND_TYPE_MIDI:
return MU_MID;
case FMOD_SOUND_TYPE_OGGVORBIS:
return MU_OGG;
case FMOD_SOUND_TYPE_MPEG:
return MU_MP3;
case FMOD_SOUND_TYPE_FLAC:
return MU_FLAC;
default:
return MU_NONE;
}
} }
else else
midimode = false; return MU_NONE;
}
data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC); boolean I_SongPlaying(void)
len = W_LumpLength(lumpnum); {
return (boolean)music_stream;
}
boolean I_SongPaused(void)
{
boolean fmpaused = false;
if (music_stream)
FMOD_Channel_GetPaused(music_channel, &fmpaused);
return fmpaused;
}
/// ------------------------
// MUSIC EFFECTS
/// ------------------------
boolean I_SetSongSpeed(float speed)
{
FMOD_RESULT e;
float frequency;
if (!music_stream)
return false;
if (speed > 250.0f)
speed = 250.0f; //limit speed up to 250x
#ifdef HAVE_LIBGME
// Try to set GME speed
if (gme)
{
gme_set_tempo(gme, speed);
return true;
}
#endif
// Try to set Mod/Midi speed
e = FMOD_Sound_SetMusicSpeed(music_stream, speed);
if (e == FMOD_ERR_FORMAT)
{
// Just change pitch instead for Ogg/etc.
FMR(FMOD_Sound_GetDefaults(music_stream, &frequency, NULL, NULL, NULL));
FMR_MUSIC(FMOD_Channel_SetFrequency(music_channel, speed*frequency));
}
else
FMR_MUSIC(e);
return true;
}
/// ------------------------
// MUSIC PLAYBACK
/// ------------------------
boolean I_LoadSong(char *data, size_t len)
{
FMOD_CREATESOUNDEXINFO fmt;
FMOD_RESULT e;
FMOD_TAG tag;
unsigned int loopstart, loopend;
if (gme || music_stream)
I_UnloadSong();
memset(&fmt, 0, sizeof(FMOD_CREATESOUNDEXINFO)); memset(&fmt, 0, sizeof(FMOD_CREATESOUNDEXINFO));
fmt.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); fmt.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
@ -530,8 +587,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}; gme_equalizer_t gmeq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0};
Z_Free(inflatedData); // GME supposedly makes a copy for itself, so we don't need this lying around Z_Free(inflatedData); // GME supposedly makes a copy for itself, so we don't need this lying around
Z_Free(data); // We don't need this, either. Z_Free(data); // We don't need this, either.
gme_start_track(gme, 0);
current_track = 0;
gme_set_equalizer(gme,&gmeq); gme_set_equalizer(gme,&gmeq);
fmt.format = FMOD_SOUND_FORMAT_PCM16; fmt.format = FMOD_SOUND_FORMAT_PCM16;
fmt.defaultfrequency = 44100; fmt.defaultfrequency = 44100;
@ -540,10 +595,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
fmt.decodebuffersize = (44100 * 2) / 35; fmt.decodebuffersize = (44100 * 2) / 35;
fmt.pcmreadcallback = GMEReadCallback; fmt.pcmreadcallback = GMEReadCallback;
fmt.userdata = gme; fmt.userdata = gme;
FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER, &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; return true;
} }
} }
@ -602,8 +654,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}; 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. Z_Free(data); // We don't need this anymore.
gme_start_track(gme, 0);
current_track = 0;
gme_set_equalizer(gme,&gmeq); gme_set_equalizer(gme,&gmeq);
fmt.format = FMOD_SOUND_FORMAT_PCM16; fmt.format = FMOD_SOUND_FORMAT_PCM16;
fmt.defaultfrequency = 44100; fmt.defaultfrequency = 44100;
@ -612,7 +662,102 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
fmt.decodebuffersize = (44100 * 2) / 35; fmt.decodebuffersize = (44100 * 2) / 35;
fmt.pcmreadcallback = GMEReadCallback; fmt.pcmreadcallback = GMEReadCallback;
fmt.userdata = gme; fmt.userdata = gme;
FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER, &fmt, &music_stream));
return true;
}
#endif
fmt.length = len;
e = FMOD_System_CreateStream(fsys, data, FMOD_OPENMEMORY_POINT, &fmt, &music_stream);
if (e != FMOD_OK)
{
if (e == FMOD_ERR_FORMAT)
CONS_Alert(CONS_WARNING, "Failed to play music lump due to invalid format.\n");
else
FMR(e);
return false;
}
// Try to find a loop point in streaming music formats (ogg, mp3)
// A proper LOOPPOINT is its own tag, stupid.
e = FMOD_Sound_GetTag(music_stream, "LOOPPOINT", 0, &tag);
if (e != FMOD_ERR_TAGNOTFOUND)
{
FMR(e);
loopstart = atoi((char *)tag.data); // assumed to be a string data tag.
FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM));
if (loopstart > 0)
FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM));
return true;
}
// Use LOOPMS for time in miliseconds.
e = FMOD_Sound_GetTag(music_stream, "LOOPMS", 0, &tag);
if (e != FMOD_ERR_TAGNOTFOUND)
{
FMR(e);
loopstart = atoi((char *)tag.data); // assumed to be a string data tag.
FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_MS, &loopend, FMOD_TIMEUNIT_PCM));
if (loopstart > 0)
FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_MS, loopend, FMOD_TIMEUNIT_PCM));
return true;
}
// Try to fetch it from the COMMENT tag, like A.J. Freda
e = FMOD_Sound_GetTag(music_stream, "COMMENT", 0, &tag);
if (e != FMOD_ERR_TAGNOTFOUND)
{
char *loopText;
// Handle any errors that arose, first
FMR(e);
// Figure out where the number starts
loopText = strstr((char *)tag.data,"LOOPPOINT=");
if (loopText != NULL)
{
// Skip the "LOOPPOINT=" part.
loopText += 10;
// Convert it to our looppoint
// FMOD seems to ensure the tag is properly NULL-terminated.
// atoi will stop when it reaches anything that's not a number.
loopstart = atoi(loopText);
// Now do the rest like above
FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM));
if (loopstart > 0)
FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM));
}
return true;
}
// No special loop point
return true;
}
void I_UnloadSong(void)
{
I_StopSong();
#ifdef HAVE_LIBGME
if (gme)
{
gme_delete(gme);
gme = NULL;
}
#endif
if (music_stream)
{
FMR(FMOD_Sound_Release(music_stream));
music_stream = NULL;
}
}
boolean I_PlaySong(boolean looping)
{
#ifdef HAVE_LIBGME
if (gme)
{
gme_start_track(gme, 0);
current_track = 0;
FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); 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_SetVolume(music_channel, music_volume / 31.0));
FMR(FMOD_Channel_SetPriority(music_channel, 0)); FMR(FMOD_Channel_SetPriority(music_channel, 0));
@ -620,139 +765,48 @@ boolean I_StartDigSong(const char *musicname, boolean looping)
} }
#endif #endif
fmt.length = len; FMR(FMOD_Sound_SetMode(music_stream, (looping ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF)));
{
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;
}
}
FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel));
if (midimode) if (I_SongType() != MU_MID)
FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0));
else else
FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0));
FMR(FMOD_Channel_SetPriority(music_channel, 0)); FMR(FMOD_Channel_SetPriority(music_channel, 0));
current_track = 0; current_track = 0;
// Try to find a loop point in streaming music formats (ogg, mp3)
if (looping)
{
FMOD_RESULT e;
FMOD_TAG tag;
unsigned int loopstart, loopend;
// A proper LOOPPOINT is its own tag, stupid.
e = FMOD_Sound_GetTag(music_stream, "LOOPPOINT", 0, &tag);
if (e != FMOD_ERR_TAGNOTFOUND)
{
FMR(e);
loopstart = atoi((char *)tag.data); // assumed to be a string data tag.
FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM));
if (loopstart > 0)
FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM));
return true;
}
// Use LOOPMS for time in miliseconds.
e = FMOD_Sound_GetTag(music_stream, "LOOPMS", 0, &tag);
if (e != FMOD_ERR_TAGNOTFOUND)
{
FMR(e);
loopstart = atoi((char *)tag.data); // assumed to be a string data tag.
FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_MS, &loopend, FMOD_TIMEUNIT_PCM));
if (loopstart > 0)
FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_MS, loopend, FMOD_TIMEUNIT_PCM));
return true;
}
// Try to fetch it from the COMMENT tag, like A.J. Freda
e = FMOD_Sound_GetTag(music_stream, "COMMENT", 0, &tag);
if (e != FMOD_ERR_TAGNOTFOUND)
{
char *loopText;
// Handle any errors that arose, first
FMR(e);
// Figure out where the number starts
loopText = strstr((char *)tag.data,"LOOPPOINT=");
if (loopText != NULL)
{
// Skip the "LOOPPOINT=" part.
loopText += 10;
// Convert it to our looppoint
// FMOD seems to ensure the tag is properly NULL-terminated.
// atoi will stop when it reaches anything that's not a number.
loopstart = atoi(loopText);
// Now do the rest like above
FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM));
if (loopstart > 0)
FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM));
}
return true;
}
}
// No special loop point, but we're playing so it's all good.
return true; return true;
} }
void I_StopDigSong(void) void I_StopSong(void)
{ {
if (music_stream) if (music_channel)
FMR(FMOD_Sound_Release(music_stream)); FMR_MUSIC(FMOD_Channel_Stop(music_channel));
music_stream = NULL;
#ifdef HAVE_LIBGME
if (gme)
gme_delete(gme);
gme = NULL;
#endif
current_track = -1;
} }
void I_SetDigMusicVolume(UINT8 volume) void I_PauseSong(void)
{ {
if (music_channel)
FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, true));
}
void I_ResumeSong(void)
{
if (music_channel)
FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, false));
}
void I_SetMusicVolume(UINT8 volume)
{
if (!music_channel)
return;
// volume is 0 to 31. // volume is 0 to 31.
music_volume = volume; if (I_SongType() == MU_MID)
if (!midimode && music_stream) music_volume = 31; // windows bug hack
FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0));
}
boolean I_SetSongSpeed(float speed)
{
FMOD_RESULT e;
float frequency;
if (!music_stream)
return false;
if (speed > 250.0f)
speed = 250.0f; //limit speed up to 250x
#ifdef HAVE_LIBGME
// Try to set GME speed
if (gme)
{
gme_set_tempo(gme, speed);
return true;
}
#endif
// Try to set Mod/Midi speed
e = FMOD_Sound_SetMusicSpeed(music_stream, speed);
if (e == FMOD_ERR_FORMAT)
{
// Just change pitch instead for Ogg/etc.
FMR(FMOD_Sound_GetDefaults(music_stream, &frequency, NULL, NULL, NULL));
FMR_MUSIC(FMOD_Channel_SetFrequency(music_channel, speed*frequency));
}
else else
FMR_MUSIC(e); music_volume = volume;
return true; FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0));
} }
boolean I_SetSongTrack(INT32 track) boolean I_SetSongTrack(INT32 track)
@ -799,62 +853,3 @@ boolean I_SetSongTrack(INT32 track)
} }
return false; return false;
} }
//
// Fuck MIDI. ... Okay fine, you can have your silly D_-only mode.
//
void I_InitMIDIMusic(void)
{
}
void I_ShutdownMIDIMusic(void)
{
if (midimode)
I_StopSong(0);
}
void I_SetMIDIMusicVolume(UINT8 volume)
{
// volume is 0 to 31.
midi_volume = volume;
if (midimode && music_stream)
FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.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)
{
midimode = true;
if (looping)
FMR(FMOD_Sound_SetMode(music_stream, FMOD_LOOP_NORMAL));
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));
}
return true;
}
void I_StopSong(INT32 handle)
{
I_UnRegisterSong(handle);
}
void I_UnRegisterSong(INT32 handle)
{
UNREFERENCED_PARAMETER(handle);
if (music_stream)
FMR(FMOD_Sound_Release(music_stream));
music_stream = NULL;
}