Skip to content

Commit

Permalink
Fix: Swap nibble order when converting to bytes
Browse files Browse the repository at this point in the history
The nibble order was inverted, causing incorrect waveforms on device
  • Loading branch information
tstirrat committed Sep 1, 2024
1 parent 5b24bb3 commit 9ffc34b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/lib/sysex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9ffc34b

Please sign in to comment.