improve music

This commit is contained in:
twobit 2013-09-04 00:57:13 +02:00
parent 5b81a6daf7
commit 6242df8ffb
2 changed files with 12 additions and 14 deletions

View File

@ -5,19 +5,17 @@
#include <pentabug/helper.h> #include <pentabug/helper.h>
#include <pentabug/app.h> #include <pentabug/app.h>
#define NOTE_BREAK MLDY_LENGTH, 16, NOTE_PAUSE
static uint16_t notes[] = { 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_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, 2, NOTE_G, NOTE_BREAK, 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, 2, NOTE_G, NOTE_BREAK, 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_BREAK, NOTE_F, NOTE_F, NOTE_F, NOTE_F, MLDY_LENGTH, 2, NOTE_E, MLDY_LENGTH, 2, NOTE_E,
NOTE_D, NOTE_D, NOTE_D, NOTE_D, MLDY_LENGTH, 1, NOTE_C, NOTE_BREAK, NOTE_G, NOTE_G, NOTE_G, NOTE_G, MLDY_LENGTH, 3, NOTE_C, NOTE_PAUSE,
NOTE_PAUSE, NOTE_PAUSE, NOTE_PAUSE,
}; };
static void music(void) { static void music(void) {
play_melody(notes, ARRAY_SIZE(notes), 4, 500); play_melody(notes, ARRAY_SIZE(notes), 4, 300);
} }
REG(music); REG(music);

View File

@ -30,8 +30,8 @@ void stop_note(void) {
} }
void play_melody(uint16_t notes[], size_t len, uint8_t octave, int speed) { void play_melody(uint16_t notes[], size_t len, uint8_t octave, int speed) {
int pause = speed / 20; uint8_t length = 1;
uint8_t length = 4; uint8_t pause = speed / 20;
size_t i; 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) { if(notes[i] == MLDY_PAUSE) {
// user defined pause // user defined pause
++i; ++i;
wait_ms(notes[i]); wait_ms(speed * notes[i]);
} else if(notes[i] == MLDY_LENGTH) { } else if(notes[i] == MLDY_LENGTH) {
// sets length for next tone // sets length for next tone
++i; ++i;
@ -48,15 +48,15 @@ void play_melody(uint16_t notes[], size_t len, uint8_t octave, int speed) {
// play note // play note
set_note(notes[i], octave); set_note(notes[i], octave);
test_stop_app(); test_stop_app();
wait_ms(speed * 4 / length); wait_ms(speed * length - pause);
// pause after note // pause
stop_note(); stop_note();
test_stop_app(); test_stop_app();
wait_ms(pause); wait_ms(pause);
// reset length for next note // reset length for next note
length = 4; length = 1;
} }
} }
} }