SD WAV File Playback

There is an example in the Tympan_Library for playing WAV files. Currently, it’s here: Tympan_Library/examples/02-Utility/SDWavPlayer at master · Tympan/Tympan_Library · GitHub

If you’re having problems making this work, you could try the Teensy audio library’s version first. It is called and WavFilePlayer. I’ve adapted it to work with Tympan without using the underlying Tympan SD classes. It’s a great way to test if your setup is working without worrying if the Tympan library is working.

Here’s the adapted sketch:

// Simple WAV file player example from the Teensy audio library
//
// Adapted for Tympan RevD
//
// WAV files to put on your SD card can be downloaded here:
//   http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
//
// This example code is in the public domain.

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Tympan_Library.h>   // added for Tympan

AudioPlaySdWav           playWav1;
AudioOutputI2S           audioOutput;
AudioConnection          patchCord1(playWav1, 0, audioOutput, 0);
AudioConnection          patchCord2(playWav1, 1, audioOutput, 1);
Tympan                   myTympan(TympanRev::D); 

// Use these with the Teensy 3.5 & 3.6 SD card...Works for Tympan RevD
#define SDCARD_CS_PIN    BUILTIN_SDCARD
#define SDCARD_MOSI_PIN  11  // not actually used?
#define SDCARD_SCK_PIN   13  // not actually used?

void setup() {
  // Audio connections require memory to work. 
  AudioMemory(8);

  //enable the flow of audio
  myTympan.enable();  //switched to Tympan

  SPI.setMOSI(SDCARD_MOSI_PIN);  
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here, but print a message repetitively
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
}

void playFile(const char *filename)
{
  Serial.print("Playing file: ");
  Serial.println(filename);

  // Start playing the file.  This sketch continues to
  // run while the file plays.
  playWav1.play(filename);

  // A brief delay for the library read WAV info
  delay(5);

  // Simply wait for the file to finish playing.
  while (playWav1.isPlaying()) {}  //wait while it plays
}


void loop() {
  playFile("SDTEST1.WAV");  // filenames are always uppercase 8.3 format
  delay(500);
}

Finally, you need a WAV files: “SDTEST1.WAV”. It needs to be 44.1 kHz, 16-bit, stereo. You can make your own or get one from: Audio Library, for high quality sound input, processing and output on Teensy 3

If this Teensy WAV player works, but the Tympan_Library SD player doesn’t, we know that we have a Tympan problem! Let me know!

Chip

Hi Chip,
Thank you for sharing I’ll try that now !
Valentin

I Tried the tympan example and it’s playing a buzz in the speaker but it’s not what it should be. If I run the serial monitor it says the wav file is playing.
I also tried the code you sent from teensy and unfortunatly I have a bunch of errors when I try to compile it… The main message is compilation error for teensy 3.6.
Do you have any ideas?

The recording of microphones on the SD card is working well.

I have confirmed that the WAV file playback makes a buzzing sound. Very strange. Totally not correct.

I’m surprised that you couldn’t compile the example that I posted here. That’s unfortunate. But, since I was able to recreate your problem, it’s been confirmed that the buzzing problem is something on our library.

What version of the Arduino IDE are you using? And what version of Teensyduino? (you can find both in the Arduino IDE…under the Help menu choose About Arduino and the spash screen will give both the Arduino version and the Teensyduino version)

Chip

I’ve created a GitHub issue to track this bug.

Wow, I forgot that this forum post was still open. Sorry!

The problem has been solved. More notes were left in the GitHub issue linked above.

Chip