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
main.cpp
00001 #include "mbed.h" 00002 #include "USBHostMSD.h" 00003 #include "wave_player.h" 00004 //mbed Application board waveplayer demo 00005 //Plays the wave file "sample.wav" on the USB flash drive 00006 //Outputs to onboard speaker (but at very low volume) 00007 //and the Audio Out jack for connection to a set of amplified PC speakers (at higher volume) 00008 //Needs a USB flash drive inserted with the wav file on it to run 00009 00010 //Analog Out Jack 00011 AnalogOut DACout(p18); 00012 //On Board Speaker 00013 PwmOut PWMout(p26); 00014 00015 wave_player waver(&DACout,&PWMout); 00016 00017 int main() 00018 { 00019 USBHostMSD msd("usb"); 00020 FILE *wave_file; 00021 //setup PWM hardware for a Class D style audio output 00022 PWMout.period(1.0/400000.0); 00023 printf("\n\n\nHello, wave world!\n"); 00024 // wait until connected to a USB device 00025 while(!msd.connect()) { 00026 Thread::wait(500); 00027 } 00028 //open wav file and play it 00029 wave_file=fopen("/usb/sample.wav","r"); 00030 waver.play(wave_file); 00031 fclose(wave_file); 00032 //end of program 00033 while(1) {}; 00034 }
Generated on Sat Jul 16 2022 12:52:33 by 1.7.2