From 0044669e5dd22d042f64d7b9fe988d92504ddc3d Mon Sep 17 00:00:00 2001 From: flo Date: Mon, 27 Feb 2017 21:47:09 +0100 Subject: [PATCH] news --- include/sound4calc.h | 1 - src/main.c | 16 +++++++++++----- src/sound4calc.c | 32 +++++++++++++++++--------------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/include/sound4calc.h b/include/sound4calc.h index d6903b4..48a452e 100644 --- a/include/sound4calc.h +++ b/include/sound4calc.h @@ -1,7 +1,6 @@ #ifndef _SOUND4CALC_H #define _SOUND4CALC_H - struct Wave { char signal[25]; diff --git a/src/main.c b/src/main.c index e33a9db..39487dd 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,12 @@ #include "string.h" //#define PI 3.141592653584 +void DrawKeyF(unsigned char* str, unsigned char keyF) +{ + dprint((keyF-1)*22 + 8 - 2*strlen(str), 55, "%s", str); + dreverse_area((keyF-1)*22 - 2 , 54, keyF * 21, 64); +} + int main(void) { unsigned int key = 0; @@ -26,7 +32,11 @@ int main(void) dprint(1, 10, "%s", note.wave.signal); dprint(1, 20, "%d", place); dprint(1, 30, "F1:note/F2:sequence"); - dtext(1, 50, "F5 _ F6 -"); + + DrawKeyF("not", 1); + DrawKeyF("seq", 2); + DrawKeyF("_", 5); + DrawKeyF("-", 6); note.wave.length = place; @@ -48,10 +58,6 @@ int main(void) case KEY_F1 : CallNote(); break; case KEY_F2 : CallSequence(); break; - case KEY_EXE : - timer_start(TIMER_USER, note.freq * place, Clock_Hz, PlayNote, place * note.freq * note.duration / 1000); - break; - case KEY_EXIT : StopTimer(); return 1; diff --git a/src/sound4calc.c b/src/sound4calc.c index d575d9a..e0a2bfa 100644 --- a/src/sound4calc.c +++ b/src/sound4calc.c @@ -8,9 +8,9 @@ static struct { int freq; int length_ms; } seq[] = { - { 440, 500 }, - { 392, 500 }, - { 349, 500 }, + { 440, 1000 }, + { 392, 1000 }, + { 349, 1000 }, { -1, -1 } }; @@ -22,44 +22,46 @@ struct Note note; */ void CallSequence() { - static int length_end = 0; - static int notes = -1 ; - - if(length_end<=0) + static int seq_length = 0; + static int seq_note = -1; + if(seq_length<=0) { - notes++; + seq_note++; //Stop the timer - if(seq[notes].freq < 0) + if(seq[seq_note].freq < 0) { - length_end = 0; + seq_length = 0; + seq_note = -1; timer_stop(TIMER_USER); return; } // update of the number of turn - length_end = strlen(note.wave.signal) * seq[notes].freq * seq[notes].length_ms / 1000; + seq_length = note.wave.length * seq[seq_note].freq * seq[seq_note].length_ms / 1000; + // start or reload the timer - timer_start(TIMER_USER, 2 * seq[notes].freq, Clock_Hz, CallSequence, 0); + timer_start(TIMER_USER, note.wave.length * seq[seq_note].freq, Clock_Hz, CallSequence, 0); } PlayNote(); - length_end--; + seq_length--; } void CallNote() { - note.duration = 1000; timer_start(TIMER_USER, note.freq * note.wave.length, Clock_Hz, PlayNote, note.wave.length * note.freq * note.duration / 1000); } /* - + StopTimer() + Allow to stop the timer, it's to be independant with the main programm */ void StopTimer() { timer_stop(TIMER_USER); } + /* PlayNote() allow to make different waveforms with '-' and '_'