DhrBaksteen / ArduinoOPL2

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

OPL3 class seems to lack OPL3-specific addressing #74

Closed jonkerj closed 3 years ago

jonkerj commented 3 years ago

I previously wrote some code to do MIDI-to-OPL2 and play old tunes through a MIDI console. I recently upgraded to (single) OPL3 using the OPL3Duo, which sounded great as a drop-in replacement. To level up my game, I enabled 4-op mode, but I got a feeling I could not achieve full 6-voice polyphony: notes sounded like they were getting "stolen" by my voice allocator.

I did some debugging, and the voice allocator works fine. Actually, it did before on 6-voice 2-op OPL2, so I dug a little deeper. My next guess was there was something wrong with the BANK/A1 pin, which would effectively halve the amount of voices. And also, it would prevent the chip from going into OPL3 mode. I started comparing the sounds to an emulated OPL3, and it could be the case.

Looking at the code:

I am trying to get my head around the datasheet/programming guide to come up with a PR to address these issues, but if anyone is more fluent in YM262, I would appreciate some help :-)

DhrBaksteen commented 3 years ago

I think you're using the OPL3 class directly? When I wrote OPL3.cpp I intended it as a base for the OPL3Duo class, so I have not fully tested it stand alone.

  1. The setChipRegister for the OPL3 class was indeed missing and I have staged it locally for the upcoming update as

    void OPL3::setChipRegister(short reg, byte value) {
    chipRegisters[getChipRegisterOffset(reg)] = value;
    write(reg >> 8, reg & 0xFF, value);
    }
  2. For the setChannelRegister and setOperatorRegister of the OPL3 class I see I completely messed up here cause indeed it should not be (channel >> 8) & 0x01! It can be something like byte bank = (channel / CHANNELS_PER_BANK); as in the OPL3Duo class.

jonkerj commented 3 years ago

Yes indeed. I am using OPL3 directly. I will try the suggestions, was already peeking at the OPL3Duo code, where they seem more appropriate.

jonkerj commented 3 years ago

Yes, that works. I'll PR it for good measure.