96789a7cb01b6ac3b6cf46a8dec650ac19c823c0

Author
Nebuleon <2391500+Nebuleon@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

Unify MIDI note calculation with the audio feature's algorithm (#21588)

Diff

 1diff --git a/quantum/midi/qmk_midi.c b/quantum/midi/qmk_midi.c
 2index 43ebd72937afdf055436e075d0fba3d9cbcd293e..6b8831fb589d90ebcfe52035238b5da67cc4bdf5 100644
 3--- a/quantum/midi/qmk_midi.c
 4+++ b/quantum/midi/qmk_midi.c
 5@@ -108,10 +108,10 @@ static void fallthrough_callback(MidiDevice* device, uint16_t cnt, uint8_t byte0
 6     if (cnt == 3) {
 7         switch (byte0 & 0xF0) {
 8             case MIDI_NOTEON:
 9-                play_note(((double)261.6) * pow(2.0, -4.0) * pow(2.0, (byte1 & 0x7F) / 12.0), (byte2 & 0x7F) / 8);
10+                play_note(440.0f * powf(2.0f, ((byte1 & 0x7F) - 57) / 12.0f), (byte2 & 0x7F) / 8);
11                 break;
12             case MIDI_NOTEOFF:
13-                stop_note(((double)261.6) * pow(2.0, -4.0) * pow(2.0, (byte1 & 0x7F) / 12.0));
14+                stop_note(440.0f * powf(2.0f, ((byte1 & 0x7F) - 57) / 12.0f));
15                 break;
16         }
17     }