2006-02-24 04:48:15 +00:00
|
|
|
/*
|
|
|
|
** i_music.cpp
|
|
|
|
** Plays music
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
2006-06-11 01:37:00 +00:00
|
|
|
** Copyright 1998-2006 Randy Heit
|
2006-02-24 04:48:15 +00:00
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <mmsystem.h>
|
|
|
|
#else
|
|
|
|
#include <SDL.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <wordexp.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "mus2midi.h"
|
|
|
|
#define FALSE 0
|
|
|
|
#define TRUE 1
|
|
|
|
extern void ChildSigHandler (int signum);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
#include "i_musicinterns.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "doomtype.h"
|
|
|
|
#include "m_argv.h"
|
|
|
|
#include "i_music.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "c_console.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "i_sound.h"
|
2008-09-15 18:18:04 +00:00
|
|
|
#include "s_sound.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "m_swap.h"
|
|
|
|
#include "i_cd.h"
|
|
|
|
#include "tempfiles.h"
|
|
|
|
#include "templates.h"
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
#include "stats.h"
|
2008-04-11 04:59:23 +00:00
|
|
|
#include "timidity/timidity.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-06-03 03:05:02 +00:00
|
|
|
#define GZIP_ID1 31
|
|
|
|
#define GZIP_ID2 139
|
|
|
|
#define GZIP_CM 8
|
|
|
|
#define GZIP_ID MAKE_ID(GZIP_ID1,GZIP_ID2,GZIP_CM,0)
|
|
|
|
|
|
|
|
#define GZIP_FTEXT 1
|
|
|
|
#define GZIP_FHCRC 2
|
|
|
|
#define GZIP_FEXTRA 4
|
|
|
|
#define GZIP_FNAME 8
|
|
|
|
#define GZIP_FCOMMENT 16
|
|
|
|
|
2010-04-06 03:12:32 +00:00
|
|
|
extern int MUSHeaderSearch(const BYTE *head, int len);
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
EXTERN_CVAR (Int, snd_samplerate)
|
|
|
|
EXTERN_CVAR (Int, snd_mididevice)
|
|
|
|
|
|
|
|
static bool MusicDown = true;
|
|
|
|
|
2009-06-03 03:05:02 +00:00
|
|
|
static BYTE *ungzip(BYTE *data, int *size);
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
MusInfo *currSong;
|
|
|
|
int nomusic = 0;
|
2006-03-03 03:57:01 +00:00
|
|
|
float relative_volume = 1.f;
|
2006-04-14 12:58:52 +00:00
|
|
|
float saved_relative_volume = 1.0f; // this could be used to implement an ACS FadeMusic function
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CVAR snd_musicvolume
|
|
|
|
//
|
|
|
|
// Maximum volume of MOD/stream music.
|
|
|
|
//==========================================================================
|
|
|
|
|
2008-03-28 03:19:18 +00:00
|
|
|
CUSTOM_CVAR (Float, snd_musicvolume, 0.5f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (self < 0.f)
|
|
|
|
self = 0.f;
|
|
|
|
else if (self > 1.f)
|
|
|
|
self = 1.f;
|
2008-03-28 03:19:18 +00:00
|
|
|
else
|
VERY IMPORTANT NOTE FOR ANYBODY BUILDING FROM THE TRUNK: This commit adds support
for FMOD Ex while at the same time removing support for FMOD 3. Be sure to update
your SDKs. GCC users, be sure to do a "make cleandep && make clean" before
building, or you will likely get inexplicable errors.
- Fixed: If you wanted to make cleandep with MinGW, you had to specifically
specify Makefile.mingw as the makefile to use.
- Added a normalizer to the OPL synth. It helped bring up the volume a little,
but not nearly as much as I would have liked.
- Removed MIDI Mapper references. It doesn't work with the stream API, and
it doesn't really exist on NT kernels, either.
- Reworked music volume: Except for MIDI, all music volume is controlled
through GSnd and not at the individual song level.
- Removed the mididevice global variable.
- Removed snd_midivolume. Now that all music uses a linear volume scale,
there's no need for two separate music volume controls.
- Increased snd_samplerate default up to 48000.
- Added snd_format, defaulting to "PCM-16".
- Added snd_speakermode, defaulting to "Auto".
- Replaced snd_fpu with snd_resampler, defaulting to "Linear".
- Bumped the snd_channels default up from a pitiful 12 to 32.
- Changed snd_3d default to true. The new cvar snd_hw3d determines if
hardware 3D support is used and default to false.
- Removed the libFLAC source, since FMOD Ex has native FLAC support.
- Removed the altsound code, since it was terribly gimped in comparison to
the FMOD code. It's original purpose was to have been as a springboard for
writing a non-FMOD sound system for Unix-y systems, but that never
happened.
- Finished preliminary FMOD Ex support.
SVN r789 (trunk)
2008-03-09 03:13:49 +00:00
|
|
|
{
|
2008-07-01 01:28:22 +00:00
|
|
|
// Set general music volume.
|
2010-03-05 03:11:10 +00:00
|
|
|
if (GSnd != NULL)
|
|
|
|
{
|
|
|
|
GSnd->SetMusicVolume(clamp<float>(self * relative_volume, 0, 1));
|
|
|
|
}
|
VERY IMPORTANT NOTE FOR ANYBODY BUILDING FROM THE TRUNK: This commit adds support
for FMOD Ex while at the same time removing support for FMOD 3. Be sure to update
your SDKs. GCC users, be sure to do a "make cleandep && make clean" before
building, or you will likely get inexplicable errors.
- Fixed: If you wanted to make cleandep with MinGW, you had to specifically
specify Makefile.mingw as the makefile to use.
- Added a normalizer to the OPL synth. It helped bring up the volume a little,
but not nearly as much as I would have liked.
- Removed MIDI Mapper references. It doesn't work with the stream API, and
it doesn't really exist on NT kernels, either.
- Reworked music volume: Except for MIDI, all music volume is controlled
through GSnd and not at the individual song level.
- Removed the mididevice global variable.
- Removed snd_midivolume. Now that all music uses a linear volume scale,
there's no need for two separate music volume controls.
- Increased snd_samplerate default up to 48000.
- Added snd_format, defaulting to "PCM-16".
- Added snd_speakermode, defaulting to "Auto".
- Replaced snd_fpu with snd_resampler, defaulting to "Linear".
- Bumped the snd_channels default up from a pitiful 12 to 32.
- Changed snd_3d default to true. The new cvar snd_hw3d determines if
hardware 3D support is used and default to false.
- Removed the libFLAC source, since FMOD Ex has native FLAC support.
- Removed the altsound code, since it was terribly gimped in comparison to
the FMOD code. It's original purpose was to have been as a springboard for
writing a non-FMOD sound system for Unix-y systems, but that never
happened.
- Finished preliminary FMOD Ex support.
SVN r789 (trunk)
2008-03-09 03:13:49 +00:00
|
|
|
// For music not implemented through the digital sound system,
|
2008-03-28 03:19:18 +00:00
|
|
|
// let them know about the change.
|
VERY IMPORTANT NOTE FOR ANYBODY BUILDING FROM THE TRUNK: This commit adds support
for FMOD Ex while at the same time removing support for FMOD 3. Be sure to update
your SDKs. GCC users, be sure to do a "make cleandep && make clean" before
building, or you will likely get inexplicable errors.
- Fixed: If you wanted to make cleandep with MinGW, you had to specifically
specify Makefile.mingw as the makefile to use.
- Added a normalizer to the OPL synth. It helped bring up the volume a little,
but not nearly as much as I would have liked.
- Removed MIDI Mapper references. It doesn't work with the stream API, and
it doesn't really exist on NT kernels, either.
- Reworked music volume: Except for MIDI, all music volume is controlled
through GSnd and not at the individual song level.
- Removed the mididevice global variable.
- Removed snd_midivolume. Now that all music uses a linear volume scale,
there's no need for two separate music volume controls.
- Increased snd_samplerate default up to 48000.
- Added snd_format, defaulting to "PCM-16".
- Added snd_speakermode, defaulting to "Auto".
- Replaced snd_fpu with snd_resampler, defaulting to "Linear".
- Bumped the snd_channels default up from a pitiful 12 to 32.
- Changed snd_3d default to true. The new cvar snd_hw3d determines if
hardware 3D support is used and default to false.
- Removed the libFLAC source, since FMOD Ex has native FLAC support.
- Removed the altsound code, since it was terribly gimped in comparison to
the FMOD code. It's original purpose was to have been as a springboard for
writing a non-FMOD sound system for Unix-y systems, but that never
happened.
- Finished preliminary FMOD Ex support.
SVN r789 (trunk)
2008-03-09 03:13:49 +00:00
|
|
|
if (currSong != NULL)
|
|
|
|
{
|
|
|
|
currSong->MusicVolumeChanged();
|
|
|
|
}
|
2008-03-28 03:19:18 +00:00
|
|
|
else
|
|
|
|
{ // If the music was stopped because volume was 0, start it now.
|
|
|
|
S_RestartMusic();
|
|
|
|
}
|
VERY IMPORTANT NOTE FOR ANYBODY BUILDING FROM THE TRUNK: This commit adds support
for FMOD Ex while at the same time removing support for FMOD 3. Be sure to update
your SDKs. GCC users, be sure to do a "make cleandep && make clean" before
building, or you will likely get inexplicable errors.
- Fixed: If you wanted to make cleandep with MinGW, you had to specifically
specify Makefile.mingw as the makefile to use.
- Added a normalizer to the OPL synth. It helped bring up the volume a little,
but not nearly as much as I would have liked.
- Removed MIDI Mapper references. It doesn't work with the stream API, and
it doesn't really exist on NT kernels, either.
- Reworked music volume: Except for MIDI, all music volume is controlled
through GSnd and not at the individual song level.
- Removed the mididevice global variable.
- Removed snd_midivolume. Now that all music uses a linear volume scale,
there's no need for two separate music volume controls.
- Increased snd_samplerate default up to 48000.
- Added snd_format, defaulting to "PCM-16".
- Added snd_speakermode, defaulting to "Auto".
- Replaced snd_fpu with snd_resampler, defaulting to "Linear".
- Bumped the snd_channels default up from a pitiful 12 to 32.
- Changed snd_3d default to true. The new cvar snd_hw3d determines if
hardware 3D support is used and default to false.
- Removed the libFLAC source, since FMOD Ex has native FLAC support.
- Removed the altsound code, since it was terribly gimped in comparison to
the FMOD code. It's original purpose was to have been as a springboard for
writing a non-FMOD sound system for Unix-y systems, but that never
happened.
- Finished preliminary FMOD Ex support.
SVN r789 (trunk)
2008-03-09 03:13:49 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-03-28 03:19:18 +00:00
|
|
|
MusInfo::MusInfo()
|
|
|
|
: m_Status(STATE_Stopped), m_Looping(false), m_NotStartedYet(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
MusInfo::~MusInfo ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-08-03 03:54:48 +00:00
|
|
|
bool MusInfo::SetPosition (unsigned int ms)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MusInfo::SetSubsong (int subsong)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
void MusInfo::Update ()
|
2008-03-04 06:36:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
VERY IMPORTANT NOTE FOR ANYBODY BUILDING FROM THE TRUNK: This commit adds support
for FMOD Ex while at the same time removing support for FMOD 3. Be sure to update
your SDKs. GCC users, be sure to do a "make cleandep && make clean" before
building, or you will likely get inexplicable errors.
- Fixed: If you wanted to make cleandep with MinGW, you had to specifically
specify Makefile.mingw as the makefile to use.
- Added a normalizer to the OPL synth. It helped bring up the volume a little,
but not nearly as much as I would have liked.
- Removed MIDI Mapper references. It doesn't work with the stream API, and
it doesn't really exist on NT kernels, either.
- Reworked music volume: Except for MIDI, all music volume is controlled
through GSnd and not at the individual song level.
- Removed the mididevice global variable.
- Removed snd_midivolume. Now that all music uses a linear volume scale,
there's no need for two separate music volume controls.
- Increased snd_samplerate default up to 48000.
- Added snd_format, defaulting to "PCM-16".
- Added snd_speakermode, defaulting to "Auto".
- Replaced snd_fpu with snd_resampler, defaulting to "Linear".
- Bumped the snd_channels default up from a pitiful 12 to 32.
- Changed snd_3d default to true. The new cvar snd_hw3d determines if
hardware 3D support is used and default to false.
- Removed the libFLAC source, since FMOD Ex has native FLAC support.
- Removed the altsound code, since it was terribly gimped in comparison to
the FMOD code. It's original purpose was to have been as a springboard for
writing a non-FMOD sound system for Unix-y systems, but that never
happened.
- Finished preliminary FMOD Ex support.
SVN r789 (trunk)
2008-03-09 03:13:49 +00:00
|
|
|
void MusInfo::MusicVolumeChanged()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MusInfo::TimidityVolumeChanged()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-15 19:54:59 +00:00
|
|
|
void MusInfo::FluidSettingInt(const char *, int)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MusInfo::FluidSettingNum(const char *, double)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MusInfo::FluidSettingStr(const char *, const char *)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
FString MusInfo::GetStats()
|
|
|
|
{
|
|
|
|
return "No stats available for this song";
|
|
|
|
}
|
|
|
|
|
2008-04-03 02:31:39 +00:00
|
|
|
MusInfo *MusInfo::GetOPLDumper(const char *filename)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-19 21:36:53 +00:00
|
|
|
MusInfo *MusInfo::GetWaveDumper(const char *filename, int rate)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
void I_InitMusic (void)
|
|
|
|
{
|
|
|
|
static bool setatterm = false;
|
|
|
|
|
2008-04-11 04:59:23 +00:00
|
|
|
Timidity::LoadConfig();
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
snd_musicvolume.Callback ();
|
|
|
|
|
2008-03-12 02:56:11 +00:00
|
|
|
nomusic = !!Args->CheckParm("-nomusic") || !!Args->CheckParm("-nosound");
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
I_InitMusicWin32 ();
|
|
|
|
#endif // _WIN32
|
|
|
|
|
|
|
|
if (!setatterm)
|
|
|
|
{
|
|
|
|
setatterm = true;
|
|
|
|
atterm (I_ShutdownMusic);
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
signal (SIGCHLD, ChildSigHandler);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
MusicDown = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-12 03:14:40 +00:00
|
|
|
void I_ShutdownMusic(void)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (MusicDown)
|
|
|
|
return;
|
|
|
|
MusicDown = true;
|
|
|
|
if (currSong)
|
|
|
|
{
|
|
|
|
S_StopMusic (true);
|
|
|
|
assert (currSong == NULL);
|
|
|
|
}
|
2008-04-11 04:59:23 +00:00
|
|
|
Timidity::FreeAll();
|
2006-02-24 04:48:15 +00:00
|
|
|
#ifdef _WIN32
|
2008-04-11 04:59:23 +00:00
|
|
|
I_ShutdownMusicWin32();
|
2006-02-24 04:48:15 +00:00
|
|
|
#endif // _WIN32
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-03 03:54:48 +00:00
|
|
|
void I_PlaySong (void *handle, int _looping, float rel_vol, int subsong)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
MusInfo *info = (MusInfo *)handle;
|
|
|
|
|
|
|
|
if (!info || nomusic)
|
|
|
|
return;
|
|
|
|
|
2006-04-14 12:58:52 +00:00
|
|
|
saved_relative_volume = relative_volume = rel_vol;
|
2006-02-24 04:48:15 +00:00
|
|
|
info->Stop ();
|
2008-08-03 03:54:48 +00:00
|
|
|
info->Play (!!_looping, subsong);
|
2008-03-28 03:19:18 +00:00
|
|
|
info->m_NotStartedYet = false;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (info->m_Status == MusInfo::STATE_Playing)
|
|
|
|
currSong = info;
|
|
|
|
else
|
|
|
|
currSong = NULL;
|
2008-03-27 00:05:32 +00:00
|
|
|
|
|
|
|
// Notify the sound system of the changed relative volume
|
|
|
|
snd_musicvolume.Callback();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void I_PauseSong (void *handle)
|
|
|
|
{
|
|
|
|
MusInfo *info = (MusInfo *)handle;
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
info->Pause ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void I_ResumeSong (void *handle)
|
|
|
|
{
|
|
|
|
MusInfo *info = (MusInfo *)handle;
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
info->Resume ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void I_StopSong (void *handle)
|
|
|
|
{
|
|
|
|
MusInfo *info = (MusInfo *)handle;
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
info->Stop ();
|
|
|
|
|
|
|
|
if (info == currSong)
|
|
|
|
currSong = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void I_UnRegisterSong (void *handle)
|
|
|
|
{
|
|
|
|
MusInfo *info = (MusInfo *)handle;
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
delete info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-03 03:54:48 +00:00
|
|
|
MusInfo *I_RegisterURLSong (const char *url)
|
2008-04-30 05:36:24 +00:00
|
|
|
{
|
|
|
|
StreamSong *song;
|
|
|
|
|
|
|
|
song = new StreamSong(url, 0, 0);
|
|
|
|
if (song->IsValid())
|
|
|
|
{
|
|
|
|
return song;
|
|
|
|
}
|
|
|
|
delete song;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-06-03 03:05:02 +00:00
|
|
|
MusInfo *I_RegisterSong (const char *filename, BYTE *musiccache, int offset, int len, int device)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
MusInfo *info = NULL;
|
2010-04-06 03:12:32 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
DWORD id[32/4];
|
|
|
|
BYTE idstr[32];
|
|
|
|
};
|
2009-06-03 03:05:02 +00:00
|
|
|
const char *fmt;
|
|
|
|
BYTE *ungzipped;
|
2010-04-06 03:12:32 +00:00
|
|
|
int i;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (nomusic)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
if (offset != -1)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-04-14 12:58:52 +00:00
|
|
|
file = fopen (filename, "rb");
|
|
|
|
if (file == NULL)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2006-04-14 12:58:52 +00:00
|
|
|
if (len == 0 && offset == 0)
|
|
|
|
{
|
|
|
|
fseek (file, 0, SEEK_END);
|
|
|
|
len = ftell (file);
|
|
|
|
fseek (file, 0, SEEK_SET);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fseek (file, offset, SEEK_SET);
|
|
|
|
}
|
2010-04-06 03:12:32 +00:00
|
|
|
if (len < 32)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (fread (id, 4, 32/4, file) != 32/4)
|
2006-04-14 12:58:52 +00:00
|
|
|
{
|
|
|
|
fclose (file);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-04-06 03:12:32 +00:00
|
|
|
fseek (file, -32, SEEK_CUR);
|
2006-04-14 12:58:52 +00:00
|
|
|
}
|
|
|
|
else
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-04-14 12:58:52 +00:00
|
|
|
file = NULL;
|
2010-04-06 03:12:32 +00:00
|
|
|
if (len < 32)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 32/4; ++i)
|
|
|
|
{
|
|
|
|
id[i] = ((DWORD *)musiccache)[i];
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-03-27 00:05:32 +00:00
|
|
|
#ifndef _WIN32
|
2010-04-06 03:12:32 +00:00
|
|
|
// non-Windows platforms don't support MDEV_MMAPI so map to MDEV_FMOD
|
2009-06-03 03:05:02 +00:00
|
|
|
if (device == MDEV_MMAPI)
|
|
|
|
device = MDEV_FMOD;
|
2008-03-27 00:05:32 +00:00
|
|
|
#endif
|
|
|
|
|
2009-06-03 03:05:02 +00:00
|
|
|
// Check for gzip compression. Some formats are expected to have players
|
|
|
|
// that can handle it, so it simplifies things if we make all songs
|
|
|
|
// gzippable.
|
|
|
|
ungzipped = NULL;
|
2010-04-06 03:12:32 +00:00
|
|
|
if ((id[0] & MAKE_ID(255,255,255,0)) == GZIP_ID)
|
2009-06-03 03:05:02 +00:00
|
|
|
{
|
|
|
|
if (offset != -1)
|
|
|
|
{
|
|
|
|
BYTE *gzipped = new BYTE[len];
|
|
|
|
if (fread(gzipped, 1, len, file) != (size_t)len)
|
|
|
|
{
|
|
|
|
delete[] gzipped;
|
|
|
|
fclose(file);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ungzipped = ungzip(gzipped, &len);
|
|
|
|
delete[] gzipped;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ungzipped = ungzip(musiccache, &len);
|
|
|
|
}
|
|
|
|
if (ungzipped == NULL)
|
|
|
|
{
|
|
|
|
fclose(file);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
musiccache = ungzipped;
|
2010-04-06 03:12:32 +00:00
|
|
|
for (i = 0; i < 32/4; ++i)
|
|
|
|
{
|
|
|
|
id[i] = ((DWORD *)musiccache)[i];
|
|
|
|
}
|
2009-06-03 03:05:02 +00:00
|
|
|
}
|
2008-03-27 00:05:32 +00:00
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
// Check for MUS format
|
2010-04-06 03:12:32 +00:00
|
|
|
// Tolerate sloppy wads by searching up to 32 bytes for the header
|
|
|
|
if (MUSHeaderSearch(idstr, sizeof(idstr)) >= 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-07-01 01:28:22 +00:00
|
|
|
/* MUS are played as:
|
|
|
|
- OPL:
|
|
|
|
- if explicitly selected by $mididevice
|
|
|
|
- when snd_mididevice is -3 and no midi device is set for the song
|
|
|
|
|
|
|
|
Timidity:
|
|
|
|
- if explicitly selected by $mididevice
|
|
|
|
- when snd_mididevice is -2 and no midi device is set for the song
|
|
|
|
|
|
|
|
FMod:
|
|
|
|
- if explicitly selected by $mididevice
|
|
|
|
- when snd_mididevice is -1 and no midi device is set for the song
|
|
|
|
- as fallback when both OPL and Timidity failed unless snd_mididevice is >= 0
|
|
|
|
|
|
|
|
MMAPI (Win32 only):
|
|
|
|
- if explicitly selected by $mididevice (non-Win32 redirects this to FMOD)
|
|
|
|
- when snd_mididevice is >= 0 and no midi device is set for the song
|
|
|
|
- as fallback when both OPL and Timidity failed and snd_mididevice is >= 0
|
|
|
|
*/
|
|
|
|
if ((snd_mididevice == -3 && device == MDEV_DEFAULT) || device == MDEV_OPL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-07-01 01:28:22 +00:00
|
|
|
info = new MUSSong2 (file, musiccache, len, MIDI_OPL);
|
|
|
|
}
|
|
|
|
else if (device == MDEV_TIMIDITY || (device == MDEV_DEFAULT && snd_mididevice == -2))
|
|
|
|
{
|
|
|
|
info = new TimiditySong (file, musiccache, len);
|
|
|
|
}
|
|
|
|
else if (snd_mididevice == -4 && device == MDEV_DEFAULT)
|
|
|
|
{
|
|
|
|
info = new MUSSong2(file, musiccache, len, MIDI_Timidity);
|
|
|
|
}
|
2010-08-15 19:54:59 +00:00
|
|
|
#ifdef HAVE_FLUIDSYNTH
|
|
|
|
else if (snd_mididevice == -5 && device == MDEV_DEFAULT)
|
|
|
|
{
|
|
|
|
info = new MUSSong2(file, musiccache, len, MIDI_Fluid);
|
|
|
|
}
|
|
|
|
#endif
|
2008-07-01 01:28:22 +00:00
|
|
|
if (info != NULL && !info->IsValid())
|
|
|
|
{
|
|
|
|
delete info;
|
|
|
|
info = NULL;
|
|
|
|
device = MDEV_DEFAULT;
|
|
|
|
}
|
|
|
|
if (info == NULL && (snd_mididevice == -1 || device == MDEV_FMOD) && device != MDEV_MMAPI)
|
|
|
|
{
|
|
|
|
TArray<BYTE> midi;
|
|
|
|
bool midi_made = false;
|
2008-03-27 00:05:32 +00:00
|
|
|
|
2008-07-01 01:28:22 +00:00
|
|
|
if (file == NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-04-07 02:02:53 +00:00
|
|
|
midi_made = ProduceMIDI((BYTE *)musiccache, len, midi);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2008-07-01 01:28:22 +00:00
|
|
|
else
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-07-01 01:28:22 +00:00
|
|
|
BYTE *mus = new BYTE[len];
|
|
|
|
size_t did_read = fread(mus, 1, len, file);
|
|
|
|
if (did_read == (size_t)len)
|
2008-03-27 00:05:32 +00:00
|
|
|
{
|
2010-04-07 02:02:53 +00:00
|
|
|
midi_made = ProduceMIDI(mus, len, midi);
|
2008-03-27 00:05:32 +00:00
|
|
|
}
|
2008-07-01 01:28:22 +00:00
|
|
|
fseek(file, -(long)did_read, SEEK_CUR);
|
|
|
|
delete[] mus;
|
|
|
|
}
|
|
|
|
if (midi_made)
|
|
|
|
{
|
|
|
|
info = new StreamSong((char *)&midi[0], -1, midi.Size());
|
|
|
|
if (!info->IsValid())
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
{
|
2008-07-01 01:28:22 +00:00
|
|
|
delete info;
|
|
|
|
info = NULL;
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef _WIN32
|
2008-03-27 00:05:32 +00:00
|
|
|
if (info == NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-11 04:59:23 +00:00
|
|
|
info = new MUSSong2 (file, musiccache, len, MIDI_Win);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
#endif // _WIN32
|
|
|
|
}
|
2008-03-27 00:05:32 +00:00
|
|
|
// Check for MIDI format
|
|
|
|
else
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-04-06 03:12:32 +00:00
|
|
|
if (id[0] == MAKE_ID('M','T','h','d'))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-03-27 00:05:32 +00:00
|
|
|
// This is a midi file
|
|
|
|
|
|
|
|
/* MIDI are played as:
|
2008-03-29 05:01:38 +00:00
|
|
|
OPL:
|
|
|
|
- if explicitly selected by $mididevice
|
|
|
|
- when snd_mididevice is -3 and no midi device is set for the song
|
|
|
|
|
2008-03-27 00:05:32 +00:00
|
|
|
Timidity:
|
|
|
|
- if explicitly selected by $mididevice
|
|
|
|
- when snd_mididevice is -2 and no midi device is set for the song
|
|
|
|
|
2009-06-03 03:05:02 +00:00
|
|
|
FMOD:
|
2008-03-27 00:05:32 +00:00
|
|
|
- if explicitly selected by $mididevice
|
|
|
|
- when snd_mididevice is -1 and no midi device is set for the song
|
|
|
|
- as fallback when Timidity failed unless snd_mididevice is >= 0
|
|
|
|
|
|
|
|
MMAPI (Win32 only):
|
|
|
|
- if explicitly selected by $mididevice (non-Win32 redirects this to FMOD)
|
|
|
|
- when snd_mididevice is >= 0 and no midi device is set for the song
|
|
|
|
- as fallback when Timidity failed and snd_mididevice is >= 0
|
|
|
|
*/
|
2008-07-01 01:28:22 +00:00
|
|
|
if (device == MDEV_OPL || (snd_mididevice == -3 && device == MDEV_DEFAULT))
|
2008-03-29 05:01:38 +00:00
|
|
|
{
|
2008-04-11 04:59:23 +00:00
|
|
|
info = new MIDISong2 (file, musiccache, len, MIDI_OPL);
|
2008-03-29 05:01:38 +00:00
|
|
|
}
|
2008-07-01 01:28:22 +00:00
|
|
|
else if (device == MDEV_TIMIDITY || (snd_mididevice == -2 && device == MDEV_DEFAULT))
|
2006-04-14 12:58:52 +00:00
|
|
|
{
|
2008-03-27 00:05:32 +00:00
|
|
|
info = new TimiditySong (file, musiccache, len);
|
2008-03-29 05:01:38 +00:00
|
|
|
}
|
2008-07-01 01:28:22 +00:00
|
|
|
else if (snd_mididevice == -4 && device == MDEV_DEFAULT)
|
2008-04-11 04:59:23 +00:00
|
|
|
{
|
|
|
|
info = new MIDISong2(file, musiccache, len, MIDI_Timidity);
|
|
|
|
}
|
2008-03-29 05:01:38 +00:00
|
|
|
if (info != NULL && !info->IsValid())
|
|
|
|
{
|
|
|
|
delete info;
|
|
|
|
info = NULL;
|
|
|
|
device = MDEV_DEFAULT;
|
2008-03-27 00:05:32 +00:00
|
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (info == NULL && device != MDEV_FMOD && (snd_mididevice >= 0 || device == MDEV_MMAPI))
|
|
|
|
{
|
2008-04-11 04:59:23 +00:00
|
|
|
info = new MIDISong2 (file, musiccache, len, MIDI_Win);
|
2006-04-14 12:58:52 +00:00
|
|
|
}
|
2008-03-27 00:05:32 +00:00
|
|
|
#endif // _WIN32
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2008-04-03 02:31:39 +00:00
|
|
|
// Check for various raw OPL formats
|
2010-04-06 03:12:32 +00:00
|
|
|
else if (
|
|
|
|
(id[0] == MAKE_ID('R','A','W','A') && id[1] == MAKE_ID('D','A','T','A')) || // Rdos Raw OPL
|
|
|
|
(id[0] == MAKE_ID('D','B','R','A') && id[1] == MAKE_ID('W','O','P','L')) || // DosBox Raw OPL
|
|
|
|
(id[0] == MAKE_ID('A','D','L','I') && *((BYTE *)id + 4) == 'B')) // Martin Fernandez's modified IMF
|
2006-04-14 12:58:52 +00:00
|
|
|
{
|
2010-04-06 03:12:32 +00:00
|
|
|
info = new OPLMUSSong (file, musiccache, len);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-06-03 03:05:02 +00:00
|
|
|
// Check for game music
|
2010-04-06 03:12:32 +00:00
|
|
|
else if ((fmt = GME_CheckFormat(id[0])) != NULL && fmt[0] != '\0')
|
2009-06-03 03:05:02 +00:00
|
|
|
{
|
|
|
|
info = GME_OpenSong(file, musiccache, len, fmt);
|
|
|
|
}
|
2008-05-29 23:33:07 +00:00
|
|
|
// Check for module formats
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info = MOD_OpenSong(file, musiccache, len);
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (info == NULL)
|
|
|
|
{
|
|
|
|
// Check for CDDA "format"
|
2010-04-06 03:12:32 +00:00
|
|
|
if (id[0] == (('R')|(('I')<<8)|(('F')<<16)|(('F')<<24)))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-04-14 12:58:52 +00:00
|
|
|
if (file != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-04-14 12:58:52 +00:00
|
|
|
DWORD subid;
|
|
|
|
|
|
|
|
fseek (file, 8, SEEK_CUR);
|
|
|
|
if (fread (&subid, 4, 1, file) != 1)
|
|
|
|
{
|
|
|
|
fclose (file);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fseek (file, -12, SEEK_CUR);
|
|
|
|
|
|
|
|
if (subid == (('C')|(('D')<<8)|(('D')<<16)|(('A')<<24)))
|
|
|
|
{
|
|
|
|
// This is a CDDA file
|
|
|
|
info = new CDDAFile (file, len);
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-27 00:05:32 +00:00
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
// no FMOD => no modules/streams
|
|
|
|
// 1024 bytes is an arbitrary restriction. It's assumed that anything
|
|
|
|
// smaller than this can't possibly be a valid music file if it hasn't
|
|
|
|
// been identified already, so don't even bother trying to load it.
|
2008-03-27 00:05:32 +00:00
|
|
|
// Of course MIDIs shorter than 1024 bytes should pass.
|
2010-04-06 03:12:32 +00:00
|
|
|
if (info == NULL && (len >= 1024 || id[0] == MAKE_ID('M','T','h','d')))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-03-16 00:54:53 +00:00
|
|
|
// Let FMOD figure out what it is.
|
VERY IMPORTANT NOTE FOR ANYBODY BUILDING FROM THE TRUNK: This commit adds support
for FMOD Ex while at the same time removing support for FMOD 3. Be sure to update
your SDKs. GCC users, be sure to do a "make cleandep && make clean" before
building, or you will likely get inexplicable errors.
- Fixed: If you wanted to make cleandep with MinGW, you had to specifically
specify Makefile.mingw as the makefile to use.
- Added a normalizer to the OPL synth. It helped bring up the volume a little,
but not nearly as much as I would have liked.
- Removed MIDI Mapper references. It doesn't work with the stream API, and
it doesn't really exist on NT kernels, either.
- Reworked music volume: Except for MIDI, all music volume is controlled
through GSnd and not at the individual song level.
- Removed the mididevice global variable.
- Removed snd_midivolume. Now that all music uses a linear volume scale,
there's no need for two separate music volume controls.
- Increased snd_samplerate default up to 48000.
- Added snd_format, defaulting to "PCM-16".
- Added snd_speakermode, defaulting to "Auto".
- Replaced snd_fpu with snd_resampler, defaulting to "Linear".
- Bumped the snd_channels default up from a pitiful 12 to 32.
- Changed snd_3d default to true. The new cvar snd_hw3d determines if
hardware 3D support is used and default to false.
- Removed the libFLAC source, since FMOD Ex has native FLAC support.
- Removed the altsound code, since it was terribly gimped in comparison to
the FMOD code. It's original purpose was to have been as a springboard for
writing a non-FMOD sound system for Unix-y systems, but that never
happened.
- Finished preliminary FMOD Ex support.
SVN r789 (trunk)
2008-03-09 03:13:49 +00:00
|
|
|
if (file != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
VERY IMPORTANT NOTE FOR ANYBODY BUILDING FROM THE TRUNK: This commit adds support
for FMOD Ex while at the same time removing support for FMOD 3. Be sure to update
your SDKs. GCC users, be sure to do a "make cleandep && make clean" before
building, or you will likely get inexplicable errors.
- Fixed: If you wanted to make cleandep with MinGW, you had to specifically
specify Makefile.mingw as the makefile to use.
- Added a normalizer to the OPL synth. It helped bring up the volume a little,
but not nearly as much as I would have liked.
- Removed MIDI Mapper references. It doesn't work with the stream API, and
it doesn't really exist on NT kernels, either.
- Reworked music volume: Except for MIDI, all music volume is controlled
through GSnd and not at the individual song level.
- Removed the mididevice global variable.
- Removed snd_midivolume. Now that all music uses a linear volume scale,
there's no need for two separate music volume controls.
- Increased snd_samplerate default up to 48000.
- Added snd_format, defaulting to "PCM-16".
- Added snd_speakermode, defaulting to "Auto".
- Replaced snd_fpu with snd_resampler, defaulting to "Linear".
- Bumped the snd_channels default up from a pitiful 12 to 32.
- Changed snd_3d default to true. The new cvar snd_hw3d determines if
hardware 3D support is used and default to false.
- Removed the libFLAC source, since FMOD Ex has native FLAC support.
- Removed the altsound code, since it was terribly gimped in comparison to
the FMOD code. It's original purpose was to have been as a springboard for
writing a non-FMOD sound system for Unix-y systems, but that never
happened.
- Finished preliminary FMOD Ex support.
SVN r789 (trunk)
2008-03-09 03:13:49 +00:00
|
|
|
fclose (file);
|
|
|
|
file = NULL;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-06-03 03:05:02 +00:00
|
|
|
info = new StreamSong (offset >= 0 ? filename : (const char *)musiccache, offset, len);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info && !info->IsValid ())
|
|
|
|
{
|
|
|
|
delete info;
|
|
|
|
info = NULL;
|
|
|
|
}
|
|
|
|
if (file != NULL)
|
|
|
|
{
|
|
|
|
fclose (file);
|
|
|
|
}
|
2009-06-03 03:05:02 +00:00
|
|
|
if (ungzipped != NULL)
|
|
|
|
{
|
|
|
|
delete[] ungzipped;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2008-08-03 03:54:48 +00:00
|
|
|
MusInfo *I_RegisterCDSong (int track, int id)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
MusInfo *info = new CDSong (track, id);
|
|
|
|
|
|
|
|
if (info && !info->IsValid ())
|
|
|
|
{
|
|
|
|
delete info;
|
|
|
|
info = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2009-06-03 03:05:02 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ungzip
|
|
|
|
//
|
|
|
|
// VGZ files are compressed with gzip, so we need to uncompress them before
|
|
|
|
// handing them to GME.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
BYTE *ungzip(BYTE *data, int *complen)
|
|
|
|
{
|
|
|
|
const BYTE *max = data + *complen - 8;
|
|
|
|
const BYTE *compstart = data + 10;
|
|
|
|
BYTE flags = data[3];
|
|
|
|
unsigned isize;
|
|
|
|
BYTE *newdata;
|
|
|
|
z_stream stream;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
// Find start of compressed data stream
|
|
|
|
if (flags & GZIP_FEXTRA)
|
|
|
|
{
|
|
|
|
compstart += 2 + LittleShort(*(WORD *)(data + 10));
|
|
|
|
}
|
|
|
|
if (flags & GZIP_FNAME)
|
|
|
|
{
|
|
|
|
while (compstart < max && *compstart != 0)
|
|
|
|
{
|
|
|
|
compstart++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flags & GZIP_FCOMMENT)
|
|
|
|
{
|
|
|
|
while (compstart < max && *compstart != 0)
|
|
|
|
{
|
|
|
|
compstart++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flags & GZIP_FHCRC)
|
|
|
|
{
|
|
|
|
compstart += 2;
|
|
|
|
}
|
|
|
|
if (compstart >= max - 1)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decompress
|
|
|
|
isize = LittleLong(*(DWORD *)(data + *complen - 4));
|
|
|
|
newdata = new BYTE[isize];
|
|
|
|
|
|
|
|
stream.next_in = (Bytef *)compstart;
|
|
|
|
stream.avail_in = (uInt)(max - compstart);
|
|
|
|
stream.next_out = newdata;
|
|
|
|
stream.avail_out = isize;
|
|
|
|
stream.zalloc = (alloc_func)0;
|
|
|
|
stream.zfree = (free_func)0;
|
|
|
|
|
|
|
|
err = inflateInit2(&stream, -MAX_WBITS);
|
|
|
|
if (err != Z_OK)
|
|
|
|
{
|
|
|
|
delete[] newdata;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = inflate(&stream, Z_FINISH);
|
|
|
|
if (err != Z_STREAM_END)
|
|
|
|
{
|
|
|
|
inflateEnd(&stream);
|
|
|
|
delete[] newdata;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
err = inflateEnd(&stream);
|
|
|
|
if (err != Z_OK)
|
|
|
|
{
|
|
|
|
delete[] newdata;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*complen = isize;
|
|
|
|
return newdata;
|
|
|
|
}
|
|
|
|
|
2008-03-05 03:10:31 +00:00
|
|
|
void I_UpdateMusic()
|
|
|
|
{
|
|
|
|
if (currSong != NULL)
|
|
|
|
{
|
|
|
|
currSong->Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
// Is the song playing?
|
|
|
|
bool I_QrySongPlaying (void *handle)
|
|
|
|
{
|
|
|
|
MusInfo *info = (MusInfo *)handle;
|
|
|
|
|
|
|
|
return info ? info->IsPlaying () : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change to a different part of the song
|
|
|
|
bool I_SetSongPosition (void *handle, int order)
|
|
|
|
{
|
|
|
|
MusInfo *info = (MusInfo *)handle;
|
|
|
|
return info ? info->SetPosition (order) : false;
|
|
|
|
}
|
|
|
|
|
2006-04-14 12:58:52 +00:00
|
|
|
// Sets relative music volume. Takes $musicvolume in SNDINFO into consideration
|
|
|
|
void I_SetMusicVolume (float factor)
|
|
|
|
{
|
|
|
|
factor = clamp<float>(factor, 0, 2.0f);
|
|
|
|
relative_volume = saved_relative_volume * factor;
|
|
|
|
snd_musicvolume.Callback();
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
CCMD(testmusicvol)
|
|
|
|
{
|
|
|
|
if (argv.argc() > 1)
|
|
|
|
{
|
|
|
|
relative_volume = (float)strtod(argv[1], NULL);
|
|
|
|
snd_musicvolume.Callback();
|
|
|
|
}
|
2008-03-09 16:30:36 +00:00
|
|
|
else
|
|
|
|
Printf("Current relative volume is %1.2f\n", relative_volume);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
- The garbage collector is now run one last time just before exiting the game.
- Removed movie volume from the sound menu and renamed some of the other
options to give the MIDI device name more room to display itself.
- Moved the midi device selection into the main sound menu.
- Added FMOD as MIDI device -1, to replace the MIDI mapper. This is still the
default device. By default, it uses exactly the same DLS instruments as the
Microsoft GS Wavetable Synth. If you have another set DLS level 1 patch set
you want to use, set the snd_midipatchfile cvar to specify where it should
load the instruments from.
- Changed the ProduceMIDI function to store its output into a TArray<BYTE>.
An overloaded version wraps around it to continue to supply file-writing
support for external Timidity++ usage.
- Added an FMOD credits banner to comply with their non-commercial license.
- Reimplemented the snd_buffersize cvar for the FMOD Ex sound system. Rather
than a time in ms, this is now the length in samples of the DSP buffer.
Also added the snd_buffercount cvar to offer complete control over the
call to FMOD::System::setDSPBufferSize(). Note that with any snd_samplerate
below about 44kHz, you will need to set snd_buffersize to avoid long
latencies.
- Reimplemented the snd_output cvar for the FMOD Ex sound system.
- Changed snd_samplerate default to 0. This now means to use the default
sample rate.
- Made snd_output, snd_output_format, snd_speakermode, snd_resampler, and
snd_hrtf available through the menu.
- Split the HRTF effect selection into its own cvar: snd_hrtf.
- Removed 96000 Hz option from the menu. It's still available through the
cvar, if desired.
- Fixed: If Windows sound init failed, retry with DirectSound. (Apparently,
WASAPI doesn't work with more than two speakers and PCM-Float output at the
same time.)
- Fixed: Area sounds only played from the front speakers once you got within
the 2D panning area.
SVN r854 (trunk)
2008-03-26 04:27:07 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// STAT music
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
ADD_STAT(music)
|
|
|
|
{
|
|
|
|
if (currSong != NULL)
|
|
|
|
{
|
|
|
|
return currSong->GetStats();
|
|
|
|
}
|
|
|
|
return "No song playing";
|
|
|
|
}
|
2008-04-03 02:31:39 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CCMD writeopl
|
|
|
|
//
|
|
|
|
// If the current song can be played with OPL instruments, dump it to
|
|
|
|
// the specified file on disk.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
CCMD (writeopl)
|
|
|
|
{
|
|
|
|
if (argv.argc() == 2)
|
|
|
|
{
|
|
|
|
if (currSong == NULL)
|
|
|
|
{
|
|
|
|
Printf ("No song is currently playing.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MusInfo *dumper = currSong->GetOPLDumper(argv[1]);
|
|
|
|
if (dumper == NULL)
|
|
|
|
{
|
|
|
|
Printf ("Current song cannot be saved as OPL data.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-03 03:54:48 +00:00
|
|
|
dumper->Play(false, 0); // FIXME: Remember subsong.
|
2008-04-03 02:31:39 +00:00
|
|
|
delete dumper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf ("Usage: writeopl <filename>");
|
|
|
|
}
|
|
|
|
}
|
2008-04-19 21:36:53 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CCMD writewave
|
|
|
|
//
|
|
|
|
// If the current song can be represented as a waveform, dump it to
|
|
|
|
// the specified file on disk. The sample rate parameter is merely a
|
|
|
|
// suggestion, and the dumper is free to ignore it.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
CCMD (writewave)
|
|
|
|
{
|
|
|
|
if (argv.argc() >= 2 && argv.argc() <= 3)
|
|
|
|
{
|
|
|
|
if (currSong == NULL)
|
|
|
|
{
|
|
|
|
Printf ("No song is currently playing.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MusInfo *dumper = currSong->GetWaveDumper(argv[1], argv.argc() == 3 ? atoi(argv[2]) : 0);
|
|
|
|
if (dumper == NULL)
|
|
|
|
{
|
|
|
|
Printf ("Current song cannot be saved as wave data.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-03 03:54:48 +00:00
|
|
|
dumper->Play(false, 0); // FIXME: Remember subsong
|
2008-04-19 21:36:53 +00:00
|
|
|
delete dumper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf ("Usage: writewave <filename> [sample rate]");
|
|
|
|
}
|
|
|
|
}
|