From 9ffc34b0ce0e6a0b5cfb2a33a2c6c48fd614861d Mon Sep 17 00:00:00 2001 From: Tim Stirrat Date: Mon, 2 Sep 2024 07:53:42 +1000 Subject: [PATCH] Fix: Swap nibble order when converting to bytes The nibble order was inverted, causing incorrect waveforms on device --- src/lib/sysex.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib/sysex.ts b/src/lib/sysex.ts index 6ddff74..854c7f9 100644 --- a/src/lib/sysex.ts +++ b/src/lib/sysex.ts @@ -15,11 +15,10 @@ export function sendWaveformSysex(port: MIDIOutput, waveform: Waveform) { /** Converts a waveform (32 samples) into a byte array (16 bytes) */ export function toBytes(waveform: Waveform) { return waveform.reduce((bytes: number[], sample: number, index: number) => { - const isHighNibble = index % 2; - if (isHighNibble) { - const lowNibble = bytes[bytes.length - 1]; + if (index % 2) { + const highNibble = bytes[bytes.length - 1]; - const byte = lowNibble + (sample << 4); + const byte = sample + (highNibble << 4); bytes[bytes.length - 1] = byte; } else {