aboutsummaryrefslogtreecommitdiff
path: root/quantum/audio/audio.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/audio/audio.c')
-rw-r--r--quantum/audio/audio.c39
1 files changed, 25 insertions, 14 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;