![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
For Nikhil
Dependencies: 4DGL-uLCD-SE EthernetInterface Game_Synchronizer MMA8452 SDFileSystem mbed-rtos mbed wave_player
Fork of 2035_Tanks_Shell by
Sound/playSound.cpp@27:bd55ab4d137c, 2015-10-30 (annotated)
- Committer:
- jford38
- Date:
- Fri Oct 30 11:08:31 2015 +0000
- Revision:
- 27:bd55ab4d137c
Added a folder for sound. Clarified the role of globals.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jford38 | 27:bd55ab4d137c | 1 | #include "playSound.h" |
jford38 | 27:bd55ab4d137c | 2 | #include "uLCD_4DGL.h" |
jford38 | 27:bd55ab4d137c | 3 | #include "SDFileSystem.h" |
jford38 | 27:bd55ab4d137c | 4 | #include "wave_player.h" |
jford38 | 27:bd55ab4d137c | 5 | |
jford38 | 27:bd55ab4d137c | 6 | extern uLCD_4DGL uLCD; |
jford38 | 27:bd55ab4d137c | 7 | extern wave_player player; |
jford38 | 27:bd55ab4d137c | 8 | |
jford38 | 27:bd55ab4d137c | 9 | // Given the filename of a .wav file in the SD card, play the file over the speaker. |
jford38 | 27:bd55ab4d137c | 10 | void playSound(char * wav) |
jford38 | 27:bd55ab4d137c | 11 | { |
jford38 | 27:bd55ab4d137c | 12 | // open wav file |
jford38 | 27:bd55ab4d137c | 13 | FILE *wave_file; |
jford38 | 27:bd55ab4d137c | 14 | wave_file=fopen(wav,"r"); |
jford38 | 27:bd55ab4d137c | 15 | |
jford38 | 27:bd55ab4d137c | 16 | if(wave_file == NULL){ |
jford38 | 27:bd55ab4d137c | 17 | uLCD.locate(0,4); |
jford38 | 27:bd55ab4d137c | 18 | uLCD.printf("Error in SD"); |
jford38 | 27:bd55ab4d137c | 19 | return; |
jford38 | 27:bd55ab4d137c | 20 | } |
jford38 | 27:bd55ab4d137c | 21 | // play wav file |
jford38 | 27:bd55ab4d137c | 22 | player.play(wave_file); |
jford38 | 27:bd55ab4d137c | 23 | |
jford38 | 27:bd55ab4d137c | 24 | // close wav file |
jford38 | 27:bd55ab4d137c | 25 | fclose(wave_file); |
jford38 | 27:bd55ab4d137c | 26 | } |