I’m stuck trying to build an audio player that reads from SD card (INPUT) and plays music onto a speaker (OUTPUT). I am using an UNO, a R2R ladder DAC and some buffers and filter to get the best out of it. The DAC is fed by a shift register - if possible at a speed of 44100 Hz (1 Byte / 22,5 µs).
To make the program run fluently time tInput (from SD) must be less than time tOutput (from shift register).
For the output I’m using an altered shiftOut function that uses portManipulation and arduinos timer0 which is set to the appropriate timing. Outputting one byte takes less than 10 µs with the altered shiftOut this way, so its pretty fast.
For reading the SD card I use SPI and I tried using a simple read command on my SD object to get the byte value that i wanted to shift out.
shift_out(&PORTB, dataPin, clockPin, latchPin, MSBFIRST, audioFile.read());
But it was not fast enough. The song played slower than it should because the reading took too long and elongated the timer ISR, decreasing the output frequency.
Anyone here ever had this problem before? Is there a way to read the SD card faster? (I’m already using SdFat lib, but it’s still not fast enough).
edit: Spend the last couple of hours trying to make it work by reading the bytes from the SD card to a buffer instead of one by one, because I thought having the overhead after every single byte is the reason for the big latency. And I actually successfully have increased the output speed by a large factor doing so, BUT this way the output speed somehow becomes dependent on the size of the buffer and I am not able to adjust to 44.1 kHz precisely enough.