qzdoom/src/sound/music_mus_opl.cpp

86 lines
1.7 KiB
C++
Raw Normal View History

#include "i_musicinterns.h"
CUSTOM_CVAR (Int, opl_frequency, 49716, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{ // Clamp frequency to FMOD's limits
if (self < 4000)
self = 4000;
else if (self > 49716) // No need to go higher than this
self = 49716;
}
CVAR (Bool, opl_enable, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
static bool OPL_Active;
CUSTOM_CVAR (Bool, opl_onechip, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
if (OPL_Active && currSong != NULL)
{
static_cast<OPLMUSSong *>(currSong)->ResetChips ();
}
}
2006-04-14 12:58:52 +00:00
OPLMUSSong::OPLMUSSong (FILE *file, char * musiccache, int len)
{
int rate = *opl_frequency;
int samples = rate/14;
2006-04-14 12:58:52 +00:00
Music = new OPLmusicBlock (file, musiccache, len, rate, samples);
m_Stream = GSnd->CreateStream (FillStream, samples*2,
SoundStream::Mono, rate, this);
if (m_Stream == NULL)
{
Printf (PRINT_BOLD, "Could not create music stream.\n");
delete Music;
return;
}
OPL_Active = true;
}
OPLMUSSong::~OPLMUSSong ()
{
OPL_Active = false;
Stop ();
if (Music != NULL)
{
delete Music;
}
}
bool OPLMUSSong::IsValid () const
{
return m_Stream != NULL;
}
void OPLMUSSong::ResetChips ()
{
Music->ResetChips ();
}
bool OPLMUSSong::IsPlaying ()
{
return m_Status == STATE_Playing;
}
void OPLMUSSong::Play (bool looping)
{
m_Status = STATE_Stopped;
m_Looping = looping;
Music->SetLooping (looping);
Music->Restart ();
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 (m_Stream->Play (true, snd_musicvolume, true))
{
m_Status = STATE_Playing;
}
}
bool OPLMUSSong::FillStream (SoundStream *stream, void *buff, int len, void *userdata)
{
OPLMUSSong *song = (OPLMUSSong *)userdata;
return song->Music->ServiceStream (buff, len);
}