From 519f868c445a86b988772307ea1f1e2fc95fe54a Mon Sep 17 00:00:00 2001 From: sowgro Date: Sat, 13 Dec 2025 22:13:27 -0500 Subject: all player code written but untested --- project/Core/Src/Project/tone.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'project/Core/Src/Project/tone.c') diff --git a/project/Core/Src/Project/tone.c b/project/Core/Src/Project/tone.c index a0d1cb0..eb6d4b0 100644 --- a/project/Core/Src/Project/tone.c +++ b/project/Core/Src/Project/tone.c @@ -5,7 +5,7 @@ * Author: bruce */ - +#include "systick.h" #include "tone.h" #define CPU_SPEED (80000000.0) @@ -25,7 +25,7 @@ static float notes[] = { /* Octave 9 */ 8372.02, 8869.84, 9397.26, 9956.06,10548.08,11175.30,11839.82,12543.86}; typedef struct { - uint32_t duration; + uint32_t note; uint16_t power; } tone_info; @@ -69,14 +69,21 @@ uint8_t add_tone (uint8_t note, uint8_t velocity) { // Remove a tone from the tones array uint8_t remove_tone (uint8_t note) { - tones [0].duration = hertz_to_systicks (notes [note]); + tones [0].note = hertz_to_systicks (notes [note]); tones [0].power = 0; return 0; } // Play any tones in the array void play_tones () { - + int power_sum = 0; + for (int i = 0; i < MAX_TONES; i++) { + uint32_t rollover = hertz_to_systicks (tones[i].note); + if ((systick_get_count () % rollover) < (rollover >> 1)) { + power_sum += 500; + } + } + DAC_Set_Value(power_sum); } -- cgit v1.2.3