Hello everyone,
I have an Arduino MKR zero board and I am tyring to play music from SDcard.
So far, I have achived for some of wav file formats such as 08-48KHz and 16-bit.
But some of formats likes 24-bit or 32-bit bit depth, arduino errored me : wave file is invalid!
What is the problem? Code below:
#include <SPI.h>
#include <SD.h>
#include <ArduinoSound.h>
const int chipSelect = SDCARD_SS_PIN;
SDWaveFile waveFile;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
while(!Serial);
Serial.println("I2S music playing example...");
if (!SD.begin(chipSelect)) {
Serial.println("SDcard not started...");
while(1);
}
const char* file_name = "2224LSS.wav";
File finfo = SD.open(file_name);
if (!finfo) {
Serial.println("File cannot open...");
while(1);
}
finfo.close();
waveFile = SDWaveFile(file_name);
// check if the WaveFile is valid
if (!waveFile) {
Serial.println("wave file is invalid!"); //error is here
while (1); // do nothing
}
Serial.print("Sample Rate : ");
Serial.println(waveFile.sampleRate());
Serial.print("Bit Per Sample : ");
Serial.println(waveFile.bitsPerSample());
Serial.print("Channels : ");
Serial.println(waveFile.channels());
Serial.print("Duration : ");
Serial.println(waveFile.duration());
AudioOutI2S.volume(100.0f);
Serial.println("Setup completed...");
}
void loop() {
Serial.println("-------------");
Serial.println("music playing now...");
while(AudioOutI2S.isPlaying());
delay(2000);
AudioOutI2S.play(waveFile);
Serial.println("loop end...");
}