mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-13 07:57:52 +00:00
- removed the global current_opl_core variable and pass the needed info as function parameters
because using global variables for this is really bad style! This also removes the unused OPLMUSDumper class.
This commit is contained in:
parent
159b98ea88
commit
2aa03e8e8a
7 changed files with 35 additions and 71 deletions
|
@ -52,7 +52,6 @@ void I_DebugPrint(const char *cp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
||||||
void OPL_SetCore(const char *args);
|
|
||||||
|
|
||||||
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
||||||
|
|
||||||
|
@ -75,11 +74,18 @@ CVAR(Bool, opl_fullpan, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
|
||||||
// OPLMIDIDevice Contructor
|
// OPLMIDIDevice Contructor
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
EXTERN_CVAR(Int, opl_core)
|
||||||
|
int getOPLCore(const char* args)
|
||||||
|
{
|
||||||
|
int current_opl_core = opl_core;
|
||||||
|
if (args != NULL && *args >= '0' && *args < '4') current_opl_core = *args - '0';
|
||||||
|
return current_opl_core;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
OPLMIDIDevice::OPLMIDIDevice(const char *args)
|
OPLMIDIDevice::OPLMIDIDevice(const char *args)
|
||||||
: SoftSynthMIDIDevice((int)OPL_SAMPLE_RATE)
|
: SoftSynthMIDIDevice((int)OPL_SAMPLE_RATE), OPLmusicBlock(getOPLCore(args))
|
||||||
{
|
{
|
||||||
OPL_SetCore(args);
|
|
||||||
FullPan = opl_fullpan;
|
FullPan = opl_fullpan;
|
||||||
auto lump = Wads.CheckNumForName("GENMIDI", ns_global);
|
auto lump = Wads.CheckNumForName("GENMIDI", ns_global);
|
||||||
if (lump < 0) I_Error("No GENMIDI lump found");
|
if (lump < 0) I_Error("No GENMIDI lump found");
|
||||||
|
@ -101,7 +107,7 @@ OPLMIDIDevice::OPLMIDIDevice(const char *args)
|
||||||
|
|
||||||
int OPLMIDIDevice::Open(MidiCallback callback, void *userdata)
|
int OPLMIDIDevice::Open(MidiCallback callback, void *userdata)
|
||||||
{
|
{
|
||||||
if (io == NULL || 0 == (NumChips = io->Init(opl_numchips, FullPan, true)))
|
if (io == NULL || 0 == (NumChips = io->Init(currentCore, opl_numchips, FullPan, true)))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,23 +297,14 @@ public:
|
||||||
bool IsPlaying ();
|
bool IsPlaying ();
|
||||||
bool IsValid () const;
|
bool IsValid () const;
|
||||||
void ResetChips ();
|
void ResetChips ();
|
||||||
MusInfo *GetOPLDumper(const char *filename);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
OPLMUSSong(const OPLMUSSong *original, const char *filename); // OPL dump constructor
|
|
||||||
|
|
||||||
static bool FillStream (SoundStream *stream, void *buff, int len, void *userdata);
|
static bool FillStream (SoundStream *stream, void *buff, int len, void *userdata);
|
||||||
|
|
||||||
OPLmusicFile *Music;
|
OPLmusicFile *Music;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OPLMUSDumper : public OPLMUSSong
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
OPLMUSDumper(const OPLMUSSong *original, const char *filename);
|
|
||||||
void Play(bool looping, int);
|
|
||||||
};
|
|
||||||
|
|
||||||
// CD track/disk played through the multimedia system -----------------------
|
// CD track/disk played through the multimedia system -----------------------
|
||||||
|
|
||||||
class CDSong : public MusInfo
|
class CDSong : public MusInfo
|
||||||
|
|
|
@ -59,24 +59,18 @@ CUSTOM_CVAR(Int, opl_core, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||||
MIDIDeviceChanged(-1, true);
|
MIDIDeviceChanged(-1, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int current_opl_core;
|
|
||||||
|
|
||||||
// Get OPL core override from $mididevice
|
int getOPLCore(const char* args);
|
||||||
void OPL_SetCore(const char *args)
|
|
||||||
{
|
|
||||||
current_opl_core = opl_core;
|
|
||||||
if (args != NULL && *args >= '0' && *args < '4') current_opl_core = *args - '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
OPLMUSSong::OPLMUSSong (FileReader &reader, const char *args)
|
OPLMUSSong::OPLMUSSong (FileReader &reader, const char *args)
|
||||||
{
|
{
|
||||||
int samples = int(OPL_SAMPLE_RATE / 14);
|
int samples = int(OPL_SAMPLE_RATE / 14);
|
||||||
|
|
||||||
OPL_SetCore(args);
|
int core = getOPLCore(args);
|
||||||
Music = new OPLmusicFile (reader);
|
Music = new OPLmusicFile (reader, core);
|
||||||
|
|
||||||
m_Stream = GSnd->CreateStream (FillStream, samples*4,
|
m_Stream = GSnd->CreateStream (FillStream, samples*4,
|
||||||
(current_opl_core == 0 ? SoundStream::Mono : 0) | SoundStream::Float, int(OPL_SAMPLE_RATE), this);
|
(core == 0 ? SoundStream::Mono : 0) | SoundStream::Float, int(OPL_SAMPLE_RATE), this);
|
||||||
if (m_Stream == NULL)
|
if (m_Stream == NULL)
|
||||||
{
|
{
|
||||||
Printf (PRINT_BOLD, "Could not create music stream.\n");
|
Printf (PRINT_BOLD, "Could not create music stream.\n");
|
||||||
|
@ -131,23 +125,3 @@ bool OPLMUSSong::FillStream (SoundStream *stream, void *buff, int len, void *use
|
||||||
return song->Music->ServiceStream (buff, len);
|
return song->Music->ServiceStream (buff, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void OPLMUSDumper::Play(bool looping, int)
|
|
||||||
{
|
|
||||||
Music->Dump();
|
|
||||||
}
|
|
||||||
|
|
|
@ -48,8 +48,9 @@
|
||||||
|
|
||||||
EXTERN_CVAR (Int, opl_numchips)
|
EXTERN_CVAR (Int, opl_numchips)
|
||||||
|
|
||||||
OPLmusicBlock::OPLmusicBlock()
|
OPLmusicBlock::OPLmusicBlock(int core)
|
||||||
{
|
{
|
||||||
|
currentCore = core;
|
||||||
scoredata = NULL;
|
scoredata = NULL;
|
||||||
NextTickIn = 0;
|
NextTickIn = 0;
|
||||||
LastOffset = 0;
|
LastOffset = 0;
|
||||||
|
@ -69,7 +70,7 @@ void OPLmusicBlock::ResetChips ()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(ChipAccess);
|
std::lock_guard<std::mutex> lock(ChipAccess);
|
||||||
io->Reset ();
|
io->Reset ();
|
||||||
NumChips = io->Init(MIN(*opl_numchips, 2), FullPan);
|
NumChips = io->Init(currentCore, MIN(*opl_numchips, 2), FullPan, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OPLmusicBlock::Restart()
|
void OPLmusicBlock::Restart()
|
||||||
|
@ -80,8 +81,8 @@ void OPLmusicBlock::Restart()
|
||||||
LastOffset = 0;
|
LastOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
OPLmusicFile::OPLmusicFile (FileReader &reader)
|
OPLmusicFile::OPLmusicFile (FileReader &reader, int core)
|
||||||
: ScoreLen ((int)reader.GetLength())
|
: OPLmusicBlock(core), ScoreLen ((int)reader.GetLength())
|
||||||
{
|
{
|
||||||
if (io == NULL)
|
if (io == NULL)
|
||||||
{
|
{
|
||||||
|
@ -97,7 +98,7 @@ fail: delete[] scoredata;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == (NumChips = io->Init(NumChips)))
|
if (0 == (NumChips = io->Init(core, NumChips, false, false)))
|
||||||
{
|
{
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -528,14 +529,8 @@ int OPLmusicFile::PlayTick ()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
OPLmusicFile::OPLmusicFile(int core, const OPLmusicFile *source, const char *filename)
|
||||||
ADD_STAT (opl)
|
: OPLmusicBlock(core)
|
||||||
{
|
|
||||||
return YM3812GetVoiceString ();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
OPLmusicFile::OPLmusicFile(const OPLmusicFile *source, const char *filename)
|
|
||||||
{
|
{
|
||||||
ScoreLen = source->ScoreLen;
|
ScoreLen = source->ScoreLen;
|
||||||
scoredata = new uint8_t[ScoreLen];
|
scoredata = new uint8_t[ScoreLen];
|
||||||
|
@ -550,7 +545,7 @@ OPLmusicFile::OPLmusicFile(const OPLmusicFile *source, const char *filename)
|
||||||
delete io;
|
delete io;
|
||||||
}
|
}
|
||||||
io = new DiskWriterIO(filename);
|
io = new DiskWriterIO(filename);
|
||||||
NumChips = io->Init(NumChips);
|
NumChips = io->Init(core, NumChips, false, false);
|
||||||
Restart();
|
Restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ class FileReader;
|
||||||
class OPLmusicBlock : public musicBlock
|
class OPLmusicBlock : public musicBlock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OPLmusicBlock();
|
OPLmusicBlock(int core);
|
||||||
virtual ~OPLmusicBlock();
|
virtual ~OPLmusicBlock();
|
||||||
|
|
||||||
bool ServiceStream(void *buff, int numbytes);
|
bool ServiceStream(void *buff, int numbytes);
|
||||||
|
@ -20,12 +20,13 @@ protected:
|
||||||
|
|
||||||
uint8_t *score;
|
uint8_t *score;
|
||||||
uint8_t *scoredata;
|
uint8_t *scoredata;
|
||||||
int playingcount;
|
|
||||||
double NextTickIn;
|
double NextTickIn;
|
||||||
double SamplesPerTick;
|
double SamplesPerTick;
|
||||||
int NumChips;
|
|
||||||
bool Looping;
|
|
||||||
double LastOffset;
|
double LastOffset;
|
||||||
|
int playingcount;
|
||||||
|
int NumChips;
|
||||||
|
int currentCore;
|
||||||
|
bool Looping;
|
||||||
bool FullPan;
|
bool FullPan;
|
||||||
|
|
||||||
std::mutex ChipAccess;
|
std::mutex ChipAccess;
|
||||||
|
@ -34,8 +35,8 @@ protected:
|
||||||
class OPLmusicFile : public OPLmusicBlock
|
class OPLmusicFile : public OPLmusicBlock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OPLmusicFile(FileReader &reader);
|
OPLmusicFile(FileReader &reader, int core);
|
||||||
OPLmusicFile(const OPLmusicFile *source, const char *filename);
|
OPLmusicFile(int core, const OPLmusicFile *source, const char *filename);
|
||||||
virtual ~OPLmusicFile();
|
virtual ~OPLmusicFile();
|
||||||
|
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
@ -44,7 +45,7 @@ public:
|
||||||
void Dump();
|
void Dump();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
OPLmusicFile() {}
|
OPLmusicFile(int core) : OPLmusicBlock(core) {}
|
||||||
int PlayTick();
|
int PlayTick();
|
||||||
|
|
||||||
enum { RDosPlay, IMF, DosBox1, DosBox2 } RawPlayer;
|
enum { RDosPlay, IMF, DosBox1, DosBox2 } RawPlayer;
|
||||||
|
|
|
@ -32,9 +32,6 @@
|
||||||
|
|
||||||
const double HALF_PI = (M_PI*0.5);
|
const double HALF_PI = (M_PI*0.5);
|
||||||
|
|
||||||
EXTERN_CVAR(Int, opl_core)
|
|
||||||
extern int current_opl_core;
|
|
||||||
|
|
||||||
OPLio::~OPLio()
|
OPLio::~OPLio()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -53,11 +50,11 @@ void OPLio::WriteDelay(int ticks)
|
||||||
//
|
//
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
int OPLio::Init(uint32_t numchips, bool stereo, bool initopl3)
|
int OPLio::Init(int core, uint32_t numchips, bool stereo, bool initopl3)
|
||||||
{
|
{
|
||||||
assert(numchips >= 1 && numchips <= countof(chips));
|
assert(numchips >= 1 && numchips <= countof(chips));
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
IsOPL3 = (current_opl_core == 1 || current_opl_core == 2 || current_opl_core == 3);
|
IsOPL3 = (core == 1 || core == 2 || core == 3);
|
||||||
|
|
||||||
memset(chips, 0, sizeof(chips));
|
memset(chips, 0, sizeof(chips));
|
||||||
if (IsOPL3)
|
if (IsOPL3)
|
||||||
|
@ -66,7 +63,7 @@ int OPLio::Init(uint32_t numchips, bool stereo, bool initopl3)
|
||||||
}
|
}
|
||||||
for (i = 0; i < numchips; ++i)
|
for (i = 0; i < numchips; ++i)
|
||||||
{
|
{
|
||||||
OPLEmul *chip = IsOPL3 ? (current_opl_core == 1 ? DBOPLCreate(stereo) : (current_opl_core == 2 ? JavaOPLCreate(stereo) : NukedOPL3Create(stereo))) : YM3812Create(stereo);
|
OPLEmul *chip = IsOPL3 ? (core == 1 ? DBOPLCreate(stereo) : (core == 2 ? JavaOPLCreate(stereo) : NukedOPL3Create(stereo))) : YM3812Create(stereo);
|
||||||
if (chip == NULL)
|
if (chip == NULL)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -72,7 +72,7 @@ struct OPLio
|
||||||
void MuteChannel(uint32_t chan);
|
void MuteChannel(uint32_t chan);
|
||||||
void StopPlayback();
|
void StopPlayback();
|
||||||
|
|
||||||
virtual int Init(uint32_t numchips, bool stereo = false, bool initopl3 = false);
|
virtual int Init(int core, uint32_t numchips, bool stereo, bool initopl3);
|
||||||
virtual void Reset();
|
virtual void Reset();
|
||||||
virtual void WriteRegister(int which, uint32_t reg, uint8_t data);
|
virtual void WriteRegister(int which, uint32_t reg, uint8_t data);
|
||||||
virtual void SetClockRate(double samples_per_tick);
|
virtual void SetClockRate(double samples_per_tick);
|
||||||
|
|
Loading…
Reference in a new issue