I'm aware the code is awful. This is derived, mostly, from the PlaySdWav example. I have four samples.
If I throttle playback more (increase the delay in the "loop()" function), I get flawless playback of all the samples. You'll note that I have four AudioPlaySdWav devices defined. If I use all four of them (use %4 instead of %2 in the playFile function), I get static much more often, unless I throttle playback.
But I can also make it through several loops through playing all the sound files with no static at all. AudioMemoryUsage was reporting that 0-5 blocks were in use, it seems like 20 should be plenty. The SD card is a SanDisk "ultra".
As an experiment, I also tried with the SDTEST?.WAV files from the audio library documentation. With those, I get static pretty much constantly and right away if I'm trying to use more than one WAV playback. On further study, this looks like it's probably SD card performance. The SD card test says:
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV:
Overall speed = 0.26 Mbyte/sec
Worst block time = 15.16 ms
522.55% of audio frame time
... But I'm going to post this anyway in case I've done something else obviously stupid.
EDIT: After a bit of reading, it looks like I might want flash chips for this. Digikey says the W25Q128FV is "discontinued at digikey". But also, chips like that appear to come in many, many, packages. I am not sure exactly which package I would be looking for. 8-SOIC, 3.9 or 5.3 mm width? The traces are wide enough that those both seem likely to work. It looks like DigiKey no longer has the FV (~3V), only the FW (~1.8V).
If I throttle playback more (increase the delay in the "loop()" function), I get flawless playback of all the samples. You'll note that I have four AudioPlaySdWav devices defined. If I use all four of them (use %4 instead of %2 in the playFile function), I get static much more often, unless I throttle playback.
But I can also make it through several loops through playing all the sound files with no static at all. AudioMemoryUsage was reporting that 0-5 blocks were in use, it seems like 20 should be plenty. The SD card is a SanDisk "ultra".
As an experiment, I also tried with the SDTEST?.WAV files from the audio library documentation. With those, I get static pretty much constantly and right away if I'm trying to use more than one WAV playback. On further study, this looks like it's probably SD card performance. The SD card test says:
Reading SDTEST1.WAV, SDTEST2.WAV, SDTEST3.WAV, SDTEST4.WAV:
Overall speed = 0.26 Mbyte/sec
Worst block time = 15.16 ms
522.55% of audio frame time
... But I'm going to post this anyway in case I've done something else obviously stupid.
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioPlaySdWav playWav1, playWav2, playWav3, playWav4;
AudioMixer4 mixerL;
AudioMixer4 mixerR;
AudioOutputI2S audioOutput;
AudioConnection patchCord1(playWav1, 0, mixerL, 0);
AudioConnection patchCord2(playWav1, 1, mixerR, 0);
AudioConnection patchCord3(playWav2, 0, mixerL, 1);
AudioConnection patchCord4(playWav2, 1, mixerR, 1);
AudioConnection patchCord5(playWav3, 0, mixerL, 2);
AudioConnection patchCord6(playWav3, 1, mixerR, 2);
AudioConnection patchCord7(playWav4, 0, mixerL, 3);
AudioConnection patchCord8(playWav4, 1, mixerR, 3);
AudioConnection patchCordA(mixerL, 0, audioOutput, 0);
AudioConnection patchCordB(mixerR, 0, audioOutput, 1);
AudioControlSGTL5000 sgtl5000_1;
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
void setup() {
Serial.begin(9600);
AudioMemory(16);
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);
}
}
}
int counter = 0;
AudioPlaySdWav *outs[4] = {
&playWav1, &playWav2, &playWav3, &playWav4
};
void playFile(const char *filename)
{
while (outs[counter]->isPlaying()) {
delay(5);
}
outs[counter]->play(filename);
counter = (counter + 1) % 2;
delay(5);
}
int samp = 0;
void loop() {
char name[] = "KEY0.WAV";
name[3] = '1' + samp;
samp = (samp + 1) % 4;
playFile(name);
uint8_t count = (rand() % 20) + 5;
delay (count * 5);
}
EDIT: After a bit of reading, it looks like I might want flash chips for this. Digikey says the W25Q128FV is "discontinued at digikey". But also, chips like that appear to come in many, many, packages. I am not sure exactly which package I would be looking for. 8-SOIC, 3.9 or 5.3 mm width? The traces are wide enough that those both seem likely to work. It looks like DigiKey no longer has the FV (~3V), only the FW (~1.8V).
Last edited: