2006-02-24 04:48:15 +00:00
|
|
|
#include "i_musicinterns.h"
|
2012-11-06 06:10:04 +00:00
|
|
|
#include "oplsynth/muslib.h"
|
2012-11-16 06:27:03 +00:00
|
|
|
#include "oplsynth/opl.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
static bool OPL_Active;
|
|
|
|
|
2012-11-06 06:10:04 +00:00
|
|
|
CUSTOM_CVAR (Int, opl_numchips, 2, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2012-11-06 06:10:04 +00:00
|
|
|
if (*self <= 0)
|
|
|
|
{
|
|
|
|
self = 1;
|
|
|
|
}
|
|
|
|
else if (*self > MAXOPL2CHIPS)
|
|
|
|
{
|
|
|
|
self = MAXOPL2CHIPS;
|
|
|
|
}
|
|
|
|
else if (OPL_Active && currSong != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
static_cast<OPLMUSSong *>(currSong)->ResetChips ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 05:45:58 +00:00
|
|
|
CVAR(Int, opl_core, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
|
|
|
|
|
2014-06-25 11:25:36 +00:00
|
|
|
OPLMUSSong::OPLMUSSong (std::auto_ptr<FileReader> reader)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-03-28 03:19:18 +00:00
|
|
|
int samples = int(OPL_SAMPLE_RATE / 14);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-06-25 11:25:36 +00:00
|
|
|
Music = new OPLmusicFile (reader.get());
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-03-29 01:30:37 +00:00
|
|
|
m_Stream = GSnd->CreateStream (FillStream, samples*4,
|
2012-11-15 05:23:24 +00:00
|
|
|
(opl_core == 0 ? SoundStream::Mono : 0) | SoundStream::Float, int(OPL_SAMPLE_RATE), this);
|
2006-02-24 04:48:15 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-08-03 03:54:48 +00:00
|
|
|
void OPLMUSSong::Play (bool looping, int subsong)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
m_Status = STATE_Stopped;
|
|
|
|
m_Looping = looping;
|
|
|
|
|
|
|
|
Music->SetLooping (looping);
|
|
|
|
Music->Restart ();
|
|
|
|
|
2008-04-13 03:23:33 +00:00
|
|
|
if (m_Stream == NULL || m_Stream->Play (true, snd_musicvolume))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2008-04-03 02:31:39 +00:00
|
|
|
|
|
|
|
MusInfo *OPLMUSSong::GetOPLDumper(const char *filename)
|
|
|
|
{
|
|
|
|
return new OPLMUSDumper(this, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
OPLMUSSong::OPLMUSSong(const OPLMUSSong *original, const char *filename)
|
|
|
|
{
|
|
|
|
Music = new OPLmusicFile(original->Music, filename);
|
|
|
|
m_Stream = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
OPLMUSDumper::OPLMUSDumper(const OPLMUSSong *original, const char *filename)
|
|
|
|
: OPLMUSSong(original, filename)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-06 00:50:09 +00:00
|
|
|
void OPLMUSDumper::Play(bool looping, int)
|
2008-04-03 02:31:39 +00:00
|
|
|
{
|
|
|
|
Music->Dump();
|
|
|
|
}
|