To improve preformance in reading a file I have decided that it would be better to use the Sd2card libary which is part of sdfatlib and for some reason doing
myfile.readStart(bgnBlock)
myfile.readData(bufferOne))
both return zero However
file.contiguousRange(&bgnBlock, &endBlock)
returns One after I defragmented my sdcard but before I defragmented it the function returned zero.
Here is my code:
#include <SdFat.h>
#include <Sd2Card.h>
#include <SdBaseFile.h>
#include <SdFatUtil.h>
const int chipSelect = 10;
#define buffer_size 512
uint8_t bufferOne[buffer_size];
uint8_t bufferTwo[buffer_size];
SdFat sd;
Sd2Card myfile;
SdFile file;
unsigned long audio_size_full;
void setup()
{
Serial.begin(115200);
pinMode(TIMER_PIN, OUTPUT );
SAMPLE_RATE=44100;
// pinMode(13, OUTPUT); //turn on led pin to see voltage
// digitalWrite(13, HIGH);
PgmPrint("FreeRam: ");
Serial.println(FreeRam());
if (!sd.init(SPI_FULL_SPEED, chipSelect)) sd.initErrorHalt();
file.open("axelf.snd",O_READ);
Serial.println(file.contiguousRange(&bgnBlock, &endBlock));
audio_size_full=file.fileSize();
//Serial.print("staring play back\nFilesize=");
PgmPrint("starting play back\nFilersize=");
Serial.println(audio_size_full);
// file.rewind();
//read the first buffer
//Serial.println(myfile.read(bufferOne,buffer_size));
//get block range
//file.close();
Serial.println(myfile.readStart(bgnBlock));
Serial.println(myfile.readData(bufferOne));
startPlayback();
// Serial.println("started");
PgmPrintln("started");
I do not understand why it is not working.