Wohlstand / libOPNMIDI

A Software MIDI Synthesizer library with OPN2 (YM2612) emulator
GNU Lesser General Public License v3.0
96 stars 6 forks source link

drum note length extension #78

Closed jpcima closed 5 years ago

jpcima commented 5 years ago

46

I wrote something quick, not really tested.

jpcima commented 5 years ago

Note: it is not optimally efficient, considering it iterates all active notes every period.

The logic is supposed to be this: a new note will receive a Time-To-Live value in seconds. The time will decrease every period until <= 0. Until dropped to 0 or less, the key-off will be kept from occurring, and the flag isOnExtendedLifeTime is true to indicate a note which has key-off pending.

Note(2): when there will exist code to allow double notes, it must take special care for the search predicate of active-notes to ignore the one which is already flagged with isOnExtendedLifeTime, and go for the next. (failing to make to check, it's possible that you will double-release a note which is pending, for example)

Wohlstand commented 5 years ago

A little song where those drums are has zero length: War3#12.mid.gz

Will try some now at my job... Yeah, it works at me, but I didn't benchmarked the thing yet, I think to do this at my home, or when you'll make the "has delayed notes" flag to don't loop this (mainly on songs are don't using percussions, or all percussions are has valid note length).

jpcima commented 5 years ago

I heard the difference on "corruptdrums" files papiezak has posted on the linked issue. It worked in realtime synth, and also in midiplay compared to master branch with sequencer fix disabled. In both cases, drums could be heard which were silent before.

jpcima commented 5 years ago

The commit 1de7ee2 is for caching the numer of notes which have a TTL countdown in progress.

The new function cleanupNote syncs channel state after a note has been removed. It's used on two occasions: note-off, and when a double-note replaces the one before with equal note number.

It fixes an overlooked problem about portamento before: if a double-note overrides a previous one, it would forget to decrement the gliding_note_count.

Wohlstand commented 5 years ago

Woops... This song makes a crash: Game10.mid.gz

jpcima commented 5 years ago

This song makes a crash: Game10.mid.gz

Ok, let me check it.

Just now I uploaded a sample of papiezak's, on the libADLMIDI branch, as I was submitting the identical PR. OI06.MID.gz OI06.MID-after.opus.gz OI06.MID-before.opus.gz

jpcima commented 5 years ago

What I know: it's from updateArpeggio where the assertion raises. The active note does not exist. I will study this case later.

https://github.com/Wohlstand/libOPNMIDI/blob/1de7ee24dda5c13a2b7cbcca36dcde2442536bed/src/opnmidi_midiplay.cpp#L1727-L1731

jpcima commented 5 years ago

Fixed it in the latest.