Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Simple Sound Player - coded by Douglas Berdeaux
- WeakNetLabs@Gmail.com
- The WAV files need to be 32kHz (Maximum) and 8 bit. (You can convert mp3s and such using the custom settings module in iTunes or Audacity (both free)).
- Although the SD card is formatted as FAT, the FAT filesystem on the SD Card is accessed like xpath, or UNIX paths. For instance, I had a folder called "sounds" and in "sounds" I had the file "payphone.wav" which I called from the play() method as,
- tmrpcm.play("sounds/payphone.wav");
- Also, A specific naming convention must be used according to the Arduino documentation, as old FAT filesystems did (rememebr the old Windows 95/98 file name tilde-truncation-mangling, like FILE00~1.EXT?): http://arduino.cc/en/Reference/SDCardNotes
- The TMRh20 library is used to play the WAV files, https://github.com/TMRh20/TMRpcm
- The Seeed SD Card Reader was used, (version 3.0): http://www.seeedstudio.com/wiki/SD_Card_Shield_V3.0
- Caveats: I had to programmatically lower the volume, because of slight distortion. Also, I had popping and cracking sounds during playback, to which I had to uncomment the line,
- #define buffSize 128
- in the file, pcmConfig.h which helped dramatically with sound quality.
- */
- #include <SD.h> // preprocessor directives (header files)
- #define SDPIN 10
- #include <TMRpcm.h>
- File myFile; // create objects here from library classes
- TMRpcm tmrpcm;
- char mychar; // for reading input from Serial console
- void setup(){
- Serial.begin(9600);
- tmrpcm.speakerPin = 9; //11 on Mega, 9 on Uno, Nano, etc
- tmrpcm.setVolume(4);
- if (!SD.begin(SDPIN)) {
- Serial.println("initialization failed!");
- return;
- }
- Serial.println("Type 'a' to play a song.");
- }
- void loop(){
- if(Serial.available()){
- mychar = Serial.read();
- if(mychar == 'a'){ //send the letter a over the serial monitor to start playback
- Serial.println("playing wav");
- tmrpcm.play("sounds/payphone.wav");
- }
- }
- }
- void playSound(char *file){
- tmrpcm.play(file);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement