From 63bcdde0bce4c4cba2b6879ec2d35335c6def572 Mon Sep 17 00:00:00 2001 From: George Satellite Date: Sun, 27 Aug 2023 15:58:47 +0300 Subject: [PATCH 1/2] midiNoteToFreq: impl closer to JUCE --- src/utils/math/midi.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/math/midi.ts b/src/utils/math/midi.ts index e9f42de..1c0c1db 100644 --- a/src/utils/math/midi.ts +++ b/src/utils/math/midi.ts @@ -2,6 +2,5 @@ * Gets frequency in Hz for corresponding MIDI note. */ export function midiNoteToFreq(note: number) { - const a = 440; - return (a / 32) * 2 ** ((note - 9) / 12); + return 440 * 2 ** ((note - 69) / 12); } From 8285f6d9829f2aca7010b33cb64a255e2f7d56cc Mon Sep 17 00:00:00 2001 From: George Satellite Date: Sun, 27 Aug 2023 16:05:50 +0300 Subject: [PATCH 2/2] [skip deploy] JUCE reference in comment --- src/utils/math/midi.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/math/midi.ts b/src/utils/math/midi.ts index 1c0c1db..c081ec0 100644 --- a/src/utils/math/midi.ts +++ b/src/utils/math/midi.ts @@ -1,5 +1,8 @@ /** * Gets frequency in Hz for corresponding MIDI note. + * + * Same as JUCE's `MidiMessage::getMidiNoteInHertz`: + * https://github.com/juce-framework/JUCE/blob/master/modules/juce_audio_basics/midi/juce_MidiMessage.cpp#L1037-L1040 */ export function midiNoteToFreq(note: number) { return 440 * 2 ** ((note - 69) / 12);