tones: add a helper macro to convert from Hz to steps

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
1 files changed, 17 insertions(+), 15 deletions(-)

M tones.c
M tones.c +17 -15
@@ 24,22 24,24 @@ 
 #include "fmfox.h"
 
 #define DIV_ROUND_UP(x, y)	(((x) + (y) - 1) / (y))
+#define HZ_TO_STEPS(freq) \
+	DIV_ROUND_UP((freq), (OUT_SAMPLE_RATE / WAVE_STEPS))
 
-#define E4	DIV_ROUND_UP(330, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define G4	DIV_ROUND_UP(392, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define A4	DIV_ROUND_UP(440, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define C5	DIV_ROUND_UP(523, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define D5	DIV_ROUND_UP(587, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define E5	DIV_ROUND_UP(659, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define G5	DIV_ROUND_UP(784, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define A5	DIV_ROUND_UP(880, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define C6	DIV_ROUND_UP(1047, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define D6	DIV_ROUND_UP(1175, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define E6	DIV_ROUND_UP(1319, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define G6	DIV_ROUND_UP(1568, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define A6	DIV_ROUND_UP(1760, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define C7	DIV_ROUND_UP(2093, (OUT_SAMPLE_RATE / WAVE_STEPS))
-#define D7	DIV_ROUND_UP(2349, (OUT_SAMPLE_RATE / WAVE_STEPS))
+#define E4	HZ_TO_STEPS(330)
+#define G4	HZ_TO_STEPS(392)
+#define A4	HZ_TO_STEPS(440)
+#define C5	HZ_TO_STEPS(523)
+#define D5	HZ_TO_STEPS(587)
+#define E5	HZ_TO_STEPS(659)
+#define G5	HZ_TO_STEPS(784)
+#define A5	HZ_TO_STEPS(880)
+#define C6	HZ_TO_STEPS(1047)
+#define D6	HZ_TO_STEPS(1175)
+#define E6	HZ_TO_STEPS(1319)
+#define G6	HZ_TO_STEPS(1568)
+#define A6	HZ_TO_STEPS(1760)
+#define C7	HZ_TO_STEPS(2093)
+#define D7	HZ_TO_STEPS(2349)
 
 /* a fixed sequence of tones that play in order */
 const __flash uint8_t tones_fixed[] = {