aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorFilippos Karapetis2010-08-18 11:03:12 +0000
committerFilippos Karapetis2010-08-18 11:03:12 +0000
commitff8cfd3d9bc12fe0ca3ceeab5ea3615801e41957 (patch)
tree7a4593f1a633427420907f0c9a575a31430ad643 /engines
parent135b9ee63cacfd6cfefa976609914cb30c144f63 (diff)
downloadscummvm-rg350-ff8cfd3d9bc12fe0ca3ceeab5ea3615801e41957.tar.gz
scummvm-rg350-ff8cfd3d9bc12fe0ca3ceeab5ea3615801e41957.tar.bz2
scummvm-rg350-ff8cfd3d9bc12fe0ca3ceeab5ea3615801e41957.zip
SCI MIDI: adding some asserts as well as proper initialization for _velocityMap
svn-id: r52184
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/sound/drivers/midi.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/engines/sci/sound/drivers/midi.cpp b/engines/sci/sound/drivers/midi.cpp
index 1ef0781906..3a7a129b5b 100644
--- a/engines/sci/sound/drivers/midi.cpp
+++ b/engines/sci/sound/drivers/midi.cpp
@@ -139,6 +139,10 @@ MidiPlayer_Midi::~MidiPlayer_Midi() {
void MidiPlayer_Midi::noteOn(int channel, int note, int velocity) {
uint8 patch = _channels[channel].mappedPatch;
+ assert(channel <= 15);
+ assert(note <= 127);
+ assert(velocity <= 127);
+
if (channel == MIDI_RHYTHM_CHANNEL) {
if (_percussionMap[note] == MIDI_UNMAPPED) {
debugC(kDebugLevelSound, "[Midi] Percussion instrument %i is unmapped", note);
@@ -175,6 +179,7 @@ void MidiPlayer_Midi::noteOn(int channel, int note, int velocity) {
// We assume that velocity 0 maps to 0 (for note off)
int mapIndex = _channels[channel].velocityMapIdx;
+ assert(velocity <= 127);
velocity = _velocityMap[mapIndex][velocity];
}
@@ -183,6 +188,8 @@ void MidiPlayer_Midi::noteOn(int channel, int note, int velocity) {
}
void MidiPlayer_Midi::controlChange(int channel, int control, int value) {
+ assert(channel <= 15);
+
switch (control) {
case 0x07:
_channels[channel].volume = value;
@@ -232,6 +239,8 @@ void MidiPlayer_Midi::controlChange(int channel, int control, int value) {
void MidiPlayer_Midi::setPatch(int channel, int patch) {
bool resetVol = false;
+ assert(channel <= 15);
+
if ((channel == MIDI_RHYTHM_CHANNEL) || (_channels[channel].patch == patch))
return;
@@ -772,6 +781,9 @@ int MidiPlayer_Midi::open(ResourceManager *resMan) {
_percussionMap[i] = i;
_patchMap[i] = i;
_velocityMap[0][i] = i;
+ _velocityMap[1][i] = i;
+ _velocityMap[2][i] = i;
+ _velocityMap[3][i] = i;
_keyShift[i] = 0;
_volAdjust[i] = 0;
_velocityMapIdx[i] = 0;
@@ -817,8 +829,12 @@ int MidiPlayer_Midi::open(ResourceManager *resMan) {
warning("Game has no native support for General MIDI, applying auto-mapping");
// Modify velocity map to make low velocity notes a little louder
- for (uint i = 1; i < 0x40; i++)
+ for (uint i = 1; i < 0x40; i++) {
_velocityMap[0][i] = 0x20 + (i - 1) / 2;
+ _velocityMap[1][i] = 0x20 + (i - 1) / 2;
+ _velocityMap[2][i] = 0x20 + (i - 1) / 2;
+ _velocityMap[3][i] = 0x20 + (i - 1) / 2;
+ }
res = resMan->findResource(ResourceId(kResourceTypePatch, 1), 0);