I'm building an audio project that has like one or two thousand RAW mono audio samples, each a second, max 5 seconds.
I just want to store all the filenames in an array on startup but with 1300 files that takes about a minute and half! That can't be right, right??
Also, it starts of kind of fast (still superslow if you ask me) but gets slower as the list grows longer.
Surely this cannot be a daunting task for the Teensy 4.0?
I just want to store all the filenames in an array on startup but with 1300 files that takes about a minute and half! That can't be right, right??
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioPlaySdRaw playRaw1;
// Use one of these 3 output types: Digital I2S, Digital S/PDIF, or Analog DAC
AudioOutputI2S audioOutput;
AudioConnection patchCord1(playRaw1, 0, audioOutput, 0);
AudioConnection patchCord2(playRaw1, 0, audioOutput, 1);
AudioControlSGTL5000 sgtl5000_1;
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
char *samples[2000];
File fileRoot;
int fileCount;
void setup() {
Serial.begin(9600);
AudioMemory(8);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
if (!(SD.begin(SDCARD_CS_PIN))) {
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
fileRoot = SD.open("/SAMPLES");
int startS = millis() / 1000;
Serial.print(millis());
readDB(fileRoot);
int endS = millis() / 1000;
Serial.print("files stored in array: ");
Serial.println(fileCount, DEC);
Serial.print("Took: ");
Serial.println(endS-startS, DEC);
}
void readDB(File dir) {
// int i = 0;
while(true) {
File entry = dir.openNextFile();
if (!entry) {
// no more files
break;
}
fileCount ++;
// i++;
Serial.println(fileCount, DEC);
entry.close();
}
}
void loop() {
}
Also, it starts of kind of fast (still superslow if you ask me) but gets slower as the list grows longer.
Surely this cannot be a daunting task for the Teensy 4.0?