This commit is contained in:
flo 2017-02-27 21:47:09 +01:00
parent a95779e318
commit 0044669e5d
3 changed files with 28 additions and 21 deletions

View File

@ -1,7 +1,6 @@
#ifndef _SOUND4CALC_H
#define _SOUND4CALC_H
struct Wave
{
char signal[25];

View File

@ -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;

View File

@ -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 '_'