aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/sound/drivers/midi.cpp
diff options
context:
space:
mode:
authorathrxx2018-12-10 00:39:10 +0100
committerFilippos Karapetis2019-04-02 20:45:35 +0300
commit037eec31446b64ec56b24e31d5be392390a694ba (patch)
tree96ff00ec6280e56975c342fa2e9efe98907f8078 /engines/sci/sound/drivers/midi.cpp
parentbc5ecb3b7c01e352c246f30789edd31d097f7c60 (diff)
downloadscummvm-rg350-037eec31446b64ec56b24e31d5be392390a694ba.tar.gz
scummvm-rg350-037eec31446b64ec56b24e31d5be392390a694ba.tar.bz2
scummvm-rg350-037eec31446b64ec56b24e31d5be392390a694ba.zip
SCI: implement SCI0 midi driver track initialization
I put this in an separate commit to make it easier to review/revert. I've tried to make this as minimum invasive as possible. That's why I put this in place of the former call to onNewSound(). SCI_0_LATE sound drivers (probably also SCI_0_EARLY, but I don't know that) do some midi track initialization, mostly resetting certain values and assigning voices (hardware channels) to midi parts. The information for this comes from the track header. The SCI0 version of the PC-98 sound driver relies on this code. The driver checks the channel flags with two different masks and assigns different sound channel types accordingly. This can't be done with the 0x4B event. Using the 0x4B event is sort of counter intuitive anyway, since only some of the SCI0 drivers even support that event. It seems that the only driver making use of onNewSound() was MT-32. I've adapted the driver to my changes, although I am quite sure that the sound will be unaffected. The only thing that the MT-32 driver does with the header information is checking whether a midi part should play or not and assign exactly one timbre (with exactly the same number) to that part if required.
Diffstat (limited to 'engines/sci/sound/drivers/midi.cpp')
-rw-r--r--engines/sci/sound/drivers/midi.cpp47
1 files changed, 38 insertions, 9 deletions
diff --git a/engines/sci/sound/drivers/midi.cpp b/engines/sci/sound/drivers/midi.cpp
index 889a875804..4f3f0da4b0 100644
--- a/engines/sci/sound/drivers/midi.cpp
+++ b/engines/sci/sound/drivers/midi.cpp
@@ -158,10 +158,10 @@ public:
int getFirstChannel() const override;
int getLastChannel() const override;
void setVolume(byte volume) override;
- virtual void onNewSound() override;
int getVolume() override;
void setReverb(int8 reverb) override;
void playSwitch(bool play) override;
+ virtual void initTrack(SciSpan<const byte> &) override;
private:
bool isMt32GmPatch(const SciSpan<const byte> &data);
@@ -479,14 +479,6 @@ int MidiPlayer_Midi::getVolume() {
return _masterVolume;
}
-void MidiPlayer_Midi::onNewSound() {
- if (_defaultReverb >= 0)
- // SCI0 in combination with MT-32 requires a reset of the reverb to
- // the default value that is present in either the MT-32 patch data
- // or MT32.DRV itself.
- setReverb(_defaultReverb);
-}
-
void MidiPlayer_Midi::setReverb(int8 reverb) {
assert(reverb < kReverbConfigNr);
@@ -507,6 +499,43 @@ void MidiPlayer_Midi::playSwitch(bool play) {
}
}
+void MidiPlayer_Midi::initTrack(SciSpan<const byte> &header) {
+ if (_version > SCI_VERSION_0_LATE)
+ return;
+
+ if (_defaultReverb >= 0)
+ // SCI0 in combination with MT-32 requires a reset of the reverb to
+ // the default value that is present in either the MT-32 patch data
+ // or MT32.DRV itself.
+ setReverb(_defaultReverb);
+
+ /* TODO: I have no idea what SCI_VERSION_0_EARLY games do here.
+ Therefore the extra code is restricted to SCI_VERSION_0_LATE for now.*/
+ if (_version == SCI_VERSION_0_EARLY)
+ return;
+
+ uint8 caps = header.getInt8At(0);
+ if (caps != 0 && caps != 2)
+ return;
+
+ uint8 readPos = 3;
+ byte msg[9];
+ uint8 flags = 0;
+
+ for (int i = 1; i < 9; ++i) {
+ readPos++;
+ flags = header.getInt8At(readPos++);
+ msg[i - 1] = (flags & 1) ? i : 0x10;
+ }
+
+ flags = header.getInt8At(readPos);
+ msg[8] = (flags & 0x80) ? 9 : 0x10;
+
+ // assign channels
+ Sci::SciSpan<const byte> s(msg, 9);
+ sendMt32SysEx(0x10000D, s, false);
+}
+
bool MidiPlayer_Midi::isMt32GmPatch(const SciSpan<const byte> &data) {
uint32 size = data.size();