Hi everyone I have a a question about reading very large files, I have a simple bit of code that I modified from one of the SD card examples, it now reads a wave file rather than a text file. the problem is that the files are being read into a buffer which works fine with small files but causes the Teensy to crash once the files are bigger and some of my files are 7 or more MB. is there a way to read the files directly without the use of a buffer and if so could someone point to to a bit of code that would help or give me a good break down of what I need to do as I'm not really a programmer and I'm sort of making it up as I go along.. below is the function Im using right now...
Code:
if (ui.checkForButtonClicked(read_wave_file_SD)) {///
myFile = SD.open("wave.wav");
if (myFile) {
Serial.println(myFile);
// int totalBytes = file.size();
// read from the file until there's nothing else in it:
myFile.seek(22);
myFile.read((char*)&numChannels, 2);
myFile.read((char*)&samplingRate, 4);
// Read bits per sample
myFile.seek(34);
myFile.read((char*)&bitsPerSample, 2);
// Read size of data in bytes
U32 sample_length;
myFile.seek(40);
myFile.read((char*)&sample_length, 4);
// Allocate array to hold all the data as PCM samples
count = sample_length / 2;
sample_data = new PCM16[count];
// // Read PCM data
myFile.read((char*)sample_data, sample_length);
Serial.print("number of channels = ");
Serial.println(numChannels);
Serial.print("sample rate = ");
Serial.println(samplingRate);
Serial.print("bits per sample = ");
Serial.println(bitsPerSample);
Serial.print("size in bytes = ");
Serial.println(sample_length);
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening file");
}