I'm using the Arduino simple audio player with a MKRZERO to play audio files https://docs.arduino.cc/tutorials/generic/simple-audio-player.
The electronics of the player are working (with the mod that capacitor between pin 1 and 8 of the LM386 were removed to reduce the amplifier gain to 20). The micro SD card is a SanDisk Ultra Plus 32GB.
I find that the player only plays one of my audio files. I'm stripping sound from iPhone video to 8 bit PCM files. MediaInfoOnline indicates that the working and nonworking files all have the same properties. See below.
Output from the code indicates that the file thunder.wav is found and it is played correctly. geesemono.wav is not found in the call SD.exists and does not play. Trying to use SD to check the card results in a message to format the card (which is already was) and even after reformating continues to give an error message.
/*
Simple Audio Player for Arduino Zero
Demonstrates the use of the Audio library for the Arduino Zero
Hardware required :
* Arduino shield with a SD card on CS4
* A sound file named "test.wav" in the root directory of the SD card
* An audio amplifier to connect to the DAC0 and ground
* A speaker to connect to the audio amplifier
Arturo Guadalupi <a.guadalupi@arduino.cc>
Angelo Scialabba <a.scialabba@arduino.cc>
Claudio Indellicati <c.indellicati@arduino.cc>
This example code is in the public domain
http://arduino.cc/en/Tutorial/SimpleAudioPlayerZero
*/
#include <SD.h>
#include <SPI.h>
#include <AudioZero.h>
const int chipSelect = SDCARD_SS_PIN;
int iCount = 0;
Sd2Card card;
SdVolume volume;
SdFile root;
void setup() {
delay(3000);
Serial.println("Starting Setup");
// debug output at 115200 baud
Serial.begin(9600);
// setup SD-card
while (!Serial) {
;
}
Serial.println("Initializing SD card...");
//
if (!SD.begin(chipSelect)) {
Serial.println("1 failed!");
while (true);
}
AudioZero.begin(44100);
}
void loop() {
Serial.println("loop starts");
playFile("thunder.wav");
//playFile("geesemono.wav");
}
void playFile(char fileName[]) {
long lExists = SD.exists(fileName);
Serial.print("file exists: ");
Serial.println(lExists);
File soundFile = SD.open(fileName);
Serial.print("SoundFile check: ");
Serial.println(soundFile);
if (!soundFile) {
// if the file didn't open, print an error and stop
Serial.print("error opening ");
Serial.println(fileName);
while (true);
} else {
Serial.print("Playing ");
Serial.print(fileName);
AudioZero.play(soundFile);
Serial.println("End of file. Thank you for listening!");
Serial.println("Count");
Serial.println(iCount);
}
iCount = iCount + 1;
}
output for thunder.wav:
Starting Setup
Initializing SD card...
loop starts
file exists: 1
SoundFile check: 1
Playing thunder.wavEnd of file. Thank you for listening!
Count
0
output for geesemono.wav
Starting Setup
Initializing SD card...
loop starts
file exists: 0
SoundFile check: 0
error opening geesemono.wav
MediaInfo report of "thunder.wav" :
General
Complete name : thunder.wav
Format : Wave
Format settings : PcmWaveformat
File size : 1.30 MiB
Duration : 30 s 835 ms
Overall bit rate mode : Constant
Overall bit rate : 353 kb/s
Track name : thunder
Performer : VideoProc Converter
Director : VideoProc Converter
Genre : Music
Writing application : Lavf58.29.100 (libsndfile-1.0.31)
Comment : thunder
Software : Lavf58.29.100
Audio
Format : PCM
Format settings : Unsigned
Codec ID : 1
Duration : 30 s 835 ms
Bit rate mode : Constant
Bit rate : 352.8 kb/s
Channel(s) : 1 channel
Sampling rate : 44.1 kHz
Bit depth : 8 bits
Stream size : 1.30 MiB (100%)
MediaInfo report of "geesemono.wav" :
General
Complete name : geesemono.wav
Format : Wave
Format settings : PcmWaveformat
File size : 247 KiB
Duration : 5 s 734 ms
Overall bit rate mode : Constant
Overall bit rate : 353 kb/s
Track name : geese
Performer : VideoProc Converter
Director : VideoProc Converter
Genre : Music
Writing application : Lavf58.29.100 (libsndfile-1.0.31)
Comment : geese
Software : Lavf58.29.100
Audio
Format : PCM
Format settings : Unsigned
Codec ID : 1
Duration : 5 s 734 ms
Bit rate mode : Constant
Bit rate : 352.8 kb/s
Channel(s) : 1 channel
Sampling rate : 44.1 kHz
Bit depth : 8 bits
Stream size : 247 KiB (100%)