DhrBaksteen / ArduinoOPL2

Arduino library for use with the OPL2 board (YM3812) and OPL3Duo (YMF262)
MIT License
195 stars 39 forks source link

Fix bug in setDrumInstrument #61

Closed virtuaCode closed 3 years ago

virtuaCode commented 3 years ago

It seams that setDrumInstrument is not quite correct. For example: the bass drum supports Carrier + Modulator, but the current code sets parameters only from the instrument.operators[0] (Modulator).
https://github.com/DhrBaksteen/ArduinoOPL2/blob/4910ca9ac149042e4b702ee9eaed247eff8da79b/src/OPL2.cpp#L395-L412

Also setting the 0xC0 registers to 0x00 makes it impossible to frequency modulate the bass drum. https://github.com/DhrBaksteen/ArduinoOPL2/blob/4910ca9ac149042e4b702ee9eaed247eff8da79b/src/OPL2.cpp#L416

After applying this fix, it will be necessary to change some percussion instrument definitions in instruments.h. (Register values for Operator 1 & 2 needs to be swapped)

Also getDrumInstrument needs to be modified because it skips reading the register for synthtype and feedback https://github.com/DhrBaksteen/ArduinoOPL2/blob/4910ca9ac149042e4b702ee9eaed247eff8da79b/src/OPL2.cpp#L336-L337

DhrBaksteen commented 3 years ago

Good catch! From the looks of it I never really finished that function and left all drums that are using the carrier broken. I'll take an in-depth look at this one tomorrow, thanks for contributing this fix!