mmitch / gbsplay

gameboy sound player
https://mmitch.github.io/gbsplay/
Other
98 stars 20 forks source link

add alternative MIDI output plugin #21

Closed mmitch closed 5 years ago

mmitch commented 5 years ago

While I was recently tinkering on plugout_midi.c, I realised that the MIDI output does not take the length registers into account and short notes will not be ended at the proper time. I tried to take the length into account but realised that it will only work properly if the MIDI export does cycle-accurate processing of the length register – but that's impossible with the IO-based callbacks.

Fortunately we already have something that does cycle-accurate bookkeeping of the length register (as well as all other registers): gbsplay itself :-) This realization lead to the idea for another MIDI output plugin.

plugout_midi.c registers as an IO callback and basically duplicates part of gbhw.c to keep track of what is going on. Some bookkeeping is needed and that state is basically a more or less accurate duplication of the state in gbhw.c. Things that happen between two IO calls (eg. a length register running out, ending a note) are not seen by plugout_midi.c.

plugout_altmidi.c instead registers a new callback into every Gameboy cpu cycle and directly parses the gbhw_channel state from gbhw.c. It is nearly cycle accurate (and thus more CPU intensive) and can take the length registers into account. Duplicate bookkeeping of the sound hardware state and duplicate code to handle the IO calls are greatly reduced. Currently only two IOs are registerd in the IO callback:

current status

I did listening tests via timidity -E i80 -int gbsfile-%d.mid and it seems to work quite good. Even drymouth sounds kind of like it should ;-)

todo