PDA

View Full Version : I just can't get my files to play (Teensy 3.2 and audio board)



dBcap
01-26-2016, 01:21 PM
Hello!

I want to build a simple wav player. I have 5 different audio clips and I want them to have seperate outputs iwth a button connected to each "channel" to make the audio play. I have 3 sets of Teensy 3.2 + audio shield to give each set 2 channels, except for one, but i wanted to start by just getting my files to paly. I started of by trying the different examples in the audio library (WavFilePlayer, PlayingMusic) but I couldn't get any of my files to play. They're all the right format, 44.1khz 16bit mono wav files. The frustrating part is that the files used in the examples are playing fine with the exact same setup. So what could be wrong? I don't know how to troubble shoot this since there's nothing going wrong with the example files. It seems to me like there still is something to be done with the files but I sent my code and the file to one of the developers (PaulStoffregen) and it worked just fine for him. Am I missing a step? I've red someting abut RAW files and translating it to "numeric" but haven't relly gasped what it's all about.

This really stresses me out since it need to be done until later this week for a art project and I have no idea what to do.

Code I'm using


// 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 audio adaptor board
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14

// 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("CROSSREF.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); */
}


Audio file and the hardware:

fms1961
01-26-2016, 03:14 PM
Your sketch works fine, your .WAV file is corrupt. Download a tool like Audacity (http://audacityteam.org/), this will load your .wav file. The export it from Audacity again as .wav file - and all should work. Worked on my test directly.

dBcap
01-26-2016, 04:00 PM
How do you mean corrupt? Because that's exactly what I've done. Several times. And as I said in the post above, I sent the file to one of the developers and it worked for him. Now I've also tried the wav2sketch tool but it doesn't work either. I just can't figure out what the problem is.

fms1961
01-26-2016, 04:06 PM
If the sample files will be played but your own file not, the reason must be a problem with the file. Do you use the same SD card? Is it well formatted (FAT32)? Is there no typo in the file name? Just rename the file completely and test again (after adapting the sketch) - I had the case that a special character was in the filename which stayed hidden ... it has to be something like this.

With "corrupt" I meant the file structure may have not the format the Audio Library expects, that's why I rewrote it in the first place.

PaulStoffregen
01-26-2016, 04:30 PM
This is the same one I looked at recently, on the big audio thread, right?


I just can't figure out what the problem is.

Nobody will ever figure out what the problem is if you keep insisting you've tried things correctly and they just don't work.

Somewhere, somehow, you're doing something we can't see and can't anticipate. It's probably something simple, some little misunderstanding. When we finally do figure out where this has gone so wrong, I'll probably revise the docs or code or examples.

But until then, we're all in the dark here.... and that's because you keep saying you're doing things right, but we can't see what you're actually doing and you're not showing us what you're actually doing. You're just telling us you did it.

Can you see how impossible it is for any of us to see where this is going so wrong for you?

dBcap
01-26-2016, 04:31 PM
Yes, it's all on the same SD, and I have tried different SD-cards aswel. (They're in FAT32) I agree on the fact that is seems like the files are corrupt but when it worked for Paul I just can't get it together. I will try to switch around with the names.

PaulStoffregen
01-26-2016, 04:34 PM
It's also becoming clear you're randomly trying lots of different things. Stop that right now!

I personally verified that WAV file and code running on a Teensy 3.1 and audio shield right here on my desk. It worked. So please, stop trying wav2sketch and the other stuff. Focus your efforts.

And focus on actually showing us every little detail of EXACTLY what you're doing. There's got to be some little detail, perhaps the SD card, how you're copying the file... something we can't see and can't expect.

PaulStoffregen
01-26-2016, 04:36 PM
Look, I'm just guessing here... can you take the SD card out of Teensy and put it on a *different* computer, not the same machine you already used, but a different machine that's never seen that particular file, and trying playing it from the card with that computer? At least verify the file really is properly on your SD card and can be played by a different PC.

dBcap
01-26-2016, 04:44 PM
Just rename the file completely and test again (after adapting the sketch)

Oh my gosh, thank you! This was it! I just simply renamed the audio files and it worked. I guess since I always had the same name it like had the old files red, or something.

PaulStoffregen
01-26-2016, 04:44 PM
I just verified this WAV file and code *again*. It does work.

I copied the CROSSREF.wav file to a brand new, fresh-out-of-the-package SanDisk Extreme 16GB card, and put the card in the audio shield. Then I uploaded the exact code from message #1. It's playing fine. The sound is a clip about a woman talking about plan your future not waste it, or something along those lines.

This code and WAV file are good. Please, focus on getting these to work. Stop trying other code, other files. These are correct. Whatever isn't working is some minor detail of how you're using them.

dBcap
01-26-2016, 04:49 PM
This is the same one I looked at recently, on the big audio thread, right?



Nobody will ever figure out what the problem is if you keep insisting you've tried things correctly and they just don't work.

Somewhere, somehow, you're doing something we can't see and can't anticipate. It's probably something simple, some little misunderstanding. When we finally do figure out where this has gone so wrong, I'll probably revise the docs or code or examples.

But until then, we're all in the dark here.... and that's because you keep saying you're doing things right, but we can't see what you're actually doing and you're not showing us what you're actually doing. You're just telling us you did it.

Can you see how impossible it is for any of us to see where this is going so wrong for you?

Yes, I'm sorry. I'm aware of the fact that my information hasn't been to mutch help. But I've only just gotten in to this and really just tumbeling in the dark. Therefore I really wan't you to know that you guys are great.

PaulStoffregen
01-26-2016, 04:58 PM
Great. Glad this got resolved. :)

PaulStoffregen
01-26-2016, 04:59 PM
Perhaps for the future I'll consider changing the main WAV player example to read the main directory and automatically try to play every file with a .WAV extension. Then if a name doesn't match perfectly or gets truncated to 8.3 format, it'd still play.

fms1961
01-26-2016, 05:09 PM
Oh my gosh, thank you! This was it! I just simply renamed the audio files and it worked.
I was an error which reminds me of this prank:

(don't try this at home!) :cool:
6202

dBcap
01-26-2016, 08:34 PM
SO, now that I have this working I can proceed. As I said I want two different channels of output for the setup. I've bought 3.5mm jacks in hope of being able to have multiple (2) channels streaming different audio clips simultaneously. To my knowledge, I2C and SPDIF can "read" audio. Can both of them stream audio from the SD-card at the same time? Or can you somehow split the stereo signal into left and right (mono). Tho, doesn't the I2S have a left and right output? If so, how do I redirect the signals there?

Sorry if you're not able to understand me.
Thanks again

Edit: These are the jacks

Frank B
01-26-2016, 09:46 PM
// Simple TWO 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 <tower.h>

#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

AudioPlaySdWav playWav1;
AudioPlaySdWav playWav2;
// 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(playWav2, 0, audioOutput, 1);
AudioControlSGTL5000 sgtl5000_1;

// Use these with the audio adaptor board
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14

// 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() {
// initTower();
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,const char *filename2)
{
Serial.print("Playing file: ");
Serial.println(filename);
Serial.println(filename2);

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

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

// 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);
}
while (playWav2.isPlaying()) {}

}


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




...you should play with the Audio Design tool, try the examples and try to understand them..

PaulStoffregen
01-27-2016, 12:22 AM
As I said I want two different channels of output for the setup. .... Can both of them stream audio from the SD-card at the same time? Or can you somehow split the stereo signal into left and right (mono). Tho, doesn't the I2S have a left and right output? If so, how do I redirect the signals there?


Please watch the tutorial video!

https://www.youtube.com/watch?v=wqt55OAabVs

If you don't have time for all 48 minutes, perhaps start watching at 9:06, where playing 2 files simultaneously is shown.

If you have a couple hours, even better than watching is actually *doing* the tutorial yourself. :) Almost everyone learns much better by actually doing something, rather than just watching, which is why we went to so much work to write all this. You can get the full instruction manual here. It's easiest if you print this (and it looks awesome when printed in color...) so you can keep your screen available for the Arduino editor window and serial monitor.

https://github.com/PaulStoffregen/AudioWorkshop2015/raw/master/workshop.pdf

All the tutorial examples from this manual and the video are in File > Examples > Audio > Tutorial. If you send the time to go through the tutorial, you'll gain a much better understanding of how to use the design tool and audio library!