diff --git a/libraries/zmusic/mididevices/mididevice.h b/libraries/zmusic/mididevices/mididevice.h index 5074c84276..98789a8740 100644 --- a/libraries/zmusic/mididevices/mididevice.h +++ b/libraries/zmusic/mididevices/mididevice.h @@ -149,7 +149,7 @@ protected: MIDIDevice *CreateFluidSynthMIDIDevice(int samplerate, const FluidConfig* config, int (*printfunc)(const char*, ...)); MIDIDevice *CreateADLMIDIDevice(const ADLConfig* config); MIDIDevice *CreateOPNMIDIDevice(const OpnConfig *args); -MIDIDevice *CreateOplMIDIDevice(const OPLMidiConfig* config); +MIDIDevice *CreateOplMIDIDevice(const OPLConfig* config); MIDIDevice *CreateTimidityMIDIDevice(GUSConfig *config, int samplerate); MIDIDevice *CreateTimidityPPMIDIDevice(TimidityConfig *config, int samplerate); MIDIDevice *CreateWildMIDIDevice(WildMidiConfig *config, int samplerate); diff --git a/libraries/zmusic/mididevices/music_opl_mididevice.cpp b/libraries/zmusic/mididevices/music_opl_mididevice.cpp index fa78434abe..0f5e3adb3c 100644 --- a/libraries/zmusic/mididevices/music_opl_mididevice.cpp +++ b/libraries/zmusic/mididevices/music_opl_mididevice.cpp @@ -57,7 +57,7 @@ class OPLMIDIDevice : public SoftSynthMIDIDevice, protected OPLmusicBlock { public: - OPLMIDIDevice(const OPLMidiConfig *config); + OPLMIDIDevice(const OPLConfig *config); int OpenRenderer(); void Close(); int GetTechnology() const; @@ -84,7 +84,7 @@ protected: // //========================================================================== -OPLMIDIDevice::OPLMIDIDevice(const OPLMidiConfig *config) +OPLMIDIDevice::OPLMIDIDevice(const OPLConfig *config) : SoftSynthMIDIDevice((int)OPL_SAMPLE_RATE), OPLmusicBlock(config->core, config->numchips) { FullPan = config->fullpan; @@ -314,7 +314,7 @@ std::string OPLMIDIDevice::GetStats() return out; } -MIDIDevice* CreateOplMIDIDevice(const OPLMidiConfig* config) +MIDIDevice* CreateOplMIDIDevice(const OPLConfig* config) { return new OPLMIDIDevice(config); } diff --git a/libraries/zmusic/zmusic/midiconfig.h b/libraries/zmusic/zmusic/midiconfig.h index edb3d125fe..edf4978b74 100644 --- a/libraries/zmusic/zmusic/midiconfig.h +++ b/libraries/zmusic/zmusic/midiconfig.h @@ -38,11 +38,12 @@ struct FluidConfig float fluid_chorus_depth = 8; }; -struct OPLMidiConfig +struct OPLConfig { int numchips = 2; int core = 0; bool fullpan = true; + bool genmidiset = false; uint8_t OPLinstruments[36 * 175]; // it really is 'struct GenMidiInstrument OPLinstruments[GENMIDI_NUM_TOTAL]'; but since this is a public header it cannot pull in a dependency from oplsynth. }; diff --git a/src/sound/backend/i_soundinternal.h b/src/sound/backend/i_soundinternal.h index fe043f12db..cb0351f3f2 100644 --- a/src/sound/backend/i_soundinternal.h +++ b/src/sound/backend/i_soundinternal.h @@ -147,10 +147,9 @@ protected: virtual bool open(FileReader &reader) = 0; friend class SoundRenderer; -private: // Make non-copyable - SoundDecoder(const SoundDecoder &rhs); - SoundDecoder& operator=(const SoundDecoder &rhs); + SoundDecoder(const SoundDecoder &rhs) = delete; + SoundDecoder& operator=(const SoundDecoder &rhs) = delete; }; class MusInfo; diff --git a/src/sound/music/i_music.cpp b/src/sound/music/i_music.cpp index 647db34054..631085aec3 100644 --- a/src/sound/music/i_music.cpp +++ b/src/sound/music/i_music.cpp @@ -457,7 +457,11 @@ MusInfo *I_RegisterSong (FileReader &reader, MidiDeviceSetting *device) (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') && *((uint8_t *)id + 4) == 'B')) // Martin Fernandez's modified IMF { - streamsource = OPL_OpenSong(reader, device != nullptr? device->args.GetChars() : ""); + OPL_SetupConfig(&oplConfig, device->args.GetChars(), false); + auto mreader = new FileReaderMusicInterface(reader); + streamsource = OPL_OpenSong(mreader, &oplConfig); + reader = mreader->GetReader(); // We need to get this back for the rest of this function. + delete mreader; } else if ((id[0] == MAKE_ID('R', 'I', 'F', 'F') && id[2] == MAKE_ID('C', 'D', 'X', 'A'))) { diff --git a/src/sound/music/i_musicinterns.h b/src/sound/music/i_musicinterns.h index 67c175cf85..a200aeee0f 100644 --- a/src/sound/music/i_musicinterns.h +++ b/src/sound/music/i_musicinterns.h @@ -21,7 +21,7 @@ class OPLmusicFile; extern ADLConfig adlConfig; extern FluidConfig fluidConfig; -extern OPLMidiConfig oplMidiConfig; +extern OPLConfig oplConfig; extern OpnConfig opnConfig; extern GUSConfig gusConfig; extern TimidityConfig timidityConfig; @@ -141,7 +141,7 @@ public: void Fluid_SetupConfig(FluidConfig *config, const char* patches, bool systemfallback); void ADL_SetupConfig(ADLConfig *config, const char *Args); -void OPL_SetupConfig(OPLMidiConfig *config, const char *args); +void OPL_SetupConfig(OPLConfig *config, const char *args, bool midi = true); void OPN_SetupConfig(OpnConfig *config, const char *Args); bool GUS_SetupConfig(GUSConfig *config, const char *args); bool Timidity_SetupConfig(TimidityConfig* config, const char* args); @@ -156,7 +156,7 @@ StreamSource *MOD_OpenSong(MusicIO::FileInterface* reader, DumbConfig* config, i StreamSource* GME_OpenSong(MusicIO::FileInterface* reader, const char* fmt, float stereo_depth, int sample_rate); StreamSource *SndFile_OpenSong(FileReader &fr); StreamSource* XA_OpenSong(FileReader& reader); -StreamSource *OPL_OpenSong(FileReader &reader, const char *args); +StreamSource* OPL_OpenSong(MusicIO::FileInterface* reader, OPLConfig *config); // stream song ------------------------------------------ diff --git a/src/sound/music/midi_cvars.cpp b/src/sound/music/midi_cvars.cpp index 8aafe9fee1..c9fd297791 100644 --- a/src/sound/music/midi_cvars.cpp +++ b/src/sound/music/midi_cvars.cpp @@ -60,7 +60,7 @@ static void CheckRestart(int devtype) ADLConfig adlConfig; FluidConfig fluidConfig; -OPLMidiConfig oplMidiConfig; +OPLConfig oplConfig; OpnConfig opnConfig; GUSConfig gusConfig; TimidityConfig timidityConfig; @@ -477,7 +477,7 @@ CUSTOM_CVAR(Int, opl_numchips, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) { if (currSong != NULL) currSong->ChangeSettingInt("opl.numchips", self); - oplMidiConfig.numchips = self; + oplConfig.numchips = self; } } @@ -488,21 +488,26 @@ CUSTOM_CVAR(Int, opl_core, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CUSTOM_CVAR(Bool, opl_fullpan, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) { - oplMidiConfig.fullpan = self; + oplConfig.fullpan = self; } -void OPL_SetupConfig(OPLMidiConfig *config, const char *args) +void OPL_SetupConfig(OPLConfig *config, const char *args, bool midi) { - // The OPL renderer should not care about where this comes from. - // Note: No I_Error here - this needs to be consistent with the rest of the music code. - auto lump = Wads.CheckNumForName("GENMIDI", ns_global); - if (lump < 0) throw std::runtime_error("No GENMIDI lump found"); - auto data = Wads.OpenLumpReader(lump); + // This needs to be done only once. + if (!config->genmidiset && midi) + { + // The OPL renderer should not care about where this comes from. + // Note: No I_Error here - this needs to be consistent with the rest of the music code. + auto lump = Wads.CheckNumForName("GENMIDI", ns_global); + if (lump < 0) throw std::runtime_error("No GENMIDI lump found"); + auto data = Wads.OpenLumpReader(lump); - uint8_t filehdr[8]; - data.Read(filehdr, 8); - if (memcmp(filehdr, "#OPL_II#", 8)) throw std::runtime_error("Corrupt GENMIDI lump"); - data.Read(oplMidiConfig.OPLinstruments, 175 * 36); + uint8_t filehdr[8]; + data.Read(filehdr, 8); + if (memcmp(filehdr, "#OPL_II#", 8)) throw std::runtime_error("Corrupt GENMIDI lump"); + data.Read(oplConfig.OPLinstruments, 175 * 36); + config->genmidiset = true; + } config->core = opl_core; if (args != NULL && *args >= '0' && *args < '4') config->core = *args - '0'; diff --git a/src/sound/musicformats/music_dumb.cpp b/src/sound/musicformats/music_dumb.cpp index 4161ebf1d2..c7ce8a7169 100644 --- a/src/sound/musicformats/music_dumb.cpp +++ b/src/sound/musicformats/music_dumb.cpp @@ -48,7 +48,7 @@ #include "m_swap.h" #include "zmusic/mididefs.h" #include "zmusic/midiconfig.h" -#include "../..//libraries/music_common/fileio.h" +#include "../../libraries/music_common/fileio.h" // MACROS ------------------------------------------------------------------ diff --git a/src/sound/musicformats/music_midistream.cpp b/src/sound/musicformats/music_midistream.cpp index 7a8f5b1e4e..9b7fd810fd 100644 --- a/src/sound/musicformats/music_midistream.cpp +++ b/src/sound/musicformats/music_midistream.cpp @@ -221,8 +221,8 @@ MIDIDevice *MIDIStreamer::CreateMIDIDevice(EMidiDevice devtype, int samplerate) break; case MDEV_OPL: - OPL_SetupConfig(&oplMidiConfig, Args); - dev = CreateOplMIDIDevice(&oplMidiConfig); + OPL_SetupConfig(&oplConfig, Args); + dev = CreateOplMIDIDevice(&oplConfig); break; case MDEV_TIMIDITY: diff --git a/src/sound/musicformats/music_opl.cpp b/src/sound/musicformats/music_opl.cpp index 35aa878fa4..4bf7cd07a8 100644 --- a/src/sound/musicformats/music_opl.cpp +++ b/src/sound/musicformats/music_opl.cpp @@ -31,13 +31,11 @@ **--------------------------------------------------------------------------- */ -#include "i_musicinterns.h" #include "streamsource.h" #include "../libraries/oplsynth/oplsynth/opl.h" #include "../libraries/oplsynth/oplsynth/opl_mus_player.h" - -EXTERN_CVAR (Int, opl_numchips) -EXTERN_CVAR(Int, opl_core) +#include "../libraries/music_common/fileio.h" +#include "zmusic/midiconfig.h" //========================================================================== @@ -49,7 +47,7 @@ EXTERN_CVAR(Int, opl_core) class OPLMUSSong : public StreamSource { public: - OPLMUSSong (FileReader &reader, const char *args); + OPLMUSSong (MusicIO::FileInterface *reader, OPLConfig *config); ~OPLMUSSong (); bool Start() override; void ChangeSettingInt(const char *name, int value) override; @@ -69,12 +67,20 @@ protected: // //========================================================================== -OPLMUSSong::OPLMUSSong (FileReader &reader, const char *args) +OPLMUSSong::OPLMUSSong(MusicIO::FileInterface* reader, OPLConfig* config) { - current_opl_core = opl_core; - if (args != NULL && *args >= '0' && *args < '4') current_opl_core = *args - '0'; - - Music = nullptr ;// new OPLmusicFile(reader, current_opl_core); + const char* error = nullptr; + reader->seek(0, SEEK_END); + auto fs = reader->tell(); + reader->seek(0, SEEK_SET); + std::vector data(fs); + reader->read(data.data(), (int)data.size()); + Music = new OPLmusicFile(data.data(), data.size(), config->core, config->numchips, error); + if (error) + { + delete Music; + throw std::runtime_error(error); + } } //========================================================================== @@ -139,7 +145,7 @@ bool OPLMUSSong::GetData(void *buffer, size_t len) return Music->ServiceStream(buffer, int(len)) ? len : 0; } -StreamSource *OPL_OpenSong(FileReader &reader, const char *args) +StreamSource *OPL_OpenSong(MusicIO::FileInterface* reader, OPLConfig *config) { - return new OPLMUSSong(reader, args); + return new OPLMUSSong(reader, config); }