wave player pwm & covox

Dependencies:   wave_player_pwm_and_covox mbed USBHost

Revision:
10:c3614ed19126
Parent:
9:d0a3b4c7b261
Child:
11:d2099045bdc9
diff -r d0a3b4c7b261 -r c3614ed19126 main.cpp
--- a/main.cpp	Thu Apr 19 13:31:58 2018 +0000
+++ b/main.cpp	Sat Dec 29 09:48:31 2018 +0000
@@ -1,67 +1,43 @@
 /*
 Big green ugly test. Free for use bla bla bla. Do not eat.
 Tested on stm32f746zg
-Results: 814 KB/s, to slow for my project.
-No have idea how i can increase reading speed up to 4MB/s.
+
+Based on Vladimir Berzin SDFileSystem wave player 
+https://os.mbed.com/users/berzin11295/code/wav_player/
 */
 
 #include "mbed.h"
 #include "USBHostMSD.h"
+#include "wave_player.h"
 
 Serial pc(USBTX, USBRX, 115200); // tx, rx, baud rate to avoid terminal glitches
 
-// read block size
-unsigned int bs = 65536;
-// read memory buffer
-char buff[65536];
-
-// Binary test file, 10MB size
-unsigned long fsize=1024*1024*10;
-// start time, end time, delta time
-unsigned long time1, time2, time3;
-// speed = fsize / time3
-float speed;
-
-
-Timer t;
+AnalogOut dac(PA_5);
+//DigitalOut enb(PA_12);
+wave_player player(&dac);
 
 int main() {
 
-// Mission clock on.
-t.start();
-    
-    USBHostMSD msd("usb");
+USBHostMSD msd("usb");
 
         while(1) {
         while(!msd.connect()) {
             pc.printf("Waiting for USB\r\n");
             wait_ms(500);
         }
+
             pc.printf("Flash mounted\r\n");    
 
-            FILE * fp = fopen("/usb/test1.bin", "rb");
+            FILE * fp = fopen("/usb/test1.wav", "rb");
         
             if (fp != NULL) {
                 pc.printf("File opened, reading...\r\n");
 
-                time1=t.read_ms();
-                pc.printf("Start timer value = %u \r\n",time1);
-
-                    while(!feof(fp))
-                    {
-                        fread(&buff,bs,1,fp);
-                    }
-                
-                time2 = t.read_ms();
-                pc.printf("End timer value = %u\r\n",time2);
+                    player.play(fp);
                
             fclose(fp);
             pc.printf("File closed\r\n");
 
-            time3 = time2 - time1;
-            speed = fsize / time3; 
-
-            pc.printf ("Time to read file %u speed KB/s = %f \r\n======================\r\n", time3, speed);
 
             } else {
                 pc.printf("FILE == NULL\r\n");