View Full Version : Self-created and PJRC WAV files not working in simple sketch - I'd love to know why!
zurielseven
02-20-2016, 05:06 AM
I just want an exceptionally simple WAV player, however, neither the sample files for the sample wav player nor the file I have created seem to be accessible on any of 3 cards I have purchased, formatted, and swapped out. Can someone do me a huge favor and simply spot-check my code - its late, perhaps I missed something? :confused:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1; //xy=433,239
AudioOutputI2S i2s1; //xy=602,239
AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=421,139
// GUItool: end automatically generated code
int flag;
void setup() {
// put your setup code here, to run once:
flag=0;
AudioMemory(10);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(playSdWav1.isPlaying());
if (flag==0) {
playSdWav1.play("BINARY.WAV");
flag++;
}
}
6419
zurielseven
02-20-2016, 05:30 AM
A few notes on my setup: I'm using a SanDisk Ultra SDHC 8GB card with no other files on it - newly opened 3 hours ago. The Audio adapter and Teensy 3.2 are both new and neatly soldered. I am using the line out instead of the headphone jack as the input to an amplifier which is powering a couple of 5W speakers.
I've successfully run a similar sketch playing audio from the memory to confirm that all of my wiring and output selection is correct and the other file played from memory properly.
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// Create an object to control the audio shield.
//
AudioControlSGTL5000 audioShield;
// GUItool: begin automatically generated code
AudioPlayMemory playMem1; //xy=413,240
AudioOutputI2S i2s1; //xy=602,239
AudioConnection patchCord1(playMem1, 0, i2s1, 0);
AudioConnection patchCord2(playMem1, 0, i2s1, 1);
// GUItool: end automatically generated code
#include "AudioSampleGame.h"
int flag;
void setup() {
// put your setup code here, to run once:
flag=0;
AudioMemory(10);
audioShield.enable();
audioShield.volume(0.5);
audioShield.unmuteLineout();
audioShield.lineOutLevel(29);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(playMem1.isPlaying());
if (playMem1.isPlaying()==false) {
if (flag<30) playMem1.play(AudioSampleGame);
flag++;
}
}
6420
PaulStoffregen
02-20-2016, 06:15 AM
perhaps I missed something?
Yes, you're missing SD.begin(), and also SPI.setMOSI() and SPI.setSCK().
For a working example, look in File > Examples > Audio > WavFilePlayer.
You might also watch the 48 minute tutorial video. Playing wav files is demonstrated. All the code shown in the video is under File > Examples > Audio > Tutorials.
zurielseven
02-20-2016, 07:45 PM
Yes, you're missing SD.begin(), and also SPI.setMOSI() and SPI.setSCK().
For a working example, look in File > Examples > Audio > WavFilePlayer.
You might also watch the 48 minute tutorial video. Playing wav files is demonstrated. All the code shown in the video is under File > Examples > Audio > Tutorials.
Thanks, Paul - setting the SD parameters hit the nail on the head. :-) Thank you for answering my n00b question - I appreciate your genius, your products, and all of the work you do.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.