diff --git a/include/sound4calc.h b/include/sound4calc.h index 5e6e000..2531984 100644 --- a/include/sound4calc.h +++ b/include/sound4calc.h @@ -3,11 +3,17 @@ extern struct Note { - char* wave_signal; + struct Wave wave; unsigned short duration; unsigned int freq; } note; +struct Wave +{ + char* signal; + unsigned short length; +}; + void CallSequence(); void CallNote(); void PutPinState(char level); diff --git a/src/main.c b/src/main.c index 1ffb0e0..d0ed060 100644 --- a/src/main.c +++ b/src/main.c @@ -19,11 +19,13 @@ int main(void) dclear(); dprint(1, 1, "%d", note.freq); - dprint(1, 10, "%s", note.wave_signal); - dprint(1, 20, "%d, %d", strlen(note.wave_signal), place); + dprint(1, 10, "%s", note.wave.signal); + dprint(1, 20, "%d", place); dprint(1, 30, "F1:note/F2:sequence"); dtext(1, 50, "F5 _ F6 -"); + note.wave.length = place; + dupdate(); key = getkey(); @@ -35,9 +37,9 @@ int main(void) case KEY_UP : note.freq+=10; break; case KEY_DOWN : note.freq-=10; break; - case KEY_F5 : *(note.wave_signal+place++) = '_'; break; - case KEY_F6 : *(note.wave_signal+place++) = '-'; break; - case KEY_DEL : place=(place>0 ? place - 1 : 0); *(note.wave_signal+place) = 0; break; + case KEY_F5 : *(note.wave.signal+place++) = '_'; break; + case KEY_F6 : *(note.wave.signal+place++) = '-'; break; + case KEY_DEL : place=(place>0 ? place - 1 : 0); *(note.wave.signal+place) = 0; break; case KEY_F1 : CallNote(); break; case KEY_F2 : CallSequence(); break; diff --git a/src/sound4calc.c b/src/sound4calc.c index 741618b..d575d9a 100644 --- a/src/sound4calc.c +++ b/src/sound4calc.c @@ -38,7 +38,7 @@ void CallSequence() } // update of the number of turn - length_end = strlen(note.wave_signal) * seq[notes].freq * seq[notes].length_ms / 1000; + length_end = strlen(note.wave.signal) * seq[notes].freq * seq[notes].length_ms / 1000; // start or reload the timer timer_start(TIMER_USER, 2 * seq[notes].freq, Clock_Hz, CallSequence, 0); } @@ -50,7 +50,7 @@ void CallSequence() void CallNote() { note.duration = 1000; - timer_start(TIMER_USER, note.freq * strlen(note.wave_signal), Clock_Hz, PlayNote, strlen(note.wave_signal) * note.freq * note.duration / 1000); + timer_start(TIMER_USER, note.freq * note.wave.length, Clock_Hz, PlayNote, note.wave.length * note.freq * note.duration / 1000); } /* @@ -68,9 +68,9 @@ void PlayNote() { static int x = 0; - PutPinState(note.wave_signal[x]=='-'); + PutPinState(note.wave.signal[x]=='-'); x = x + 1; - if(!(note.wave_signal[x])) x = 0; + if(!(note.wave.signal[x])) x = 0; } /*