Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Front/Front.cpp
- Revision:
- 19:08862f49cd9e
- Parent:
- 18:204cd747b54a
- Child:
- 24:c3bb1b0b2207
--- a/Front/Front.cpp Thu May 21 22:59:59 2020 +0000 +++ b/Front/Front.cpp Fri May 22 20:10:00 2020 +0000 @@ -6,7 +6,7 @@ Envelope envelope; //Sprites----------------------------------------------------------------------- -const int fader[35][5] = { +const int fader[35][5] = { //Fader Sprite { 1,1,1,1,1 }, { 0,0,1,0,0 }, { 0,0,1,0,0 }, @@ -69,7 +69,9 @@ { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, }; //Gloabal Variables -volatile int g_isr_flag; +volatile int g_isr_flag; //used for sound generation +volatile extern int silent_flag; //used for note release + //constructor/destructor Front::Front() @@ -82,41 +84,48 @@ void Front::frontrun(N5110 &lcd, Gamepad &pad, int submenu) { - //printf("G_ISR_FLAG= %d\n",g_isr_flag); - frontsetup(lcd, pad, submenu, true); - menuflag=1; - used=1; - a=17; - d=17; - s=17; - r=17; - out=sound.sound_main(true,submenu,440); + //printf("G_ISR_FLAG= %d\n",g_isr_flag); //DEBUG + frontsetup(lcd, pad, submenu, true); //Initialises front pannel display + menuflag=1; //sets up flags + release_flag=silent_flag=0; + used=1; //initialises vairables + envelope_in=0; + a=d=s=r=17; //starting adsr values (1->35) + noteon=false; + printsliders(lcd,a,d,s,r,1); //prints initialsliders + out=sound.sound_main(true,submenu,440); //initialises external variables out=envelope.env_in(a,d,s,r,out,true); - noteon=false; + out=envelope.release(s,r,out,true); pad.reset_buttons(); - //printf("starting while loop"); - #ifdef CSV - itterator=0; - #endif +#ifdef CSV + itterator=0; //sets itterator for CSV OUTPUT +#endif while (menuflag==1) { - if (noteon==true) { - if (g_isr_flag == 1) { - pad.write_u16(out); - - envelope_in=(sound.sound_main(false,submenu,440)-32767); //value around 0 #ifdef SLOW_TIME - printf("SPEAKER VALUE = %u\n",out); - printf("\nENVELOPE IN = %d\n",envelope_in); + print_SLOWTIME_out(out,noteon,a,d,s,r,release_flag,silent_flag); #endif - //out = envelope_in+32767; //skips envelope - out=(envelope.env_in(a,d,s,r,envelope_in,false)+32767);//value around 32767 - g_isr_flag=0; + if (noteon==true && g_isr_flag == 1) { + pad.write_u16(out); + envelope_in=(sound.sound_main(false,submenu,440)-32767); //value around 0 + if (release_flag==0) { + out=(envelope.env_in(a,d,s,r,envelope_in,false));//value around 32767 + //out=envelope_in+32767; + } else { + out=envelope.release(s,r,envelope_in,false); + if (silent_flag==1) { + release_flag=0; + silent_flag=0; + noteon=false; + out=envelope.env_in(a,d,s,r,out,true); + out=0; + } + } + g_isr_flag=0; #ifdef CSV - printf("%d,%d\n",itterator,out); - itterator++; + printf("%d,%d\n",itterator,out); + itterator++; #endif - } } dir=pad.get_direction(); if (dir!=dir_1) { @@ -168,27 +177,25 @@ } //END if DIR if ( pad.A_pressed()) { //NOTE ON printf("NOTE_ON\n"); - //wait_ms(200); //debounce noteon=true; out=envelope.env_in(a,d,s,r,out,true); } if ( pad.B_pressed()) { //NOTE OFF - printf("NOTE_OFF\n"); - //wait_ms(200); //debounce - noteon=false; - out=envelope.env_in(a,d,s,r,out,true); + //printf("NOTE_OFF (W.release)\n"); + release_flag=1; + envelope_in=envelope.release(s,r,envelope_in,true); + pad.reset_buttons(); } if (pad.start_pressed()) { //go back menu // printf("start pressed\n"); printf("Waveforms Sub selected\n"); //debug noteon=false; - //wait_ms(200); //debounce menuflag=0; //sets flag } dir=dir_1; - sleep(); - }//end while() + sleep(); //puts sleep until ISR wakes up + } } //PRIVATE----------------------------------------------------------------------- @@ -293,4 +300,15 @@ } } return(adsr); -} \ No newline at end of file +} + +#ifdef SLOW_TIME +void Front::print_SLOWTIME_out (uint16_t out, bool noteon, int a, int d, int s, int r, int release_flag, int silent_flag) +{ + //Prints all data required in SLOW_TIME + printf("OUTPUT:%d\n",out); + printf("NOTEON: %d\n",noteon); + printf("A:%d,D:%d,S:%d,R:%d\n",a,d,s,r); + printf("RelFlag=%d, SilFlag=%d\n\n",release_flag,silent_flag); +} +#endif \ No newline at end of file