mtolly / pokemid

Import/export Pokémon Red/Blue music as MIDI
39 stars 2 forks source link

Channel desync on import #9

Closed Sanqui closed 9 years ago

Sanqui commented 9 years ago

A few midis I have tried seem to desync. I have managed to fix one of them by using a "Collapse Equal-Pitch Notes" option in my MIDI editor, however, this is undesirable for many songs.

http://sanqui.rustedlogic.net/etc/037the_flood.mid - Ch1 and Ch2 accumulate lag over time. http://sanqui.rustedlogic.net/etc/074battle--wild_pokemon.mid - Ch1 lags behind Ch2 consistently. http://sanqui.rustedlogic.net/etc/03Title_screen.mid - Just plain desyncs, but this is a complex piece. Also, Ch1 goes completely silent for a while for no discernible reason.

mtolly commented 9 years ago

I'm starting to look into this. The problem appears to be that the music engine does not support a note or rest that lasts 1 tick while the speed (first parameter of notetype in the assembly) is set to 1. https://gist.github.com/mtolly/e845abda8ccbbf7a6dda demonstrates this; the note should be a tiny blip but instead lasts several seconds. These notes correspond to a note/rest in the MIDI with a length of 1/48 of a beat. So for example, a rest that is 1/48 can result in that channel just pausing for several seconds while the others still play, messing up the whole song.

If this is the main problem, I'll have to figure out some bug-free way to translate these rests, or maybe stretch the notes before them to cover the gap (since it's so small anyway).

BTW, your third MIDI link above is broken. The other two I downloaded fine.

mtolly commented 9 years ago

I was able to fix your first two MIDIs by quantizing to 1/24 of a beat (aka 64th note triplets) which covered up any rests lasting only 1/48 of a beat.

http://pages.cs.wisc.edu/~tolly/pokemid/flood-fixed.mid http://pages.cs.wisc.edu/~tolly/pokemid/wild-fixed.mid

In the future, the program should try to do this itself. For now, the commit I did yesterday will simply tell you it can't make a note/rest that's 1/48 beats long if you give it your original MIDIs. I'll close this issue and make a new one for the quantizing feature.

Sanqui commented 9 years ago

Thank you for looking into this! Since it's a bug in the engine, I'll look into possibly fixing it in my fork instead (which is where the converted songs will be used). Thanks for identifying the issue! Oh, and I also uploaded the third midi in case you want to test with it. It got lost in transmit somewhere. EDIT: For real this time.