Wrapper class for wav_player.
playSound.cpp@0:d20271759ae8, 2016-04-09 (annotated)
- Committer:
- lennonjoseph
- Date:
- Sat Apr 09 06:51:24 2016 +0000
- Revision:
- 0:d20271759ae8
Transferring for use in Agar
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lennonjoseph | 0:d20271759ae8 | 1 | #include "playSound.h" |
lennonjoseph | 0:d20271759ae8 | 2 | #include "uLCD_4DGL.h" |
lennonjoseph | 0:d20271759ae8 | 3 | #include "SDFileSystem.h" |
lennonjoseph | 0:d20271759ae8 | 4 | #include "wave_player.h" |
lennonjoseph | 0:d20271759ae8 | 5 | |
lennonjoseph | 0:d20271759ae8 | 6 | extern uLCD_4DGL uLCD; |
lennonjoseph | 0:d20271759ae8 | 7 | extern wave_player player; |
lennonjoseph | 0:d20271759ae8 | 8 | |
lennonjoseph | 0:d20271759ae8 | 9 | // Given the filename of a .wav file in the SD card, play the file over the speaker. |
lennonjoseph | 0:d20271759ae8 | 10 | void playSound(char * wav) |
lennonjoseph | 0:d20271759ae8 | 11 | { |
lennonjoseph | 0:d20271759ae8 | 12 | // open wav file |
lennonjoseph | 0:d20271759ae8 | 13 | FILE *wave_file; |
lennonjoseph | 0:d20271759ae8 | 14 | wave_file=fopen(wav,"r"); |
lennonjoseph | 0:d20271759ae8 | 15 | |
lennonjoseph | 0:d20271759ae8 | 16 | if(wave_file == NULL){ |
lennonjoseph | 0:d20271759ae8 | 17 | uLCD.locate(0,4); |
lennonjoseph | 0:d20271759ae8 | 18 | uLCD.printf("Error in SD"); |
lennonjoseph | 0:d20271759ae8 | 19 | return; |
lennonjoseph | 0:d20271759ae8 | 20 | } |
lennonjoseph | 0:d20271759ae8 | 21 | // play wav file |
lennonjoseph | 0:d20271759ae8 | 22 | player.play(wave_file); |
lennonjoseph | 0:d20271759ae8 | 23 | |
lennonjoseph | 0:d20271759ae8 | 24 | // close wav file |
lennonjoseph | 0:d20271759ae8 | 25 | fclose(wave_file); |
lennonjoseph | 0:d20271759ae8 | 26 | } |