A wave player demo setup for the mbed application board. Reads a wave file from a USB flash drive, and outputs to the onboard speaker (very low volume) and the analog audio out jack that can be connected to a set of PC speakers for more volume. A wave file for the demo is available at http://mbed.org/media/uploads/4180_1/sample.wav. Copy it to the USB drive. See http://mbed.org/users/4180_1/notebook/application-board-waveplayer-demo/ for more details and instructions.

Dependencies:   USBHost mbed wave_player_appbd

Fork of USBHostMSD_HelloWorld by Samuel Mokrani

Files at this revision

API Documentation at this revision

Comitter:
4180_1
Date:
Fri Nov 01 15:30:47 2013 +0000
Parent:
8:758190c6c455
Commit message:
A wave player demo setup for the mbed application board
; Reads a wave file from a USB flash drive, and outputs to the onboard speaker (low volume) and the audio out jack that can be connected to a set of PC speakers.

Changed in this revision

USBHost.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
wave_player_appbd.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 758190c6c455 -r f1aebfbe7e78 USBHost.lib
--- a/USBHost.lib	Thu Mar 14 14:23:42 2013 +0000
+++ b/USBHost.lib	Fri Nov 01 15:30:47 2013 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/mbed_official/code/USBHost/#7671b6a8c363
+https://mbed.org/users/mbed_official/code/USBHost/#37c948cf0dbf
diff -r 758190c6c455 -r f1aebfbe7e78 main.cpp
--- a/main.cpp	Thu Mar 14 14:23:42 2013 +0000
+++ b/main.cpp	Fri Nov 01 15:30:47 2013 +0000
@@ -1,50 +1,34 @@
 #include "mbed.h"
 #include "USBHostMSD.h"
-
-DigitalOut led(LED1);
+#include "wave_player.h"
+//mbed Application board waveplayer demo
+//Plays the wave file "sample.wav" on the USB flash drive
+//Outputs to onboard speaker (but at very low volume)
+//and the Audio Out jack for connection to a set of amplified PC speakers (at higher volume)
+//Needs a USB flash drive inserted with the wav file on it to run
 
-void msd_task(void const *) {
-    
+//Analog Out Jack
+AnalogOut DACout(p18);
+//On Board Speaker
+PwmOut PWMout(p26);
+
+wave_player waver(&DACout,&PWMout);
+
+int main()
+{
     USBHostMSD msd("usb");
-    int i = 0;
-    
-    while(1) {
-        
-        // try to connect a MSD device
-        while(!msd.connect()) {
-            Thread::wait(500);
-        }
-        
-        // in a loop, append a file
-        // if the device is disconnected, we try to connect it again
-        while(1) {
-            
-            // append a file
-            FILE * fp = fopen("/usb/test1.txt", "a");
-        
-            if (fp != NULL) {
-                fprintf(fp, "Hello fun SD Card World: %d!\r\n", i++);
-                printf("Goodbye World!\r\n");
-                fclose(fp);
-            } else {
-                printf("FILE == NULL\r\n");
-            }
-            
-            Thread::wait(500);
-        
-            // if device disconnected, try to connect again
-            if (!msd.connected())
-                break;
-        }
-            
-    }
-}
-
-
-int main() {
-    Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4);
-    while(1) {
-        led=!led;
+    FILE *wave_file;
+    //setup PWM hardware for a Class D style audio output
+    PWMout.period(1.0/400000.0);
+    printf("\n\n\nHello, wave world!\n");
+    // wait until connected to a USB device
+    while(!msd.connect()) {
         Thread::wait(500);
     }
+    //open wav file and play it
+    wave_file=fopen("/usb/sample.wav","r");
+    waver.play(wave_file);
+    fclose(wave_file);
+    //end of program
+    while(1) {};
 }
\ No newline at end of file
diff -r 758190c6c455 -r f1aebfbe7e78 mbed.bld
--- a/mbed.bld	Thu Mar 14 14:23:42 2013 +0000
+++ b/mbed.bld	Fri Nov 01 15:30:47 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/5e5da4a5990b
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/f37f3b9c9f0b
\ No newline at end of file
diff -r 758190c6c455 -r f1aebfbe7e78 wave_player_appbd.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wave_player_appbd.lib	Fri Nov 01 15:30:47 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/4180_1/code/wave_player_appbd/#b1cea7afcfd2