diff options
author | Martin Kiewitz | 2015-07-04 21:33:41 +0200 |
---|---|---|
committer | Martin Kiewitz | 2015-07-04 21:33:41 +0200 |
commit | 8e470918298bf09a7c18602b6d4a9b22c2753160 (patch) | |
tree | d5c06c3d8ac4895203eff8113c02651b3f3f8f3b /audio | |
parent | 72af7a03d722c3f8c4bd32db0e0197d1129f9db6 (diff) | |
download | scummvm-rg350-8e470918298bf09a7c18602b6d4a9b22c2753160.tar.gz scummvm-rg350-8e470918298bf09a7c18602b6d4a9b22c2753160.tar.bz2 scummvm-rg350-8e470918298bf09a7c18602b6d4a9b22c2753160.zip |
AUDIO: Miles Audio AdLib: read AdLib+OPL3 file
Checks if at least one of those exists and reads the one that does
Needed for another version of Simon The Sorcerer 2, that only
features FAT.OPL
Diffstat (limited to 'audio')
-rw-r--r-- | audio/miles.h | 2 | ||||
-rw-r--r-- | audio/miles_adlib.cpp | 47 |
2 files changed, 41 insertions, 8 deletions
diff --git a/audio/miles.h b/audio/miles.h index 584460952e..fc19cc35eb 100644 --- a/audio/miles.h +++ b/audio/miles.h @@ -72,7 +72,7 @@ namespace Audio { // Miles Audio actually used 0x4000, because they didn't shift the 2 bytes properly #define MILES_PITCHBENDER_DEFAULT 0x2000 -extern MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &instrumentDataFilename, const Common::String &instrumentDataFilenameOPL3, Common::SeekableReadStream *instrumentStream = nullptr); +extern MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &filenameAdLib, const Common::String &filenameOPL3, Common::SeekableReadStream *instrumentStream = nullptr); extern MidiDriver *MidiDriver_Miles_MT32_create(const Common::String &instrumentDataFilename); diff --git a/audio/miles_adlib.cpp b/audio/miles_adlib.cpp index c85348cdd5..6731c5f7a4 100644 --- a/audio/miles_adlib.cpp +++ b/audio/miles_adlib.cpp @@ -1060,9 +1060,10 @@ uint32 MidiDriver_Miles_AdLib::property(int prop, uint32 param) { return 0; } -MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &instrumentDataFilename, const Common::String &instrumentDataFilenameOPL3, Common::SeekableReadStream *instrumentStream) { +MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &filenameAdLib, const Common::String &filenameOPL3, Common::SeekableReadStream *instrumentStream) { // Load adlib instrument data from file SAMPLE.AD (OPL3: SAMPLE.OPL) - Common::File *fileStream = NULL; + Common::String filename; + Common::File *fileStream = new Common::File(); uint32 fileSize = 0; uint32 fileDataOffset = 0; uint32 fileDataLeft = 0; @@ -1079,11 +1080,42 @@ MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &instrumentDataFi uint32 instrumentOffset = 0; uint16 instrumentDataSize = 0; - if (!instrumentDataFilename.empty()) { - // Filename was passed to us (this is the common case for most games) - fileStream = new Common::File(); + // First check if any filename was passed to us + if ((!filenameAdLib.empty()) || (!filenameOPL3.empty())) { + // If that's the case, check if one of those exists + // Prefer the AdLib one for now + if (!filenameAdLib.empty()) { + if (fileStream->exists(filenameAdLib)) { + // if AdLib file exists, use it + filename = filenameAdLib; + } + } + if (!filename.empty()) { + if (!filenameOPL3.empty()) { + if (fileStream->exists(filenameOPL3)) { + // if OPL3 file exists, use it + filename = filenameOPL3; + } + } + } + if (filename.empty()) { + // If none of them exists, we can't do anything about it + if (!filenameAdLib.empty()) { + if (!filenameOPL3.empty()) { + error("MILES-ADLIB: could not open instrument file (%s or %s)", filenameAdLib.c_str(), filenameOPL3.c_str()); + } else { + error("MILES-ADLIB: could not open instrument file (%s)", filenameAdLib.c_str()); + } + } else { + error("MILES-ADLIB: could not open instrument file (%s)", filenameOPL3.c_str()); + } + } + } + + if (!filename.empty()) { + // Filename was passed to us and file exists (this is the common case for most games) - if (!fileStream->open(instrumentDataFilename)) + if (!fileStream->open(filename)) error("MILES-ADLIB: could not open instrument file"); streamSize = fileStream->size(); @@ -1093,7 +1125,6 @@ MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &instrumentDataFi if (fileStream->read(streamDataPtr, streamSize) != streamSize) error("MILES-ADLIB: error while reading instrument file"); fileStream->close(); - delete fileStream; } else if (instrumentStream) { // instrument data was passed directly (currently used by Amazon Guardians of Eden + Simon 2) @@ -1104,6 +1135,8 @@ MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &instrumentDataFi error("MILES-ADLIB: error while reading instrument stream"); } + delete fileStream; + // File is like this: // [patch:BYTE] [bank:BYTE] [patchoffset:UINT32] // ... |