aboutsummaryrefslogtreecommitdiff
path: root/quantum/audio.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/audio.c')
-rw-r--r--quantum/audio.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/quantum/audio.c b/quantum/audio.c
index 50e5505fe..73985479c 100644
--- a/quantum/audio.c
+++ b/quantum/audio.c
@@ -8,6 +8,8 @@
8#include "audio.h" 8#include "audio.h"
9#include "keymap_common.h" 9#include "keymap_common.h"
10 10
11#include "eeconfig.h"
12
11#define PI 3.14159265 13#define PI 3.14159265
12 14
13// #define PWM_AUDIO 15// #define PWM_AUDIO
@@ -57,6 +59,25 @@ uint8_t notes_length;
57bool notes_repeat; 59bool notes_repeat;
58uint8_t current_note = 0; 60uint8_t current_note = 0;
59 61
62audio_config_t audio_config;
63
64
65void audio_toggle(void) {
66 audio_config.enable ^= 1;
67 eeconfig_write_audio(audio_config.raw);
68}
69
70void audio_on(void) {
71 audio_config.enable = 1;
72 eeconfig_write_audio(audio_config.raw);
73}
74
75void audio_off(void) {
76 audio_config.enable = 0;
77 eeconfig_write_audio(audio_config.raw);
78}
79
80
60void stop_all_notes() { 81void stop_all_notes() {
61 voices = 0; 82 voices = 0;
62 #ifdef PWM_AUDIO 83 #ifdef PWM_AUDIO
@@ -129,6 +150,12 @@ void stop_note(double freq) {
129 150
130void init_notes() { 151void init_notes() {
131 152
153 /* check signature */
154 if (!eeconfig_is_enabled()) {
155 eeconfig_init();
156 }
157 audio_config.raw = eeconfig_read_audio();
158
132 #ifdef PWM_AUDIO 159 #ifdef PWM_AUDIO
133 PLLFRQ = _BV(PDIV2); 160 PLLFRQ = _BV(PDIV2);
134 PLLCSR = _BV(PLLE); 161 PLLCSR = _BV(PLLE);
@@ -160,7 +187,6 @@ void init_notes() {
160 187
161 188
162ISR(TIMER3_COMPA_vect) { 189ISR(TIMER3_COMPA_vect) {
163
164 if (note) { 190 if (note) {
165 #ifdef PWM_AUDIO 191 #ifdef PWM_AUDIO
166 if (voices == 1) { 192 if (voices == 1) {
@@ -288,9 +314,16 @@ ISR(TIMER3_COMPA_vect) {
288 314
289 } 315 }
290 316
317 if (!audio_config.enable) {
318 notes = false;
319 note = false;
320 }
291} 321}
292 322
293void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) { 323void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) {
324
325if (audio_config.enable) {
326
294 if (note) 327 if (note)
295 stop_all_notes(); 328 stop_all_notes();
296 notes = true; 329 notes = true;
@@ -319,7 +352,12 @@ void play_notes(float (*np)[][2], uint8_t n_length, bool n_repeat) {
319 #endif 352 #endif
320} 353}
321 354
355}
356
322void play_sample(uint8_t * s, uint16_t l, bool r) { 357void play_sample(uint8_t * s, uint16_t l, bool r) {
358
359if (audio_config.enable) {
360
323 stop_all_notes(); 361 stop_all_notes();
324 place_int = 0; 362 place_int = 0;
325 sample = s; 363 sample = s;
@@ -330,9 +368,15 @@ void play_sample(uint8_t * s, uint16_t l, bool r) {
330 TIMSK3 |= _BV(OCIE3A); 368 TIMSK3 |= _BV(OCIE3A);
331 #else 369 #else
332 #endif 370 #endif
371
372}
373
333} 374}
334 375
335void play_note(double freq, int vol) { 376void play_note(double freq, int vol) {
377
378if (audio_config.enable) {
379
336 if (notes) 380 if (notes)
337 stop_all_notes(); 381 stop_all_notes();
338 note = true; 382 note = true;
@@ -367,4 +411,6 @@ void play_note(double freq, int vol) {
367 TCCR3A |= _BV(COM3A1); 411 TCCR3A |= _BV(COM3A1);
368 #endif 412 #endif
369 413
414}
415
370} \ No newline at end of file 416} \ No newline at end of file