Painful n00b question w/ Teensy Audio Shield/microSD player

Status
Not open for further replies.

nhla

New member
Gratitude in advance for anyone willing to walk me through this. I do art conservation and we were brought a sculpture that has an audio component comprised of a Teensy 3.2 board connected with the Teensy Audio Shield with a MicroSD card reader. It's then routed to a MAX98306 amplifier that routes the signal via speaker wire to a speaker. The goal is to get an audio file to play from the microSD card via the speakers. I believe the issue here is with the code, which is not my strength. Everything appears to be connected and routed properly, as far as I can tell.

-The audio is a .wav file that's approximately 15 minutes long with a file size of approximately 40 mb. The audio file is 16 bit with a sample rate of 22 khz. It's low quality audio of people speaking.

-I've tried to load the code for the WavPlayer from Teensyduino and cannot get it to work. I've tried a couple variations, copied the code below, which was my last attempt.

While I have experience with audio equipment, I've not used Arduino before and this is a heck of a way to dive in. I've watched the Teensy Audio Tutorial & Workshop and still can't get this figured out, thus my appealing to those that may know better.

Any help at all would be much appreciated, especially someone who could walk me through this like the dummy that I apparently am. Thanks again for reading this.

Code:
// Simple WAV file player example
//
// Three types of output may be used, by configuring the code below.
//
//   1: Digital I2S - Normally used with the audio shield:
//         http://www.pjrc.com/store/teensy3_audio.html
//
//   2: Digital S/PDIF - Connect pin 22 to a S/PDIF transmitter
//         https://www.oshpark.com/shared_projects/KcDBKHta
//
//   3: Analog DAC - Connect the DAC pin to an amplified speaker
//         http://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog
//
// To configure the output type, first uncomment one of the three
// output objects.  If not using the audio shield, comment out
// the sgtl5000_1 lines in setup(), so it does not wait forever
// trying to configure the SGTL5000 codec chip.
//
// The SD card may connect to different pins, depending on the
// hardware you are using.  Uncomment or configure the SD card
// pins to match your hardware.
//
// Data 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>

AudioPlaySdWav           playWav1;
// Use one of these 3 output types: Digital I2S, Digital S/PDIF, or Analog DAC
/\






AudioOutputI2S           audioOutput;
//AudioOutputSPDIF       audioOutput;
AudioOutputAnalog      audioOutput;
AudioConnection          patchCord1(playWav1, 0, audioOutput, 0);
AudioConnection          patchCord2(playWav1, 1, audioOutput, 1);
AudioControlSGTL5000     sgtl5000_1;

// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

// Use these with the Teensy 3.5 & 3.6 SD card
//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13

void setup() {
  Serial.begin(9600);

  // Audio connections require memory to work.  For more
  // detailed information, see the MemoryAndCpuUsage example
  AudioMemory(8);

  // Comment these out if not using the audio adaptor board.
  // This may wait forever if the SDA & SCL pins lack
  // pullup resistors
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);

  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()) {
    // uncomment these lines if you audio shield
    // has the optional volume pot soldered
    //float vol = analogRead(15);
    //vol = vol / 1024;
    // sgtl5000_1.volume(vol);
  }
}


void loop() {
  playFile("CS.WAV");  // filenames are always uppercase 8.3 format
  delay(500);
 // playFile("SDTEST2.WAV");
 // delay(500);
 // playFile("SDTEST3.WAV");
 // delay(500);
 // playFile("SDTEST4.WAV");
 // delay(1500);
}

IMG_6183.jpgIMG_6184.jpgIMG_6185.jpg
 
-The audio is a .wav file that's approximately 15 minutes long with a file size of approximately 40 mb. The audio file is 16 bit with a sample rate of 22 khz. It's low quality audio of people speaking.

-I've tried to load the code for the WavPlayer from Teensyduino and cannot get it to work. I've tried a couple variations, copied the code below, which was my last attempt.

First,
the audio library expects files with a sampling rate of 44.1 kHz
Second,
what do you mean exactly with "cannot get it to work"?

It does not compile?
it does not upload?
it does not start?
program crashes?
no sound?
sound is too fast?
sound is very noisy?
sound is intermittent?
etc.

Finally, where did you get your Teensy from?
Which Arduino/Teensyduino are you using?
 
That looks like a Purple OSH Teensy 3.2.

Settig up the SD card with the Audio sample of the provided known to work WAV sample files will show if all is well.
 
Some simple things come to mind in terms of debugging it. Note, I am a software guy, not one who does a lot of processing with the audio shield (I tend to prefer the prop shield to play simple sounds):

  • You only have one speaker hooked up. Maybe the wave file is mono, but for the left side instead of the right side, so try both sides;
  • Try using the headphone jack instead of your amp and speakers to make sure the audio shield is playing the sound;
  • I see you are using a SanDisk 32GB SD card. Perhaps there is an incompatibility with this particular card and the auto adapter. Perhaps you formatted for a filesystem other than FAT-32 (or VFAT). Try a different card if you have one.
  • Try one of the other tests that don't rely on having a SD card like ToneSweep (but note ToneSweep is mono, so be sure to hook up the correct speaker).
 
Thanks to everyone that took time to reply to this. I've got it up and running. I ran ToneSweep and it worked, ran SDCardTest and that worked, then uploaded WavFilePlayer again and voila! Not sure what I did differently today, but I'm good. Thanks again!
 
Status
Not open for further replies.
Back
Top