Lab4
Dependencies: USBHost mbed wave_player_appbd
Fork of AppBoard_Waveplayer by
main.cpp@13:1b26be6d53ad, 2015-03-03 (annotated)
- Committer:
- psahay
- Date:
- Tue Mar 03 19:52:25 2015 +0000
- Revision:
- 13:1b26be6d53ad
- Parent:
- 12:67b9ed2c6e4f
stop added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:0d68fe822228 | 1 | #include "mbed.h" |
samux | 0:0d68fe822228 | 2 | #include "USBHostMSD.h" |
4180_1 | 9:f1aebfbe7e78 | 3 | #include "wave_player.h" |
psahay | 11:84161ded6baf | 4 | #include "rtos.h" |
psahay | 11:84161ded6baf | 5 | |
4180_1 | 9:f1aebfbe7e78 | 6 | //mbed Application board waveplayer demo |
4180_1 | 9:f1aebfbe7e78 | 7 | //Plays the wave file "sample.wav" on the USB flash drive |
4180_1 | 9:f1aebfbe7e78 | 8 | //Outputs to onboard speaker (but at very low volume) |
4180_1 | 9:f1aebfbe7e78 | 9 | //and the Audio Out jack for connection to a set of amplified PC speakers (at higher volume) |
4180_1 | 9:f1aebfbe7e78 | 10 | //Needs a USB flash drive inserted with the wav file on it to run |
samux | 0:0d68fe822228 | 11 | |
4180_1 | 9:f1aebfbe7e78 | 12 | //Analog Out Jack |
4180_1 | 9:f1aebfbe7e78 | 13 | AnalogOut DACout(p18); |
4180_1 | 9:f1aebfbe7e78 | 14 | //On Board Speaker |
4180_1 | 9:f1aebfbe7e78 | 15 | PwmOut PWMout(p26); |
4180_1 | 9:f1aebfbe7e78 | 16 | |
4180_1 | 9:f1aebfbe7e78 | 17 | wave_player waver(&DACout,&PWMout); |
4180_1 | 9:f1aebfbe7e78 | 18 | |
psahay | 11:84161ded6baf | 19 | void playwav(void const *args) |
psahay | 11:84161ded6baf | 20 | { |
psahay | 12:67b9ed2c6e4f | 21 | FILE *wave_file; |
psahay | 11:84161ded6baf | 22 | wave_file=fopen((const char *)args,"r"); |
psahay | 11:84161ded6baf | 23 | waver.play(wave_file); |
psahay | 11:84161ded6baf | 24 | fclose(wave_file); |
psahay | 11:84161ded6baf | 25 | } |
psahay | 11:84161ded6baf | 26 | |
4180_1 | 9:f1aebfbe7e78 | 27 | int main() |
4180_1 | 9:f1aebfbe7e78 | 28 | { |
samux | 0:0d68fe822228 | 29 | USBHostMSD msd("usb"); |
4180_1 | 9:f1aebfbe7e78 | 30 | //setup PWM hardware for a Class D style audio output |
4180_1 | 9:f1aebfbe7e78 | 31 | PWMout.period(1.0/400000.0); |
4180_1 | 9:f1aebfbe7e78 | 32 | printf("\n\n\nHello, wave world!\n"); |
4180_1 | 9:f1aebfbe7e78 | 33 | // wait until connected to a USB device |
4180_1 | 9:f1aebfbe7e78 | 34 | while(!msd.connect()) { |
samux | 0:0d68fe822228 | 35 | Thread::wait(500); |
samux | 0:0d68fe822228 | 36 | } |
4180_1 | 9:f1aebfbe7e78 | 37 | //open wav file and play it |
psahay | 12:67b9ed2c6e4f | 38 | waver.stop = false; |
psahay | 11:84161ded6baf | 39 | Thread thread(playwav,(void *)"/usb/wav3.wav"); |
4180_1 | 9:f1aebfbe7e78 | 40 | //end of program |
psahay | 11:84161ded6baf | 41 | Thread::wait(10); |
psahay | 11:84161ded6baf | 42 | waver.stop = true; |
4180_1 | 9:f1aebfbe7e78 | 43 | while(1) {}; |
samux | 0:0d68fe822228 | 44 | } |