beug
This commit is contained in:
parent
5649753dfc
commit
8de686f0d2
|
@ -1,4 +1,6 @@
|
|||
#ifndef _MAIN_H
|
||||
#define _MAIN_H
|
||||
|
||||
void DrawKeyF(char* str, unsigned char keyF);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
#ifndef _SOUND4CALC_H
|
||||
#define _SOUND4CALC_H
|
||||
|
||||
#include <timer.h>
|
||||
#include <clock.h>
|
||||
#include <mpu.h>
|
||||
|
||||
struct Wave
|
||||
{
|
||||
unsigned short signal;
|
||||
unsigned int signal;
|
||||
unsigned short length;
|
||||
};
|
||||
|
||||
|
@ -14,8 +18,10 @@ extern struct Note
|
|||
unsigned int freq;
|
||||
} note;
|
||||
|
||||
void CallSequence();
|
||||
void CallNote();
|
||||
void CallSequence(timer_t **timer);
|
||||
void Sequence();
|
||||
void CallNote(timer_t **timer);
|
||||
void Note();
|
||||
void PutPinState(char level);
|
||||
void PlayNote();
|
||||
void InitPorts();
|
||||
|
|
62
src/main.c
62
src/main.c
|
@ -6,41 +6,47 @@
|
|||
#include "string.h"
|
||||
//#define PI 3.141592653584
|
||||
|
||||
unsigned char *itoa(int n, unsigned char* str, int base)
|
||||
{
|
||||
int i=1, j=0, x;
|
||||
if(n<0) str[j++] = '-', n = -n;
|
||||
for(x=n;x;x/=base) j++;
|
||||
for(x=n;x;x/=base) str[j-i++] = x%base + '0' + 39*(x%base>9);
|
||||
str[j] = 0;
|
||||
return str;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned int key = 0;
|
||||
unsigned short place = 0;
|
||||
unsigned char str[16];
|
||||
unsigned char str[33];
|
||||
|
||||
// initialisation to play
|
||||
note.freq = 440;
|
||||
note.wave.signal = 0;
|
||||
note.duration = 2000;
|
||||
|
||||
note.wave.length = 16; // 2 bytes long
|
||||
note.wave.length = 32; // 4 bytes long
|
||||
|
||||
InitPorts();
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
||||
dclear();
|
||||
|
||||
dprint(1, 1, "frq = %d", note.freq);
|
||||
dprint(1, 10, "%s", str);
|
||||
dprint(1, 10, "%s", itoa(note.wave.signal, str, 16));
|
||||
dprint(1, 20, "%d", note.wave.signal);
|
||||
dprint(1, 30, "%d", place);
|
||||
dprint(1, 40, "length %d", note.wave.length);
|
||||
|
||||
DrawKeyF("not", 1);
|
||||
DrawKeyF("seq", 2);
|
||||
DrawKeyF("1", 5);
|
||||
DrawKeyF("0", 6);
|
||||
|
||||
dupdate();
|
||||
|
||||
str[place] = 0;
|
||||
note.wave.signal = atob(str, note.wave.length);
|
||||
|
||||
key = getkey();
|
||||
|
||||
switch(key)
|
||||
|
@ -50,19 +56,37 @@ int main(void)
|
|||
case KEY_UP : note.freq+=10; break;
|
||||
case KEY_DOWN : note.freq-=10; break;
|
||||
|
||||
case KEY_F5 : str[place] = '1'; place=(place < note.wave.signal ? place + 1 : place); break;
|
||||
case KEY_F6 : str[place] = '0'; place=(place < note.wave.signal ? place + 1 : place); break;
|
||||
case KEY_DEL : place=(place>0 ? place - 1 : 0); break;
|
||||
//case KEY_F5 : note.wave.signal = note.wave.signal | (0x01<<place); place=(place < note.wave.length - 1 ? place + 1 : place); break;
|
||||
//case KEY_F6 : note.wave.signal = (note.wave.signal & ~(0x0<<place)); place=(place < note.wave.length - 1 ? place + 1 : place); break;
|
||||
|
||||
case KEY_1 : note.wave.signal = note.wave.signal | 0x1 << place; place +=4; break;
|
||||
case KEY_2 : note.wave.signal = note.wave.signal | 0x2 << place; place +=4; break;
|
||||
case KEY_3 : note.wave.signal = note.wave.signal | 0x3 << place; place +=4; break;
|
||||
case KEY_4 : note.wave.signal = note.wave.signal | 0x4 << place; place +=4; break;
|
||||
case KEY_5 : note.wave.signal = note.wave.signal | 0x5 << place; place +=4; break;
|
||||
case KEY_6 : note.wave.signal = note.wave.signal | 0x6 << place; place +=4; break;
|
||||
case KEY_7 : note.wave.signal = note.wave.signal | 0x7 << place; place +=4; break;
|
||||
case KEY_8 : note.wave.signal = note.wave.signal | 0x8 << place; place +=4; break;
|
||||
case KEY_9 : note.wave.signal = note.wave.signal | 0x9 << place; place +=4; break;
|
||||
case KEY_XOT : note.wave.signal = note.wave.signal | 0xA << place; place +=4; break;
|
||||
case KEY_LOG : note.wave.signal = note.wave.signal | 0xB << place; place +=4; break;
|
||||
case KEY_LN : note.wave.signal = note.wave.signal | 0xC << place; place +=4; break;
|
||||
case KEY_SIN : note.wave.signal = note.wave.signal | 0xD << place; place +=4; break;
|
||||
case KEY_COS : note.wave.signal = note.wave.signal | 0xE << place; place +=4; break;
|
||||
case KEY_TAN : note.wave.signal = note.wave.signal | 0xF << place; place +=4; break;
|
||||
|
||||
case KEY_DEL : place = 0; note.wave.signal = 0; break;
|
||||
|
||||
//case KEY_F5 : *(note.wave.signal+place++) = 255; *(note.wave.signal+place) = 0; break;
|
||||
//case KEY_F6 : *(note.wave.signal+place++) = 240; *(note.wave.signal+place) = 0; 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;
|
||||
case KEY_F1 : Note(); break;
|
||||
case KEY_F2 : Sequence(); break;
|
||||
|
||||
case KEY_EXIT : StopTimer(); return 1;
|
||||
}
|
||||
note.wave.signal &= 0x7FFFFFFF;
|
||||
}
|
||||
return 1; // this point is never reached
|
||||
}
|
||||
|
@ -70,15 +94,5 @@ int main(void)
|
|||
void DrawKeyF(char* str, unsigned char keyF)
|
||||
{
|
||||
dprint((keyF-1)*21 + 11 - 3*strlen(str), 55, "%s", str);
|
||||
dreverse_area((keyF-1)*21 + 1 , 54, keyF * 21 - 1, 64);
|
||||
}
|
||||
|
||||
int atob(unsigned char* str, int bit_nb)
|
||||
{
|
||||
unsigned int tmp = 0;
|
||||
for(int i = 0; i < bit_nb; i++)
|
||||
{
|
||||
tmp += ((str[i] - '0') * (0x1 << (bit_nb - i - 1)));
|
||||
}
|
||||
return tmp;
|
||||
//dreverse_area((keyF-1)*21 + 1 , 54, keyF * 21 - 1, 64);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
#include "sound4calc.h"
|
||||
#include <mpu.h> // from Gint
|
||||
#include <timer.h> //from Gint
|
||||
|
||||
static struct {
|
||||
int freq;
|
||||
|
@ -17,14 +15,16 @@ static struct {
|
|||
|
||||
struct Note note;
|
||||
|
||||
|
||||
/*
|
||||
CallSequence()
|
||||
make a little sound sequence
|
||||
*/
|
||||
void CallSequence()
|
||||
void CallSequence(timer_t **timer)
|
||||
{
|
||||
static int seq_length = 0;
|
||||
static int seq_note = -1;
|
||||
|
||||
if(seq_length<=0)
|
||||
{
|
||||
seq_note++;
|
||||
|
@ -34,28 +34,47 @@ void CallSequence()
|
|||
{
|
||||
seq_length = 0;
|
||||
seq_note = -1;
|
||||
timer_stop(TIMER_USER);
|
||||
timer_stop(timer);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t constant = clock_setting(note.wave.length * seq[seq_note].freq, clock_Hz);
|
||||
*timer = htimer_setup(timer_user, constant, timer_Po_4, 0);
|
||||
timer_attach(*timer, CallSequence, NULL);
|
||||
timer_start(*timer);
|
||||
|
||||
// update of the number of turn
|
||||
seq_length = note.wave.length * seq[seq_note].freq * seq[seq_note].length_ms / 1000;
|
||||
|
||||
// start or reload the timer
|
||||
timer_start(TIMER_USER, note.wave.length * seq[seq_note].freq, Clock_Hz, CallSequence, 0);
|
||||
}
|
||||
|
||||
PlayNote();
|
||||
seq_length--;
|
||||
}
|
||||
|
||||
void Sequence()
|
||||
{
|
||||
timer_t *timer = NULL;
|
||||
CallSequence(&timer);
|
||||
}
|
||||
|
||||
/*
|
||||
CallNote();
|
||||
Create a single sound
|
||||
*/
|
||||
void CallNote()
|
||||
void CallNote(timer_t **timer)
|
||||
{
|
||||
timer_start(TIMER_USER, note.freq * note.wave.length, Clock_Hz, PlayNote, note.wave.length * note.freq * note.duration / 1000);
|
||||
///timer_t *timer = NULL;
|
||||
|
||||
*timer = htimer_setup(timer_user, clock_setting(note.freq * note.wave.length, clock_Hz), timer_Po_4, 2*note.freq * note.wave.length);
|
||||
timer_attach(*timer, PlayNote, timer);
|
||||
timer_start(*timer);
|
||||
// timer_start(TIMER_USER, note.freq * note.wave.length, Clock_Hz, PlayNote, note.wave.length * note.freq * note.duration / 1000);
|
||||
}
|
||||
|
||||
void Note()
|
||||
{
|
||||
timer_t *timer = NULL;
|
||||
CallNote(&timer);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -64,12 +83,12 @@ void CallNote()
|
|||
*/
|
||||
void StopTimer()
|
||||
{
|
||||
timer_stop(TIMER_USER);
|
||||
//timer_stop(timer);
|
||||
}
|
||||
|
||||
/*
|
||||
PlayNote()
|
||||
allow to make different waveforms with '-' and '_'
|
||||
allow to make different waveforms with bits
|
||||
*/
|
||||
void PlayNote()
|
||||
{
|
||||
|
@ -77,7 +96,7 @@ void PlayNote()
|
|||
|
||||
PutPinState((note.wave.signal >> x) & 0x01);
|
||||
x = x + 1;
|
||||
if(x>=note.wave.length)
|
||||
if(x >= note.wave.length)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
|
@ -92,6 +111,8 @@ void PlayNote()
|
|||
state 1 : xxxx.x1xx
|
||||
|
||||
We can put 2 other state but the sound volume is too high
|
||||
We could reduce the sound volumle but we have to send
|
||||
a lot of bits to the port in order to reduce the volume. (Poupe solution)
|
||||
|
||||
SH3 :
|
||||
state 0 : xxxx.xxx0
|
||||
|
@ -107,7 +128,7 @@ void PutPinState(char level)
|
|||
}
|
||||
else
|
||||
{
|
||||
*(volatile unsigned char*)SH7305_PJDR = (*(volatile unsigned char*)SH7305_PJDR & 0xF3) | (0x2 << level);
|
||||
*(volatile unsigned char*)SH7305_PJDR = (*(volatile unsigned char*)SH7305_PJDR & 0xFB) | (level << 0x2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue