
Microprocessor and embedded system Final Project (Music/61) 60010194 Chanathip Pongskul 60010454 Tantep Sinjankhom 60010551 Netiwat Akarachaimongkol
Dependencies: TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG
Diff: main.cpp
- Revision:
- 6:d6d4f48fc2e1
- Parent:
- 5:7db99d28bc36
--- a/main.cpp Sun May 05 02:48:03 2019 +0000 +++ b/main.cpp Mon May 06 07:11:21 2019 +0000 @@ -7,6 +7,7 @@ #include"ophh44.h" #include"kick44.h" + #define sample_freq 16000.0 DigitalOut led(LED1); LCD_DISCO_F746NG lcd; @@ -16,13 +17,14 @@ PwmOut speaker(D1); Serial pc(USBTX, USBRX); Ticker re,er,rr,ee,sn44tick,cl44tick,clhh44tick,ophh44tick,kick44tick,testprint;//timer ไว้ attach ตอนplay audio กับไว้รับปุ่ม +//Timeout re; int checkplay=0,beat[5][8],page=1; int tracking=1; char currentpage[50],volumechar[50],strvolume[50],strtempo[50],tempostr[50]; //สร้างไว้ให้เขียนอักษรได้เฉยๆ float volume,tempo; float speed; //tempo converted to sec -int h,i,j,k,l; +int h,i,j,k,l,m; void test(void); //function for touchscreen void play(void);// function for play void screen(void);//function for display @@ -35,7 +37,7 @@ { lcd.Clear(LCD_COLOR_BLUE); ee.attach(&screen, 0.03); - re.attach(&play,0.5);//เล่นตามtempo + re.attach(&play,0.45);//เล่นตามtempo er.attach(&test, 0.25);//กดช้ากดเร็วแล้วแต่ rr.attach(&knob,0.5);//readknob ทุก0.5 @@ -99,12 +101,22 @@ //led = 0; } } +/*void hand_sample () +{ + speaker = hand_data[m]/16777215.0;//scale to 0.0 to 1.0 for PWM + m++; + if (m>= num_hand) { + m = 0; + handtick.detach(); + //led = 0; + } +}*/ ///////////////////////////////////////////////////////////////////////////// PLAY PART ////////////////////////////////////////////// void playsnare() { speaker = volume*(sn44_data[h]/16777215.0);//scale to 0.0 to 1.0 for PWM h++; - speaker.period(1.0/330750.0); //PWM freq >10X audio sample rate + speaker.period(1.0/88200.0); //PWM freq >10X audio sample rate if (h>= num_sn44) { h = 0; @@ -117,7 +129,7 @@ { speaker = volume*(kick44_data[l]/16777215.0);//scale to 0.0 to 1.0 for PWM l++; - speaker.period(1.0/441000.0); //PWM freq >10X audio sample rate + speaker.period(1.0/88200.0); //PWM freq >10X audio sample rate if (l>= num_kick44) { l = 0; @@ -129,7 +141,7 @@ { speaker = volume*(cl44_data[i]/16777215.0);//scale to 0.0 to 1.0 for PWM i++; - speaker.period(1.0/220500.0); //PWM freq >10X audio sample rate + speaker.period(1.0/96000.0); //PWM freq >10X audio sample rate if (i>= num_cl44) { i = 0; @@ -142,7 +154,7 @@ { speaker = volume*(clhh44_data[j]/16777215.0);//scale to 0.0 to 1.0 for PWM j++; - speaker.period(1.0/330750.0); //PWM freq >10X audio sample rate + speaker.period(1.0/96000.0); //PWM freq >10X audio sample rate if (j>= num_clhh44) { j = 0; @@ -155,7 +167,7 @@ { speaker = volume*(ophh44_data[k]/16777215.0);//scale to 0.0 to 1.0 for PWM k++; - speaker.period(1.0/330750.0); //PWM freq >10X audio sample rate + speaker.period(1.0/96000.0); //PWM freq >10X audio sample rate if (k>= num_ophh44) { k = 0; @@ -163,6 +175,9 @@ } } + + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void play() { @@ -180,12 +195,12 @@ if(beat[0][0]==1) { pc.printf("1"); - kick44tick.attach(&playkick,1.0 / 33075); + kick44tick.attach(&playkick,1.0 / 88200); } if(beat[1][0]==1) { pc.printf("2"); - sn44tick.attach(&playsnare,1.0 / 33075); + sn44tick.attach(&playsnare,1.0 / 88200); } if(beat[2][0]==1) { @@ -214,12 +229,12 @@ if(beat[0][1]==1) { pc.printf("1"); - kick44tick.attach(&playkick,1.0 / 33075); + kick44tick.attach(&playkick,1.0 / 88200); } if(beat[1][1]==1) { pc.printf("2"); - sn44tick.attach(&playsnare,1.0 / 33075); + sn44tick.attach(&playsnare,1.0 / 88200); } if(beat[2][1]==1) { @@ -249,27 +264,27 @@ if(beat[0][2]==1) { pc.printf("1"); - kick44tick.attach(&playkick,1.0 / 33075); + kick44tick.attach(&playkick,1.0 / 88200); } if(beat[1][2]==1) { pc.printf("2"); - sn44tick.attach(&playsnare,1.0 / 33075); + sn44tick.attach(&playsnare,1.0 / 88200); } if(beat[2][2]==1) { pc.printf("3"); - cl44tick.attach(&playclap,1.0 /22050); + cl44tick.attach(&playclap,1.0 /96000); } if(beat[3][2]==1) { pc.printf("4"); - clhh44tick.attach(&playclhh,1.0 / 33075); + clhh44tick.attach(&playclhh,1.0 / 96000); } if(beat[4][2]==1) { pc.printf("5"); - ophh44tick.attach(&playophh,1.0 / 33075); + ophh44tick.attach(&playophh,1.0 / 96000); } @@ -284,27 +299,27 @@ if(beat[0][3]==1) { pc.printf("1"); - kick44tick.attach(&playkick,1.0 / 33075); + kick44tick.attach(&playkick,1.0 / 88200); } if(beat[1][3]==1) { pc.printf("2"); - sn44tick.attach(&playsnare,1.0 / 33075); + sn44tick.attach(&playsnare,1.0 / 88200); } if(beat[2][3]==1) { pc.printf("3"); - cl44tick.attach(&playclap,1.0 /22050); + cl44tick.attach(&playclap,1.0 /96000); } if(beat[3][3]==1) { pc.printf("4"); - clhh44tick.attach(&playclhh,1.0 / 33075); + clhh44tick.attach(&playclhh,1.0 / 96000); } if(beat[4][3]==1) { pc.printf("5"); - ophh44tick.attach(&playophh,1.0 / 33075); + ophh44tick.attach(&playophh,1.0 / 96000); } @@ -319,27 +334,27 @@ if(beat[0][4]==1) { pc.printf("1"); - kick44tick.attach(&playkick,1.0 / 33075); + kick44tick.attach(&playkick,1.0 / 88200); } if(beat[1][4]==1) { pc.printf("2"); - sn44tick.attach(&playsnare,1.0 / 33075); + sn44tick.attach(&playsnare,1.0 / 88200); } if(beat[2][4]==1) { pc.printf("3"); - cl44tick.attach(&playclap,1.0 /22050); + cl44tick.attach(&playclap,1.0 /96000); } if(beat[3][4]==1) { pc.printf("4"); - clhh44tick.attach(&playclhh,1.0 / 33075); + clhh44tick.attach(&playclhh,1.0 / 96000); } if(beat[4][4]==1) { pc.printf("5"); - ophh44tick.attach(&playophh,1.0 / 33075); + ophh44tick.attach(&playophh,1.0 / 96000); } @@ -354,27 +369,27 @@ if(beat[0][5]==1) { pc.printf("1"); - kick44tick.attach(&playkick,1.0 / 33075); + kick44tick.attach(&playkick,1.0 / 88200); } if(beat[1][5]==1) { pc.printf("2"); - sn44tick.attach(&playsnare,1.0 / 33075); + sn44tick.attach(&playsnare,1.0 / 88200); } if(beat[2][5]==1) { pc.printf("3"); - cl44tick.attach(&playclap,1.0 /22050); + cl44tick.attach(&playclap,1.0 /96000); } if(beat[3][5]==1) { pc.printf("4"); - clhh44tick.attach(&playclhh,1.0 / 33075); + clhh44tick.attach(&playclhh,1.0 / 96000); } if(beat[4][5]==1) { pc.printf("5"); - ophh44tick.attach(&playophh,1.0 / 33075); + ophh44tick.attach(&playophh,1.0 / 96000); } @@ -389,27 +404,27 @@ if(beat[0][6]==1) { pc.printf("1"); - kick44tick.attach(&playkick,1.0 / 33075); + kick44tick.attach(&playkick,1.0 / 88200); } if(beat[1][6]==1) { pc.printf("2"); - sn44tick.attach(&playsnare,1.0 / 33075); + sn44tick.attach(&playsnare,1.0 / 88200); } if(beat[2][6]==1) { pc.printf("3"); - cl44tick.attach(&playclap,1.0 /22050); + cl44tick.attach(&playclap,1.0 /96000); } if(beat[3][6]==1) { pc.printf("4"); - clhh44tick.attach(&playclhh,1.0 / 33075); + clhh44tick.attach(&playclhh,1.0 / 96000); } if(beat[4][6]==1) { pc.printf("5"); - ophh44tick.attach(&playophh,1.0 / 33075); + ophh44tick.attach(&playophh,1.0 / 96000); } @@ -424,27 +439,27 @@ if(beat[0][7]==1) { pc.printf("1"); - kick44tick.attach(&playkick,1.0 / 33075); + kick44tick.attach(&playkick,1.0 / 88200); } if(beat[1][7]==1) { pc.printf("2"); - sn44tick.attach(&playsnare,1.0 / 33075); + sn44tick.attach(&playsnare,1.0 / 88200); } if(beat[2][7]==1) { pc.printf("3"); - cl44tick.attach(&playclap,1.0 /22050); + cl44tick.attach(&playclap,1.0 /96000); } if(beat[3][7]==1) { pc.printf("4"); - clhh44tick.attach(&playclhh,1.0 / 33075); + clhh44tick.attach(&playclhh,1.0 / 96000); } if(beat[4][7]==1) { pc.printf("5"); - ophh44tick.attach(&playophh,1.0 / 33075); + ophh44tick.attach(&playophh,1.0 / 96000); } @@ -627,7 +642,7 @@ volume=volumeknob.read();//0to100 tempo=tempoknob.read();//problematic******************************************** - + //volume=1; volume2=volume*100; sprintf(volumechar,"%1.1f",volume2); tempo2=60+(tempo*90);