codewitch-honey-crisis / MidiSlicer

A simple MIDI slicer tool and full featured MIDI lib in C#
59 stars 16 forks source link

Fix wrong midi channel pitch value. #2

Closed Koseng closed 1 year ago

Koseng commented 1 year ago

Midi channel pitch must be a 14bit value from 0-16383. Current implementation is 15bit value from 0-32639.

Current implementation just combines the two bytes to a 15bit value with a leading 0. unchecked((short)(Data1 + Data2 * 256)) leads to a range from 0 to (127 + 127 * 256) = 32639. 01111111 01111111

Correct calculation for 14bit value: unchecked((short)(Data1 + Data2 * 128)) leads to a range from 0 to (127 + 127 * 128) = 16383. 01111111 1111111

Also when calculated like that, endianess is already always correct.

codewitch-honey-crisis commented 1 year ago

Thanks for this. Sorry the fix took so long for me to get to. I've been kinda slammed.