AUDIO: Miles Audio AdLib: OPL3 detect for timbre
tries to detect OPL3 availability and prefers OPL3 timbre data in that case.
This commit is contained in:
parent
83f4565fe2
commit
ba66236c2e
1 changed files with 60 additions and 16 deletions
|
@ -1065,6 +1065,8 @@ MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &filenameAdLib, c
|
||||||
Common::String timbreFilename;
|
Common::String timbreFilename;
|
||||||
Common::SeekableReadStream *timbreStream = nullptr;
|
Common::SeekableReadStream *timbreStream = nullptr;
|
||||||
|
|
||||||
|
bool preferOPL3 = false;
|
||||||
|
|
||||||
Common::File *fileStream = new Common::File();
|
Common::File *fileStream = new Common::File();
|
||||||
uint32 fileSize = 0;
|
uint32 fileSize = 0;
|
||||||
uint32 fileDataOffset = 0;
|
uint32 fileDataOffset = 0;
|
||||||
|
@ -1083,16 +1085,39 @@ MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &filenameAdLib, c
|
||||||
uint32 instrumentOffset = 0;
|
uint32 instrumentOffset = 0;
|
||||||
uint16 instrumentDataSize = 0;
|
uint16 instrumentDataSize = 0;
|
||||||
|
|
||||||
|
// Logic:
|
||||||
|
// We prefer OPL3 timbre data in case OPL3 is available in ScummVM
|
||||||
|
// If it's not or OPL3 timbre data is not available, we go for AdLib timbre data
|
||||||
|
// And if OPL3 is not available in ScummVM and also AdLib timbre data is not available,
|
||||||
|
// we then still go for OPL3 timbre data.
|
||||||
|
//
|
||||||
|
// Note: for most games OPL3 timbre data + AdLib timbre data is the same.
|
||||||
|
// And at least in theory we should still be able to use OPL3 timbre data even for AdLib.
|
||||||
|
// However there is a special OPL3-specific timbre format, which is currently not supported.
|
||||||
|
// In this case the error message "unsupported instrument size" should appear. I haven't found
|
||||||
|
// a game that uses it, which is why I haven't implemented it yet.
|
||||||
|
|
||||||
|
if (OPL::Config::detect(OPL::Config::kOpl3) >= 0) {
|
||||||
|
// OPL3 available, prefer OPL3 timbre data because of this
|
||||||
|
preferOPL3 = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if streams were passed to us and select one of them
|
// Check if streams were passed to us and select one of them
|
||||||
if ((streamAdLib) || (streamOPL3)) {
|
if ((streamAdLib) || (streamOPL3)) {
|
||||||
// At least one stream was passed by caller
|
// At least one stream was passed by caller
|
||||||
// Prefer AdLib for now
|
if (preferOPL3) {
|
||||||
if (streamAdLib) {
|
// Prefer OPL3 timbre stream in case OPL3 is available
|
||||||
timbreStream = streamAdLib;
|
timbreStream = streamOPL3;
|
||||||
} else {
|
}
|
||||||
// If not available, use OPL3
|
if (!timbreStream) {
|
||||||
if (streamOPL3) {
|
// Otherwise prefer AdLib timbre stream first
|
||||||
timbreStream = streamOPL3;
|
if (streamAdLib) {
|
||||||
|
timbreStream = streamAdLib;
|
||||||
|
} else {
|
||||||
|
// If not available, use OPL3 timbre stream
|
||||||
|
if (streamOPL3) {
|
||||||
|
timbreStream = streamOPL3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1100,20 +1125,39 @@ MidiDriver *MidiDriver_Miles_AdLib_create(const Common::String &filenameAdLib, c
|
||||||
// Now check if any filename was passed to us
|
// Now check if any filename was passed to us
|
||||||
if ((!filenameAdLib.empty()) || (!filenameOPL3.empty())) {
|
if ((!filenameAdLib.empty()) || (!filenameOPL3.empty())) {
|
||||||
// If that's the case, check if one of those exists
|
// If that's the case, check if one of those exists
|
||||||
// Prefer the AdLib one for now
|
if (preferOPL3) {
|
||||||
if (!filenameAdLib.empty()) {
|
// OPL3 available
|
||||||
if (fileStream->exists(filenameAdLib)) {
|
|
||||||
// if AdLib file exists, use it
|
|
||||||
timbreFilename = filenameAdLib;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (timbreFilename.empty()) {
|
|
||||||
if (!filenameOPL3.empty()) {
|
if (!filenameOPL3.empty()) {
|
||||||
if (fileStream->exists(filenameOPL3)) {
|
if (fileStream->exists(filenameOPL3)) {
|
||||||
// if OPL3 file exists, use it
|
// If OPL3 available, prefer OPL3 timbre file in case file exists
|
||||||
timbreFilename = filenameOPL3;
|
timbreFilename = filenameOPL3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (timbreFilename.empty()) {
|
||||||
|
if (!filenameAdLib.empty()) {
|
||||||
|
if (fileStream->exists(filenameAdLib)) {
|
||||||
|
// otherwise use AdLib timbre file, if it exists
|
||||||
|
timbreFilename = filenameAdLib;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// OPL3 not available
|
||||||
|
// Prefer the AdLib one for now
|
||||||
|
if (!filenameAdLib.empty()) {
|
||||||
|
if (fileStream->exists(filenameAdLib)) {
|
||||||
|
// if AdLib file exists, use it
|
||||||
|
timbreFilename = filenameAdLib;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (timbreFilename.empty()) {
|
||||||
|
if (!filenameOPL3.empty()) {
|
||||||
|
if (fileStream->exists(filenameOPL3)) {
|
||||||
|
// if OPL3 file exists, use it
|
||||||
|
timbreFilename = filenameOPL3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (timbreFilename.empty() && (!timbreStream)) {
|
if (timbreFilename.empty() && (!timbreStream)) {
|
||||||
// If none of them exists and also no stream was passed, we can't do anything about it
|
// If none of them exists and also no stream was passed, we can't do anything about it
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue