aboutsummaryrefslogtreecommitdiff
path: root/quantum/audio
diff options
context:
space:
mode:
authorAlex Ong <the.onga@gmail.com>2019-01-04 19:39:14 +1100
committerAlex Ong <the.onga@gmail.com>2019-01-04 19:39:14 +1100
commit47c91fc7f75ae0a477e55b687aa0fc30da0a283c (patch)
tree65ad39452748ff2e6d4a83ce54ede6ca22c9ada9 /quantum/audio
parentac9b88e8ccbbf38762871504cd827ff0d941c426 (diff)
parent563ce3f225d981ce460c12ca5130dfe47af41df0 (diff)
downloadqmk_firmware-47c91fc7f75ae0a477e55b687aa0fc30da0a283c.tar.gz
qmk_firmware-47c91fc7f75ae0a477e55b687aa0fc30da0a283c.zip
Merge branch 'master' of https://github.com/qmk/qmk_firmware
Diffstat (limited to 'quantum/audio')
-rw-r--r--quantum/audio/audio.c8
-rw-r--r--quantum/audio/audio.h3
-rw-r--r--quantum/audio/audio_arm.c135
-rw-r--r--quantum/audio/song_list.h30
4 files changed, 47 insertions, 129 deletions
diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c
index c948a60d6..6d6833ec1 100644
--- a/quantum/audio/audio.c
+++ b/quantum/audio/audio.c
@@ -223,7 +223,7 @@ void audio_init()
223 TCCR1B = (1 << WGM13) | (1 << WGM12) | (0 << CS12) | (1 << CS11) | (0 << CS10); 223 TCCR1B = (1 << WGM13) | (1 << WGM12) | (0 << CS12) | (1 << CS11) | (0 << CS10);
224 TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (440 * CPU_PRESCALER)); 224 TIMER_1_PERIOD = (uint16_t)(((float)F_CPU) / (440 * CPU_PRESCALER));
225 TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (440 * CPU_PRESCALER)) * note_timbre); 225 TIMER_1_DUTY_CYCLE = (uint16_t)((((float)F_CPU) / (440 * CPU_PRESCALER)) * note_timbre);
226 #endif 226 #endif
227 227
228 audio_initialized = true; 228 audio_initialized = true;
229 } 229 }
@@ -231,7 +231,7 @@ void audio_init()
231 if (audio_config.enable) { 231 if (audio_config.enable) {
232 PLAY_SONG(startup_song); 232 PLAY_SONG(startup_song);
233 } 233 }
234 234
235} 235}
236 236
237void stop_all_notes() 237void stop_all_notes()
@@ -464,7 +464,7 @@ ISR(TIMER3_AUDIO_vect)
464 note_position++; 464 note_position++;
465 bool end_of_note = false; 465 bool end_of_note = false;
466 if (TIMER_3_PERIOD > 0) { 466 if (TIMER_3_PERIOD > 0) {
467 if (!note_resting) 467 if (!note_resting)
468 end_of_note = (note_position >= (note_length / TIMER_3_PERIOD * 0xFFFF - 1)); 468 end_of_note = (note_position >= (note_length / TIMER_3_PERIOD * 0xFFFF - 1));
469 else 469 else
470 end_of_note = (note_position >= (note_length)); 470 end_of_note = (note_position >= (note_length));
@@ -604,7 +604,7 @@ ISR(TIMER1_AUDIO_vect)
604 note_position++; 604 note_position++;
605 bool end_of_note = false; 605 bool end_of_note = false;
606 if (TIMER_1_PERIOD > 0) { 606 if (TIMER_1_PERIOD > 0) {
607 if (!note_resting) 607 if (!note_resting)
608 end_of_note = (note_position >= (note_length / TIMER_1_PERIOD * 0xFFFF - 1)); 608 end_of_note = (note_position >= (note_length / TIMER_1_PERIOD * 0xFFFF - 1));
609 else 609 else
610 end_of_note = (note_position >= (note_length)); 610 end_of_note = (note_position >= (note_length));
diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h
index da09b2bcd..8136c5b25 100644
--- a/quantum/audio/audio.h
+++ b/quantum/audio/audio.h
@@ -40,7 +40,8 @@ typedef union {
40 uint8_t raw; 40 uint8_t raw;
41 struct { 41 struct {
42 bool enable :1; 42 bool enable :1;
43 uint8_t level :7; 43 bool clicky_enable :1;
44 uint8_t level :6;
44 }; 45 };
45} audio_config_t; 46} audio_config_t;
46 47
diff --git a/quantum/audio/audio_arm.c b/quantum/audio/audio_arm.c
index d38184f32..989f7a64b 100644
--- a/quantum/audio/audio_arm.c
+++ b/quantum/audio/audio_arm.c
@@ -80,6 +80,9 @@ float startup_song[][2] = STARTUP_SONG;
80static void gpt_cb8(GPTDriver *gptp); 80static void gpt_cb8(GPTDriver *gptp);
81 81
82#define DAC_BUFFER_SIZE 720 82#define DAC_BUFFER_SIZE 720
83#ifndef DAC_SAMPLE_MAX
84#define DAC_SAMPLE_MAX 65535U
85#endif
83 86
84#define START_CHANNEL_1() gptStart(&GPTD6, &gpt6cfg1); \ 87#define START_CHANNEL_1() gptStart(&GPTD6, &gpt6cfg1); \
85 gptStartContinuous(&GPTD6, 2U) 88 gptStartContinuous(&GPTD6, 2U)
@@ -202,132 +205,16 @@ GPTConfig gpt8cfg1 = {
202 205
203// squarewave 206// squarewave
204static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = { 207static const dacsample_t dac_buffer[DAC_BUFFER_SIZE] = {
205 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 208 // First half is max, second half is 0
206 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 209 [0 ... DAC_BUFFER_SIZE/2-1] = DAC_SAMPLE_MAX,
207 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 210 [DAC_BUFFER_SIZE/2 ... DAC_BUFFER_SIZE -1] = 0,
208 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
209 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
210 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
211 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
212 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
213 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
214 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
215 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
216 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
217 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
218 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
219 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
220 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
221 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
222 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
223 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
224 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
225 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
226 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
227 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
228 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
229 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
230 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
231 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
232 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
233 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
234 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
235
236 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
237 0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0,
265 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
266}; 211};
267 212
268// squarewave 213// squarewave
269static const dacsample_t dac_buffer_2[DAC_BUFFER_SIZE] = { 214static const dacsample_t dac_buffer_2[DAC_BUFFER_SIZE] = {
270 215 // opposite of dac_buffer above
271 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 216 [0 ... DAC_BUFFER_SIZE/2-1] = 0,
272 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 217 [DAC_BUFFER_SIZE/2 ... DAC_BUFFER_SIZE -1] = DAC_SAMPLE_MAX,
273 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
274 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
275 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
276 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
277 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
278 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
279 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
280 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
281 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
282 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
283 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
284 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
285 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
286 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
287 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
288 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
289 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
290 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
291 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
292 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
293 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
294 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
295 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
296 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
297 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
298 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
299 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
300 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
301 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
302 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
303 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
304 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
305 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
306 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
307 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
308 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
309 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
310 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
311 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
312 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
313 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
314 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
315 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
316 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
317 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
318 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
319 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
320 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
321 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
322 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
323 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
324 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
325 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
326 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
327 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
328 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
329 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047,
330 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047, 2047
331}; 218};
332 219
333/* 220/*
@@ -363,7 +250,7 @@ static void error_cb1(DACDriver *dacp, dacerror_t err) {
363} 250}
364 251
365static const DACConfig dac1cfg1 = { 252static const DACConfig dac1cfg1 = {
366 .init = 2047U, 253 .init = DAC_SAMPLE_MAX,
367 .datamode = DAC_DHRM_12BIT_RIGHT 254 .datamode = DAC_DHRM_12BIT_RIGHT
368}; 255};
369 256
@@ -375,7 +262,7 @@ static const DACConversionGroup dacgrpcfg1 = {
375}; 262};
376 263
377static const DACConfig dac1cfg2 = { 264static const DACConfig dac1cfg2 = {
378 .init = 2047U, 265 .init = DAC_SAMPLE_MAX,
379 .datamode = DAC_DHRM_12BIT_RIGHT 266 .datamode = DAC_DHRM_12BIT_RIGHT
380}; 267};
381 268
diff --git a/quantum/audio/song_list.h b/quantum/audio/song_list.h
index e63616a99..994608497 100644
--- a/quantum/audio/song_list.h
+++ b/quantum/audio/song_list.h
@@ -472,4 +472,34 @@
472 H__NOTE(_AS4), W__NOTE(_GS4), W__NOTE(_GS4), W__NOTE(_FS4), W__NOTE(_GS4), \ 472 H__NOTE(_AS4), W__NOTE(_GS4), W__NOTE(_GS4), W__NOTE(_FS4), W__NOTE(_GS4), \
473 H__NOTE(_AS4), WD_NOTE(_DS4) 473 H__NOTE(_AS4), WD_NOTE(_DS4)
474 474
475#define RICK_ROLL \
476 Q__NOTE(_F4), \
477 Q__NOTE(_G4), \
478 Q__NOTE(_BF4), \
479 Q__NOTE(_G4), \
480 HD_NOTE(_D5), \
481 HD_NOTE(_D5), \
482 W__NOTE(_C5), \
483 S__NOTE(_REST), \
484 Q__NOTE(_F4), \
485 Q__NOTE(_G4), \
486 Q__NOTE(_BF4), \
487 Q__NOTE(_G4), \
488 HD_NOTE(_C5), \
489 HD_NOTE(_C5), \
490 W__NOTE(_BF4), \
491 S__NOTE(_REST), \
492 Q__NOTE(_F4), \
493 Q__NOTE(_G4), \
494 Q__NOTE(_BF4), \
495 Q__NOTE(_G4), \
496 W__NOTE(_BF4), \
497 H__NOTE(_C5), \
498 H__NOTE(_A4), \
499 H__NOTE(_A4), \
500 H__NOTE(_G4), \
501 H__NOTE(_F4), \
502 H__NOTE(_F4), \
503 W__NOTE(_C5), \
504 W__NOTE(_BF4),
475#endif 505#endif