From 900086c1c9bc4c3ed8db78f622b0c6c70130f51e Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Thu, 31 Aug 2023 01:04:47 -0500 Subject: [PATCH] Fixed 0.1Hz error in tone key frequencies 146.2, 156.7, and 162.2 (#1427) * Fixed tone key freq truncation in float->int conversion * Round integer division when displaying tone key freq --- firmware/application/tone_key.cpp | 2 +- firmware/application/tone_key.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/application/tone_key.cpp b/firmware/application/tone_key.cpp index 5f6aaf98..44858786 100644 --- a/firmware/application/tone_key.cpp +++ b/firmware/application/tone_key.cpp @@ -85,7 +85,7 @@ const tone_key_t tone_keys = { {"Senn. 32.768k", F2Ix100(32768.0)}}; std::string fx100_string(uint32_t f) { - return to_string_dec_uint(f / 100) + "." + to_string_dec_uint((f / 10) % 10); + return to_string_dec_uint(f / 100) + "." + to_string_dec_uint(((f + 5) / 10) % 10); } float tone_key_frequency(tone_index index) { diff --git a/firmware/application/tone_key.hpp b/firmware/application/tone_key.hpp index f2e998f0..6866bfc4 100644 --- a/firmware/application/tone_key.hpp +++ b/firmware/application/tone_key.hpp @@ -31,7 +31,7 @@ namespace tonekey { #define TONE_FREQ_TOLERANCE_CENTIHZ (4 * 100) #define TONE_DISPLAY_TOGGLE_COUNTER 3 -#define F2Ix100(x) (int32_t)(x * 100.0) +#define F2Ix100(x) (int32_t)(x * 100.0 + 0.5) // add 0.5f to round vs truncate during FP->int conversion using tone_index = int32_t; using tone_key_t = std::vector>;