From 6242df8ffb1987e8b8382d4ceae1456157258e42 Mon Sep 17 00:00:00 2001 From: twobit Date: Wed, 4 Sep 2013 00:57:13 +0200 Subject: [PATCH] improve music --- firmware/apps/ducklings.c | 14 ++++++-------- firmware/lib/music.c | 12 ++++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/firmware/apps/ducklings.c b/firmware/apps/ducklings.c index 4059009..49ce798 100644 --- a/firmware/apps/ducklings.c +++ b/firmware/apps/ducklings.c @@ -5,19 +5,17 @@ #include #include -#define NOTE_BREAK MLDY_LENGTH, 16, NOTE_PAUSE static uint16_t notes[] = { - NOTE_C, NOTE_D, NOTE_E, NOTE_F, MLDY_LENGTH, 2, NOTE_G, MLDY_LENGTH, 2, NOTE_G, NOTE_BREAK, - NOTE_A, NOTE_A, NOTE_A, NOTE_A, MLDY_LENGTH, 2, NOTE_G, NOTE_BREAK, - NOTE_A, NOTE_A, NOTE_A, NOTE_A, MLDY_LENGTH, 2, NOTE_G, NOTE_BREAK, - NOTE_F, NOTE_F, NOTE_F, NOTE_F, MLDY_LENGTH, 2, NOTE_E, MLDY_LENGTH, 2, NOTE_E, NOTE_BREAK, - NOTE_D, NOTE_D, NOTE_D, NOTE_D, MLDY_LENGTH, 1, NOTE_C, NOTE_BREAK, - NOTE_PAUSE, NOTE_PAUSE, NOTE_PAUSE, + NOTE_C, NOTE_D, NOTE_E, NOTE_F, MLDY_LENGTH, 2, NOTE_G, MLDY_LENGTH, 2, NOTE_G, + NOTE_A, NOTE_A, NOTE_A, NOTE_A, MLDY_LENGTH, 3, NOTE_G, NOTE_PAUSE, + NOTE_A, NOTE_A, NOTE_A, NOTE_A, MLDY_LENGTH, 3, NOTE_G, NOTE_PAUSE, + NOTE_F, NOTE_F, NOTE_F, NOTE_F, MLDY_LENGTH, 2, NOTE_E, MLDY_LENGTH, 2, NOTE_E, + NOTE_G, NOTE_G, NOTE_G, NOTE_G, MLDY_LENGTH, 3, NOTE_C, NOTE_PAUSE, }; static void music(void) { - play_melody(notes, ARRAY_SIZE(notes), 4, 500); + play_melody(notes, ARRAY_SIZE(notes), 4, 300); } REG(music); diff --git a/firmware/lib/music.c b/firmware/lib/music.c index 1d5b7fa..73cfc92 100644 --- a/firmware/lib/music.c +++ b/firmware/lib/music.c @@ -30,8 +30,8 @@ void stop_note(void) { } void play_melody(uint16_t notes[], size_t len, uint8_t octave, int speed) { - int pause = speed / 20; - uint8_t length = 4; + uint8_t length = 1; + uint8_t pause = speed / 20; size_t i; @@ -39,7 +39,7 @@ void play_melody(uint16_t notes[], size_t len, uint8_t octave, int speed) { if(notes[i] == MLDY_PAUSE) { // user defined pause ++i; - wait_ms(notes[i]); + wait_ms(speed * notes[i]); } else if(notes[i] == MLDY_LENGTH) { // sets length for next tone ++i; @@ -48,15 +48,15 @@ void play_melody(uint16_t notes[], size_t len, uint8_t octave, int speed) { // play note set_note(notes[i], octave); test_stop_app(); - wait_ms(speed * 4 / length); + wait_ms(speed * length - pause); - // pause after note + // pause stop_note(); test_stop_app(); wait_ms(pause); // reset length for next note - length = 4; + length = 1; } } }