summaryrefslogtreecommitdiff
path: root/project/Core/Src/Project/tone.c
diff options
context:
space:
mode:
Diffstat (limited to 'project/Core/Src/Project/tone.c')
-rw-r--r--project/Core/Src/Project/tone.c15
1 files changed, 11 insertions, 4 deletions
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);
}