Skip to content

Commit

Permalink
Merge pull request #61 from virtuaCode/drums-bugfix
Browse files Browse the repository at this point in the history
Fix bug in setDrumInstrument
  • Loading branch information
DhrBaksteen authored Aug 29, 2020
2 parents 4910ca9 + 039bb3d commit 3284cf3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
30 changes: 16 additions & 14 deletions src/OPL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ Instrument OPL2::getDrumInstrument(byte drumType) {
}
}

instrument.feedback = 0x00;
instrument.isAdditiveSynth = false;
instrument.feedback = getFeedback(channel);
instrument.isAdditiveSynth = getSynthMode(channel);
instrument.type = drumType;

return instrument;
Expand Down Expand Up @@ -394,26 +394,28 @@ void OPL2::setDrumInstrument(Instrument instrument, float volume) {

if (registerOffset != 0xFF) {
write(0x20 + registerOffset,
(instrument.operators[0].hasTremolo ? 0x80 : 0x00) +
(instrument.operators[0].hasVibrato ? 0x40 : 0x00) +
(instrument.operators[0].hasSustain ? 0x20 : 0x00) +
(instrument.operators[0].hasEnvelopeScaling ? 0x10 : 0x00) +
(instrument.operators[0].frequencyMultiplier & 0x0F));
(instrument.operators[op].hasTremolo ? 0x80 : 0x00) +
(instrument.operators[op].hasVibrato ? 0x40 : 0x00) +
(instrument.operators[op].hasSustain ? 0x20 : 0x00) +
(instrument.operators[op].hasEnvelopeScaling ? 0x10 : 0x00) +
(instrument.operators[op].frequencyMultiplier & 0x0F));
write(0x40 + registerOffset,
((instrument.operators[0].keyScaleLevel & 0x03) << 6) +
((instrument.operators[op].keyScaleLevel & 0x03) << 6) +
(outputLevel & 0x3F));
write(0x60 + registerOffset,
((instrument.operators[0].attack & 0x0F) << 4) +
(instrument.operators[0].decay & 0x0F));
((instrument.operators[op].attack & 0x0F) << 4) +
(instrument.operators[op].decay & 0x0F));
write(0x80 + registerOffset,
((instrument.operators[0].sustain & 0x0F) << 4) +
(instrument.operators[0].release & 0x0F));
((instrument.operators[op].sustain & 0x0F) << 4) +
(instrument.operators[op].release & 0x0F));
write(0xE0 + registerOffset,
(instrument.operators[0].waveForm & 0x03));
(instrument.operators[op].waveForm & 0x03));
}
}

write(0xC0 + drumChannels[instrument.type - INSTRUMENT_TYPE_BASS], 0x00);
write(0xC0 + drumChannels[instrument.type - INSTRUMENT_TYPE_BASS],
((instrument.feedback & 0x07) << 1) +
(instrument.isAdditiveSynth ? 0x01 : 0x00));
}


Expand Down
14 changes: 7 additions & 7 deletions src/instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const unsigned char INSTRUMENT_BASS2[12] PROGMEM = { 0x00, 0x01, 0x1D, 0xF2,
const unsigned char INSTRUMENT_BASSHARP[12] PROGMEM = { 0x00, 0xC0, 0x6D, 0xF9, 0x01, 0x01, 0x0E, 0x41, 0x00, 0xF2, 0x73, 0x00 };
const unsigned char INSTRUMENT_BASSOON1[12] PROGMEM = { 0x00, 0x30, 0xC8, 0xD5, 0x19, 0x00, 0x0C, 0x71, 0x80, 0x61, 0x1B, 0x00 };
const unsigned char INSTRUMENT_BASSTRLG[12] PROGMEM = { 0x00, 0xC1, 0x4F, 0xB1, 0x53, 0x03, 0x06, 0xE0, 0x00, 0x12, 0x74, 0x03 };
const unsigned char INSTRUMENT_BDRUM1[12] PROGMEM = { 0x06, 0x00, 0x0B, 0xA8, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
const unsigned char INSTRUMENT_BDRUM1[12] PROGMEM = { 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0xA8, 0x4C, 0x00 };
const unsigned char INSTRUMENT_BELLONG[12] PROGMEM = { 0x00, 0x64, 0xDB, 0xFF, 0x01, 0x00, 0x04, 0x3E, 0xC0, 0xF3, 0x62, 0x00 };
const unsigned char INSTRUMENT_BELLS[12] PROGMEM = { 0x00, 0x07, 0x4F, 0xF2, 0x60, 0x00, 0x08, 0x12, 0x00, 0xF2, 0x72, 0x00 };
const unsigned char INSTRUMENT_BELSHORT[12] PROGMEM = { 0x00, 0x64, 0xDB, 0xFF, 0x01, 0x00, 0x04, 0x3E, 0xC0, 0xF5, 0xF3, 0x00 };
Expand All @@ -55,7 +55,7 @@ const unsigned char INSTRUMENT_CLAR2[12] PROGMEM = { 0x00, 0x31, 0x1C, 0x41,
const unsigned char INSTRUMENT_CLARINET[12] PROGMEM = { 0x00, 0x32, 0x9A, 0x51, 0x1B, 0x00, 0x0C, 0x61, 0x82, 0xA2, 0x3B, 0x00 };
const unsigned char INSTRUMENT_CLAVECIN[12] PROGMEM = { 0x00, 0x11, 0x0D, 0xF2, 0x01, 0x00, 0x0A, 0x15, 0x0D, 0xF2, 0xB1, 0x00 };
const unsigned char INSTRUMENT_CROMORNE[12] PROGMEM = { 0x00, 0x00, 0x02, 0xF0, 0xFF, 0x00, 0x06, 0x11, 0x80, 0xF0, 0xFF, 0x00 };
const unsigned char INSTRUMENT_CYMBAL1[12] PROGMEM = { 0x09, 0x01, 0x00, 0xF5, 0xB5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
const unsigned char INSTRUMENT_CYMBAL1[12] PROGMEM = { 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xF5, 0xB5, 0x00 };
const unsigned char INSTRUMENT_ELCLAV1[12] PROGMEM = { 0x00, 0x05, 0x8A, 0xF0, 0x7B, 0x00, 0x08, 0x01, 0x80, 0xF4, 0x7B, 0x00 };
const unsigned char INSTRUMENT_ELCLAV2[12] PROGMEM = { 0x00, 0x01, 0x49, 0xF1, 0x53, 0x01, 0x06, 0x11, 0x00, 0xF1, 0x74, 0x02 };
const unsigned char INSTRUMENT_ELECFL[12] PROGMEM = { 0x00, 0xE0, 0x6D, 0x57, 0x04, 0x01, 0x0E, 0x61, 0x00, 0x67, 0x7D, 0x00 };
Expand Down Expand Up @@ -97,12 +97,12 @@ const unsigned char INSTRUMENT_JEWSHARP[12] PROGMEM = { 0x00, 0x00, 0x50, 0xF2,
const unsigned char INSTRUMENT_KEYBRD1[12] PROGMEM = { 0x00, 0x00, 0x02, 0xF0, 0xFA, 0x01, 0x06, 0x11, 0x80, 0xF2, 0xFA, 0x01 };
const unsigned char INSTRUMENT_KEYBRD2[12] PROGMEM = { 0x00, 0x01, 0x8F, 0xF2, 0xBD, 0x00, 0x08, 0x14, 0x80, 0x82, 0xBD, 0x00 };
const unsigned char INSTRUMENT_KEYBRD3[12] PROGMEM = { 0x00, 0x01, 0x00, 0xF0, 0xF0, 0x00, 0x00, 0xE4, 0x03, 0xF3, 0x36, 0x00 };
const unsigned char INSTRUMENT_LASER[12] PROGMEM = { 0x09, 0xE6, 0x00, 0x25, 0xB5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
const unsigned char INSTRUMENT_LASER[12] PROGMEM = { 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0x00, 0x25, 0xB5, 0x00 };
const unsigned char INSTRUMENT_LOGDRUM1[12] PROGMEM = { 0x00, 0x32, 0x44, 0xF8, 0xFF, 0x00, 0x0E, 0x11, 0x00, 0xF5, 0x7F, 0x00 };
const unsigned char INSTRUMENT_MARIMBA1[12] PROGMEM = { 0x00, 0x05, 0x4E, 0xDA, 0x25, 0x00, 0x0A, 0x01, 0x00, 0xF9, 0x15, 0x00 };
const unsigned char INSTRUMENT_MARIMBA2[12] PROGMEM = { 0x00, 0x85, 0x4E, 0xDA, 0x15, 0x00, 0x0A, 0x81, 0x80, 0xF9, 0x13, 0x00 };
const unsigned char INSTRUMENT_MDRNPHON[12] PROGMEM = { 0x00, 0x30, 0x00, 0xFE, 0x11, 0x01, 0x08, 0xAE, 0xC0, 0xF1, 0x19, 0x01 };
const unsigned char INSTRUMENT_MLTRDRUM[12] PROGMEM = { 0x07, 0x0C, 0x00, 0xC8, 0xB6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
const unsigned char INSTRUMENT_MLTRDRUM[12] PROGMEM = { 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0xC8, 0xB6, 0x01 };
const unsigned char INSTRUMENT_MOOGSYNT[12] PROGMEM = { 0x00, 0x20, 0x90, 0xF5, 0x9E, 0x02, 0x0C, 0x11, 0x00, 0xF4, 0x5B, 0x03 };
const unsigned char INSTRUMENT_NOISE1[12] PROGMEM = { 0x00, 0x0E, 0x40, 0xD1, 0x53, 0x00, 0x0E, 0x0E, 0x00, 0xF2, 0x7F, 0x03 };
const unsigned char INSTRUMENT_OBOE1[12] PROGMEM = { 0x00, 0xB1, 0xC5, 0x6E, 0x17, 0x00, 0x02, 0x22, 0x05, 0x8B, 0x0E, 0x00 };
Expand All @@ -125,7 +125,7 @@ const unsigned char INSTRUMENT_PIANO4[12] PROGMEM = { 0x00, 0x01, 0x4D, 0xF1,
const unsigned char INSTRUMENT_PIANOBEL[12] PROGMEM = { 0x00, 0x03, 0x4F, 0xF1, 0x53, 0x00, 0x06, 0x17, 0x03, 0xF2, 0x74, 0x00 };
const unsigned char INSTRUMENT_PIANOF[12] PROGMEM = { 0x00, 0x01, 0xCF, 0xF1, 0x53, 0x00, 0x02, 0x12, 0x00, 0xF2, 0x83, 0x00 };
const unsigned char INSTRUMENT_POPBASS1[12] PROGMEM = { 0x00, 0x10, 0x00, 0x75, 0x93, 0x01, 0x00, 0x01, 0x00, 0xF5, 0x82, 0x01 };
const unsigned char INSTRUMENT_RKSNARE1[12] PROGMEM = { 0x07, 0x0C, 0x00, 0xC7, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
const unsigned char INSTRUMENT_RKSNARE1[12] PROGMEM = { 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0xC7, 0xB4, 0x00 };
const unsigned char INSTRUMENT_SAX1[12] PROGMEM = { 0x00, 0x01, 0x4F, 0x71, 0x53, 0x00, 0x0A, 0x12, 0x00, 0x52, 0x7C, 0x00 };
const unsigned char INSTRUMENT_SCRATCH[12] PROGMEM = { 0x00, 0x07, 0x00, 0xF0, 0xF0, 0x00, 0x0E, 0x00, 0x00, 0x5C, 0xDC, 0x00 };
const unsigned char INSTRUMENT_SCRATCH4[12] PROGMEM = { 0x00, 0x07, 0x00, 0xF0, 0xF0, 0x00, 0x0E, 0x00, 0x00, 0x5C, 0xDC, 0x00 };
Expand All @@ -134,7 +134,7 @@ const unsigned char INSTRUMENT_SHRTVIBE[12] PROGMEM = { 0x00, 0xE4, 0x0E, 0xFF,
const unsigned char INSTRUMENT_SITAR1[12] PROGMEM = { 0x00, 0x01, 0x40, 0xF1, 0x53, 0x00, 0x00, 0x08, 0x40, 0xF1, 0x53, 0x00 };
const unsigned char INSTRUMENT_SITAR2[12] PROGMEM = { 0x00, 0x01, 0x40, 0xF1, 0x53, 0x00, 0x00, 0x08, 0x40, 0xF1, 0x53, 0x01 };
const unsigned char INSTRUMENT_SNAKEFL[12] PROGMEM = { 0x00, 0x61, 0x0C, 0x81, 0x03, 0x00, 0x08, 0x71, 0x80, 0x61, 0x0C, 0x00 };
const unsigned char INSTRUMENT_SNARE1[12] PROGMEM = { 0x07, 0x0C, 0x00, 0xF8, 0xB5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
const unsigned char INSTRUMENT_SNARE1[12] PROGMEM = { 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0xF8, 0xB5, 0x00 };
const unsigned char INSTRUMENT_SNRSUST[12] PROGMEM = { 0x00, 0x06, 0x00, 0xF0, 0xF0, 0x00, 0x0E, 0xC4, 0x03, 0xC4, 0x34, 0x00 };
const unsigned char INSTRUMENT_SOLOVLN[12] PROGMEM = { 0x00, 0x70, 0x1C, 0x51, 0x03, 0x02, 0x0E, 0x20, 0x00, 0x54, 0x67, 0x02 };
const unsigned char INSTRUMENT_STEELGT1[12] PROGMEM = { 0x00, 0x01, 0x46, 0xF1, 0x83, 0x00, 0x06, 0x61, 0x03, 0x31, 0x86, 0x00 };
Expand Down Expand Up @@ -176,5 +176,5 @@ const unsigned char INSTRUMENT_VIOLIN3[12] PROGMEM = { 0x00, 0xE1, 0x88, 0x64,
const unsigned char INSTRUMENT_VLNPIZZ1[12] PROGMEM = { 0x00, 0x31, 0x9C, 0xF1, 0xF9, 0x00, 0x0E, 0x31, 0x80, 0xF7, 0xE6, 0x00 };
const unsigned char INSTRUMENT_WAVE[12] PROGMEM = { 0x00, 0x00, 0x02, 0x00, 0xF0, 0x00, 0x0E, 0x14, 0x80, 0x1B, 0xA2, 0x00 };
const unsigned char INSTRUMENT_XYLO1[12] PROGMEM = { 0x00, 0x11, 0x2D, 0xC8, 0x2F, 0x00, 0x0C, 0x31, 0x00, 0xF5, 0xF5, 0x00 };
const unsigned char INSTRUMENT_XYLO2[12] PROGMEM = { 0x06, 0x2E, 0x00, 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
const unsigned char INSTRUMENT_XYLO2[12] PROGMEM = { 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2E, 0x00, 0xFF, 0x0F, 0x00 };
const unsigned char INSTRUMENT_XYLO3[12] PROGMEM = { 0x00, 0x06, 0x00, 0xFF, 0xF0, 0x00, 0x0E, 0xC4, 0x00, 0xF8, 0xB5, 0x00 };

0 comments on commit 3284cf3

Please sign in to comment.