aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-07-21 12:58:48 -0400
committerJack Humbert <jack.humb@gmail.com>2017-07-23 14:59:29 -0400
commit92ccc9a7b8ac856966147be48e24ce652c160386 (patch)
tree14ab610b19a9602392fc1803fcdb380835b20825 /quantum
parentf40ded78947e63c10d97266901d257179aaf49d9 (diff)
downloadqmk_firmware-92ccc9a7b8ac856966147be48e24ce652c160386.tar.gz
qmk_firmware-92ccc9a7b8ac856966147be48e24ce652c160386.zip
use automatic rests with songs (no more rest styles)
Diffstat (limited to 'quantum')
-rw-r--r--quantum/audio/audio.c39
-rw-r--r--quantum/audio/audio.h8
-rw-r--r--quantum/audio/musical_notes.h7
3 files changed, 30 insertions, 24 deletions
diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c
index 5b8563093..baa364eec 100644
--- a/quantum/audio/audio.c
+++ b/quantum/audio/audio.c
@@ -99,7 +99,6 @@ uint16_t note_position = 0;
99float (* notes_pointer)[][2]; 99float (* notes_pointer)[][2];
100uint16_t notes_count; 100uint16_t notes_count;
101bool notes_repeat; 101bool notes_repeat;
102float notes_rest;
103bool note_resting = false; 102bool note_resting = false;
104 103
105uint8_t current_note = 0; 104uint8_t current_note = 0;
@@ -180,7 +179,7 @@ void audio_init()
180 audio_initialized = true; 179 audio_initialized = true;
181 180
182 if (audio_config.enable) { 181 if (audio_config.enable) {
183 PLAY_NOTE_ARRAY(startup_song, false, LEGATO); 182 PLAY_SONG(startup_song);
184 } 183 }
185 184
186} 185}
@@ -416,9 +415,12 @@ ISR(TIMER3_COMPA_vect)
416 note_position++; 415 note_position++;
417 bool end_of_note = false; 416 bool end_of_note = false;
418 if (TIMER_3_PERIOD > 0) { 417 if (TIMER_3_PERIOD > 0) {
419 end_of_note = (note_position >= (note_length / TIMER_3_PERIOD * 0xFFFF)); 418 if (!note_resting)
419 end_of_note = (note_position >= (note_length / TIMER_3_PERIOD * 0xFFFF - 1));
420 else
421 end_of_note = (note_position >= (note_length));
420 } else { 422 } else {
421 end_of_note = (note_position >= (note_length * 0x7FF)); 423 end_of_note = (note_position >= (note_length));
422 } 424 }
423 425
424 if (end_of_note) { 426 if (end_of_note) {
@@ -433,11 +435,16 @@ ISR(TIMER3_COMPA_vect)
433 return; 435 return;
434 } 436 }
435 } 437 }
436 if (!note_resting && (notes_rest > 0)) { 438 if (!note_resting) {
437 note_resting = true; 439 note_resting = true;
438 note_frequency = 0;
439 note_length = notes_rest;
440 current_note--; 440 current_note--;
441 if ((*notes_pointer)[current_note][0] == (*notes_pointer)[current_note + 1][0]) {
442 note_frequency = 0;
443 note_length = 1;
444 } else {
445 note_frequency = (*notes_pointer)[current_note][0];
446 note_length = 1;
447 }
441 } else { 448 } else {
442 note_resting = false; 449 note_resting = false;
443 envelope_index = 0; 450 envelope_index = 0;
@@ -548,9 +555,9 @@ ISR(TIMER1_COMPA_vect)
548 note_position++; 555 note_position++;
549 bool end_of_note = false; 556 bool end_of_note = false;
550 if (TIMER_1_PERIOD > 0) { 557 if (TIMER_1_PERIOD > 0) {
551 end_of_note = (note_position >= (note_length / TIMER_1_PERIOD * 0xFFFF)); 558 end_of_note = (note_position >= (note_length / TIMER_1_PERIOD * 0xFFFF - 1));
552 } else { 559 } else {
553 end_of_note = (note_position >= (note_length * 0x7FF)); 560 end_of_note = (note_position >= (note_length));
554 } 561 }
555 562
556 if (end_of_note) { 563 if (end_of_note) {
@@ -565,11 +572,16 @@ ISR(TIMER1_COMPA_vect)
565 return; 572 return;
566 } 573 }
567 } 574 }
568 if (!note_resting && (notes_rest > 0)) { 575 if (!note_resting) {
569 note_resting = true; 576 note_resting = true;
570 note_frequency = 0;
571 note_length = notes_rest;
572 current_note--; 577 current_note--;
578 if ((*notes_pointer)[current_note][0] == (*notes_pointer)[current_note + 1][0]) {
579 note_frequency = 0;
580 note_length = 1;
581 } else {
582 note_frequency = (*notes_pointer)[current_note][0];
583 note_length = 1;
584 }
573 } else { 585 } else {
574 note_resting = false; 586 note_resting = false;
575 envelope_index = 0; 587 envelope_index = 0;
@@ -638,7 +650,7 @@ void play_note(float freq, int vol) {
638 650
639} 651}
640 652
641void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest) 653void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat)
642{ 654{
643 655
644 if (!audio_initialized) { 656 if (!audio_initialized) {
@@ -663,7 +675,6 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest)
663 notes_pointer = np; 675 notes_pointer = np;
664 notes_count = n_count; 676 notes_count = n_count;
665 notes_repeat = n_repeat; 677 notes_repeat = n_repeat;
666 notes_rest = n_rest;
667 678
668 place = 0; 679 place = 0;
669 current_note = 0; 680 current_note = 0;
diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h
index ad3abeb78..e29770e3b 100644
--- a/quantum/audio/audio.h
+++ b/quantum/audio/audio.h
@@ -86,7 +86,7 @@ void play_sample(uint8_t * s, uint16_t l, bool r);
86void play_note(float freq, int vol); 86void play_note(float freq, int vol);
87void stop_note(float freq); 87void stop_note(float freq);
88void stop_all_notes(void); 88void stop_all_notes(void);
89void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest); 89void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat);
90 90
91#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \ 91#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
92 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \ 92 0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
@@ -98,8 +98,10 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat, float n_rest)
98// length. This works around the limitation of C's sizeof operation on pointers. 98// length. This works around the limitation of C's sizeof operation on pointers.
99// The global float array for the song must be used here. 99// The global float array for the song must be used here.
100#define NOTE_ARRAY_SIZE(x) ((int16_t)(sizeof(x) / (sizeof(x[0])))) 100#define NOTE_ARRAY_SIZE(x) ((int16_t)(sizeof(x) / (sizeof(x[0]))))
101#define PLAY_NOTE_ARRAY(note_array, note_repeat, note_rest_style) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat), (note_rest_style)); 101#define PLAY_NOTE_ARRAY(note_array, note_repeat, deprecated_arg) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), (note_repeat)); \
102#define PLAY_SONG(song) PLAY_NOTE_ARRAY(song, false, STACCATO) 102 _Pragma ("message \"'PLAY_NOTE_ARRAY' macro is deprecated\"")
103#define PLAY_SONG(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), false);
104#define PLAY_LOOP(note_array) play_notes(&note_array, NOTE_ARRAY_SIZE((note_array)), true);
103 105
104bool is_playing_notes(void); 106bool is_playing_notes(void);
105 107
diff --git a/quantum/audio/musical_notes.h b/quantum/audio/musical_notes.h
index a3aaa2f19..647b69564 100644
--- a/quantum/audio/musical_notes.h
+++ b/quantum/audio/musical_notes.h
@@ -51,12 +51,6 @@
51#define ED_NOTE(n) EIGHTH_DOT_NOTE(n) 51#define ED_NOTE(n) EIGHTH_DOT_NOTE(n)
52#define SD_NOTE(n) SIXTEENTH_DOT_NOTE(n) 52#define SD_NOTE(n) SIXTEENTH_DOT_NOTE(n)
53 53
54// Note Styles
55// Staccato makes sure there is a rest between each note. Think: TA TA TA
56// Legato makes notes flow together. Think: TAAA
57#define STACCATO 0.01
58#define LEGATO 0
59
60// Note Timbre 54// Note Timbre
61// Changes how the notes sound 55// Changes how the notes sound
62#define TIMBRE_12 0.125 56#define TIMBRE_12 0.125
@@ -65,7 +59,6 @@
65#define TIMBRE_75 0.750 59#define TIMBRE_75 0.750
66#define TIMBRE_DEFAULT TIMBRE_50 60#define TIMBRE_DEFAULT TIMBRE_50
67 61
68
69// Notes - # = Octave 62// Notes - # = Octave
70 63
71#define NOTE_REST 0.00 64#define NOTE_REST 0.00