mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 23:02:08 +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
|
||||
|
||||
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
||||
void OPL_SetCore(const char *args);
|
||||
|
||||
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
||||
|
||||
|
@ -75,11 +74,18 @@ CVAR(Bool, opl_fullpan, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
|
|||
// 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)
|
||||
: SoftSynthMIDIDevice((int)OPL_SAMPLE_RATE)
|
||||
: SoftSynthMIDIDevice((int)OPL_SAMPLE_RATE), OPLmusicBlock(getOPLCore(args))
|
||||
{
|
||||
OPL_SetCore(args);
|
||||
FullPan = opl_fullpan;
|
||||
auto lump = Wads.CheckNumForName("GENMIDI", ns_global);
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -297,23 +297,14 @@ public:
|
|||
bool IsPlaying ();
|
||||
bool IsValid () const;
|
||||
void ResetChips ();
|
||||
MusInfo *GetOPLDumper(const char *filename);
|
||||
|
||||
protected:
|
||||
OPLMUSSong(const OPLMUSSong *original, const char *filename); // OPL dump constructor
|
||||
|
||||
static bool FillStream (SoundStream *stream, void *buff, int len, void *userdata);
|
||||
|
||||
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 -----------------------
|
||||
|
||||
class CDSong : public MusInfo
|
||||
|
|
|
@ -59,24 +59,18 @@ CUSTOM_CVAR(Int, opl_core, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|||
MIDIDeviceChanged(-1, true);
|
||||
}
|
||||
}
|
||||
int current_opl_core;
|
||||
|
||||
// Get OPL core override from $mididevice
|
||||
void OPL_SetCore(const char *args)
|
||||
{
|
||||
current_opl_core = opl_core;
|
||||
if (args != NULL && *args >= '0' && *args < '4') current_opl_core = *args - '0';
|
||||
}
|
||||
int getOPLCore(const char* args);
|
||||
|
||||
OPLMUSSong::OPLMUSSong (FileReader &reader, const char *args)
|
||||
{
|
||||
int samples = int(OPL_SAMPLE_RATE / 14);
|
||||
|
||||
OPL_SetCore(args);
|
||||
Music = new OPLmusicFile (reader);
|
||||
int core = getOPLCore(args);
|
||||
Music = new OPLmusicFile (reader, core);
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
OPLmusicBlock::OPLmusicBlock()
|
||||
OPLmusicBlock::OPLmusicBlock(int core)
|
||||
{
|
||||
currentCore = core;
|
||||
scoredata = NULL;
|
||||
NextTickIn = 0;
|
||||
LastOffset = 0;
|
||||
|
@ -69,7 +70,7 @@ void OPLmusicBlock::ResetChips ()
|
|||
{
|
||||
std::lock_guard<std::mutex> lock(ChipAccess);
|
||||
io->Reset ();
|
||||
NumChips = io->Init(MIN(*opl_numchips, 2), FullPan);
|
||||
NumChips = io->Init(currentCore, MIN(*opl_numchips, 2), FullPan, false);
|
||||
}
|
||||
|
||||
void OPLmusicBlock::Restart()
|
||||
|
@ -80,8 +81,8 @@ void OPLmusicBlock::Restart()
|
|||
LastOffset = 0;
|
||||
}
|
||||
|
||||
OPLmusicFile::OPLmusicFile (FileReader &reader)
|
||||
: ScoreLen ((int)reader.GetLength())
|
||||
OPLmusicFile::OPLmusicFile (FileReader &reader, int core)
|
||||
: OPLmusicBlock(core), ScoreLen ((int)reader.GetLength())
|
||||
{
|
||||
if (io == NULL)
|
||||
{
|
||||
|
@ -97,7 +98,7 @@ fail: delete[] scoredata;
|
|||
return;
|
||||
}
|
||||
|
||||
if (0 == (NumChips = io->Init(NumChips)))
|
||||
if (0 == (NumChips = io->Init(core, NumChips, false, false)))
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
@ -528,14 +529,8 @@ int OPLmusicFile::PlayTick ()
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
ADD_STAT (opl)
|
||||
{
|
||||
return YM3812GetVoiceString ();
|
||||
}
|
||||
*/
|
||||
|
||||
OPLmusicFile::OPLmusicFile(const OPLmusicFile *source, const char *filename)
|
||||
OPLmusicFile::OPLmusicFile(int core, const OPLmusicFile *source, const char *filename)
|
||||
: OPLmusicBlock(core)
|
||||
{
|
||||
ScoreLen = source->ScoreLen;
|
||||
scoredata = new uint8_t[ScoreLen];
|
||||
|
@ -550,7 +545,7 @@ OPLmusicFile::OPLmusicFile(const OPLmusicFile *source, const char *filename)
|
|||
delete io;
|
||||
}
|
||||
io = new DiskWriterIO(filename);
|
||||
NumChips = io->Init(NumChips);
|
||||
NumChips = io->Init(core, NumChips, false, false);
|
||||
Restart();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class FileReader;
|
|||
class OPLmusicBlock : public musicBlock
|
||||
{
|
||||
public:
|
||||
OPLmusicBlock();
|
||||
OPLmusicBlock(int core);
|
||||
virtual ~OPLmusicBlock();
|
||||
|
||||
bool ServiceStream(void *buff, int numbytes);
|
||||
|
@ -20,12 +20,13 @@ protected:
|
|||
|
||||
uint8_t *score;
|
||||
uint8_t *scoredata;
|
||||
int playingcount;
|
||||
double NextTickIn;
|
||||
double SamplesPerTick;
|
||||
int NumChips;
|
||||
bool Looping;
|
||||
double LastOffset;
|
||||
int playingcount;
|
||||
int NumChips;
|
||||
int currentCore;
|
||||
bool Looping;
|
||||
bool FullPan;
|
||||
|
||||
std::mutex ChipAccess;
|
||||
|
@ -34,8 +35,8 @@ protected:
|
|||
class OPLmusicFile : public OPLmusicBlock
|
||||
{
|
||||
public:
|
||||
OPLmusicFile(FileReader &reader);
|
||||
OPLmusicFile(const OPLmusicFile *source, const char *filename);
|
||||
OPLmusicFile(FileReader &reader, int core);
|
||||
OPLmusicFile(int core, const OPLmusicFile *source, const char *filename);
|
||||
virtual ~OPLmusicFile();
|
||||
|
||||
bool IsValid() const;
|
||||
|
@ -44,7 +45,7 @@ public:
|
|||
void Dump();
|
||||
|
||||
protected:
|
||||
OPLmusicFile() {}
|
||||
OPLmusicFile(int core) : OPLmusicBlock(core) {}
|
||||
int PlayTick();
|
||||
|
||||
enum { RDosPlay, IMF, DosBox1, DosBox2 } RawPlayer;
|
||||
|
|
|
@ -32,9 +32,6 @@
|
|||
|
||||
const double HALF_PI = (M_PI*0.5);
|
||||
|
||||
EXTERN_CVAR(Int, opl_core)
|
||||
extern int current_opl_core;
|
||||
|
||||
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));
|
||||
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));
|
||||
if (IsOPL3)
|
||||
|
@ -66,7 +63,7 @@ int OPLio::Init(uint32_t numchips, bool stereo, bool initopl3)
|
|||
}
|
||||
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)
|
||||
{
|
||||
break;
|
||||
|
|
|
@ -72,7 +72,7 @@ struct OPLio
|
|||
void MuteChannel(uint32_t chan);
|
||||
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 WriteRegister(int which, uint32_t reg, uint8_t data);
|
||||
virtual void SetClockRate(double samples_per_tick);
|
||||
|
|
Loading…
Reference in a new issue