From c4b8e9c5b70c4559a58fdf7386f84bb566db8a24 Mon Sep 17 00:00:00 2001 From: Ivan Chinenov <40003182+JohnDowson@users.noreply.github.com> Date: Sun, 28 Jun 2020 19:38:17 +0300 Subject: [PATCH] Improve note to frequency conversion ```8 * pow(1.0594630943592952645618252949463, nNoteID);``` was off by about 10hz on my system, while also being ever so slightly slower than this formula --- main4.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main4.cpp b/main4.cpp index 1c35e37..b62fde3 100644 --- a/main4.cpp +++ b/main4.cpp @@ -155,7 +155,9 @@ namespace synth switch (nScaleID) { case SCALE_DEFAULT: default: - return 8 * pow(1.0594630943592952645618252949463, nNoteID); + // n/12th root of 2 * A=440 where n is distance from A4 in semitones + // n = NoteID - 69 as A4 is midi note 69 + return pow(2.0, 0.0 / nNoteID - 69) * 440.0); } }