diff options
author | Martin Kiewitz | 2015-07-05 01:08:40 +0200 |
---|---|---|
committer | Martin Kiewitz | 2015-07-05 01:08:40 +0200 |
commit | 2104f41521a64913d88d1b26da51de5c0b899dc8 (patch) | |
tree | fc9f75d244d3f883f59ccb706b12fe72b2570e08 | |
parent | ef5eda2279a3893ab2c42d06c97ea6c824a30167 (diff) | |
download | scummvm-rg350-2104f41521a64913d88d1b26da51de5c0b899dc8.tar.gz scummvm-rg350-2104f41521a64913d88d1b26da51de5c0b899dc8.tar.bz2 scummvm-rg350-2104f41521a64913d88d1b26da51de5c0b899dc8.zip |
AUDIO: Miles Audio AdLib: support AD+OPL3 streams
- support AdLib + OPL3 streams
- also support stream(s) and filenames getting passed at the same time
in that case filenames are checked first, streams are used
as fallback
-rw-r--r-- | audio/miles.h | 2 | ||||
-rw-r--r-- | audio/miles_adlib.cpp | 63 |
2 files changed, 44 insertions, 21 deletions
diff --git a/audio/miles.h b/audio/miles.h index fc19cc35eb..23d5998fba 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 &filenameAdLib, const Common::String &filenameOPL3, Common::SeekableReadStream *instrumentStream = nullptr); +extern MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &filenameAdLib, const Common::String &filenameOPL3, Common::SeekableReadStream *streamAdLib = nullptr, Common::SeekableReadStream *streamOPL3 = nullptr); extern MidiDriver *MidiDriver_Miles_MT32_create(const Common::String &instrumentDataFilename); diff --git a/audio/miles_adlib.cpp b/audio/miles_adlib.cpp index fb02b906d6..3dcf2e9a55 100644 --- a/audio/miles_adlib.cpp +++ b/audio/miles_adlib.cpp @@ -1060,14 +1060,17 @@ uint32 MidiDriver_Miles_AdLib::property(int prop, uint32 param) { return 0; } -MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &filenameAdLib, const Common::String &filenameOPL3, Common::SeekableReadStream *instrumentStream) { +MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &filenameAdLib, const Common::String &filenameOPL3, Common::SeekableReadStream *streamAdLib, Common::SeekableReadStream *streamOPL3) { // Load adlib instrument data from file SAMPLE.AD (OPL3: SAMPLE.OPL) - Common::String filename; + Common::String timbreFilename; + Common::SeekableReadStream *timbreStream = nullptr; + Common::File *fileStream = new Common::File(); uint32 fileSize = 0; uint32 fileDataOffset = 0; uint32 fileDataLeft = 0; + uint32 streamSize = 0; byte *streamDataPtr = nullptr; @@ -1080,59 +1083,79 @@ MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &filenameAdLib, c uint32 instrumentOffset = 0; uint16 instrumentDataSize = 0; - // First check if any filename was passed to us + // Check if streams were passed to us and select one of them + if ((streamAdLib) || (streamOPL3)) { + // At least one stream was passed by caller + // Prefer AdLib for now + if (streamAdLib) { + timbreStream = streamAdLib; + } else { + // If not available, use OPL3 + if (streamOPL3) { + timbreStream = streamOPL3; + } + } + } + + // Now 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; + timbreFilename = filenameAdLib; } } - if (filename.empty()) { + if (timbreFilename.empty()) { if (!filenameOPL3.empty()) { if (fileStream->exists(filenameOPL3)) { // if OPL3 file exists, use it - filename = filenameOPL3; + timbreFilename = filenameOPL3; } } } - if (filename.empty()) { - // If none of them exists, we can't do anything about it + if (timbreFilename.empty() && (!timbreStream)) { + // If none of them exists and also no stream was passed, 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()); + error("MILES-ADLIB: could not open timbre file (%s or %s)", filenameAdLib.c_str(), filenameOPL3.c_str()); } else { - error("MILES-ADLIB: could not open instrument file (%s)", filenameAdLib.c_str()); + error("MILES-ADLIB: could not open timbre file (%s)", filenameAdLib.c_str()); } } else { - error("MILES-ADLIB: could not open instrument file (%s)", filenameOPL3.c_str()); + error("MILES-ADLIB: could not open timbre file (%s)", filenameOPL3.c_str()); } } } - if (!filename.empty()) { + if (!timbreFilename.empty()) { // Filename was passed to us and file exists (this is the common case for most games) + // We prefer this situation - if (!fileStream->open(filename)) - error("MILES-ADLIB: could not open instrument file"); + if (!fileStream->open(timbreFilename)) + error("MILES-ADLIB: could not open timbre file (%s)", timbreFilename.c_str()); streamSize = fileStream->size(); streamDataPtr = new byte[streamSize]; if (fileStream->read(streamDataPtr, streamSize) != streamSize) - error("MILES-ADLIB: error while reading instrument file"); + error("MILES-ADLIB: error while reading timbre file (%s)", timbreFilename.c_str()); fileStream->close(); - } else if (instrumentStream) { - // instrument data was passed directly (currently used by Amazon Guardians of Eden + Simon 2) - streamSize = instrumentStream->size(); + } else if (timbreStream) { + // Timbre data was passed directly (possibly read from resource file by caller) + // Currently used by "Amazon Guardians of Eden", "Simon 2" and "Return To Zork" + streamSize = timbreStream->size(); + streamDataPtr = new byte[streamSize]; - if (instrumentStream->read(streamDataPtr, streamSize) != streamSize) - error("MILES-ADLIB: error while reading instrument stream"); + if (timbreStream->read(streamDataPtr, streamSize) != streamSize) + error("MILES-ADLIB: error while reading timbre stream"); + + } else { + error("MILES-ADLIB: timbre filenames nor timbre stream were passed"); } delete fileStream; |