mp3

Revision:
5:ce3a3ce60f30
Parent:
4:5b1bd3cca8dc
Child:
6:a26a42923924
--- a/player.cpp	Mon Dec 11 12:29:47 2017 +0000
+++ b/player.cpp	Tue Dec 12 14:04:24 2017 +0000
@@ -11,6 +11,7 @@
 char green;
 bool startplaysong;
 bool playsong;
+char datainput;
 
 char list[20][50];            //song list
 
@@ -54,6 +55,7 @@
 
 /*  select file by num.  */
 void Player::selectfile(char n){
+
     startplaysong=false;
     playerState =PS_STOP;
     playsong=false;
@@ -68,26 +70,49 @@
     playerState =PS_STOP;
     }
     
-void Player::run(void){
-	if(pc.readable()){
-			
-			char datainput;
-			
+    
+void Player::run(void){	
+			if(datainput=='0'){
+				selectfile(0);
+				playFile(list[green]);
+    			//stop();
+				}
 			if(datainput=='1'){
 				selectfile(1);
-    			stop();
+				playFile(list[green]);
+				//stop();
+				
 				}
 			if(datainput=='2'){
 				selectfile(2);
-    			stop();
+				playFile(list[green]);
+    			//stop();
+				}
+			if(datainput=='3'){
+				selectfile(3);
+				playFile(list[green]);
+    			//stop();
 				}
-	}
+			if(datainput=='4'){
+				selectfile(4);
+				playFile(list[green]);
+    			//stop();
+				}
+			if(datainput=='5'){
+				selectfile(5);
+				playFile(list[green]);
+    			//stop();
+				}
+			else{
+				stop();
+				}
 }
 
 
 
 void Player::read(void){
 	pc.readable();
+	datainput = pc.getc();
 
     }
 
@@ -113,16 +138,26 @@
         printf("Playing %s ...\r\n",file);
         
         /* Main playback loop */
-        while((bytes = fp->read(fileBuf,48000)) > 0) {
-        {
+        while((bytes = fp->read(fileBuf,48000)) > 0) {	
+       {
+            pc.printf("green\n");
+            if(pc.readable()){
+            	break;
+    			//stop();
+    			}
+    		vs1053.setFreq(24000000); 
             bufptr = fileBuf;
             // actual audio data gets sent to VS10xx.
             while(bytes > 0)
             {
-                n = (bytes < 32)?bytes:32; 
+                n = (bytes < 32)?bytes:32; //defalt 32 
                 vs1053.writeData(bufptr,n);
                 bytes -= n;
                 bufptr += n;
+                if(pc.readable()){
+                	break;
+    				//stop();
+    			}
                 
             }
             uint8_t vol = 0x00;//set vlume