using two files at once

do any of the sd card library's allow you to open two or more files? and let you grab the data from each one at pretty much the same time

like

file1 = new file("blah0.txt");
file2 = new file("blah1.txt");

file1.getByte();
file2.getByte();
file1.getByte();
file2.getByte();
file1.getByte();

any help would be much appreciated :slight_smile:

Several SD libraries allow multiple open files. The number of files open in SdFat is only limited by SRAM.

You can interleave I/O to open files but performance may suffer since there is only one 512 byte buffer for an SD block.

If you read one byte from the first file then write a byte to a second file 1536 bytes of I/O are required. 512 to read a block from the first file then 512 bytes to read the block from the second file followed by 512 bytes to write the updated block to the second file.

Programs that read and write larger chunks of data work well.

The Arduino SD.h wrapper for SdFat only allows one open file.

thanks for the reply

i will only need to read data, i need this for a dual sample audio board that will be able to play two samples at once, the mp3 decoders can be sent 32bytes at a time so i could read each file in 32byte chunks.

can i use any sd card arduino shield with this library? (for quick development)

do you have a link to it?

thanks

You will never get the latency/bandwidth for good audio if you read small, 32 byte, chunks from two files. Arduinos with 2K of SRAM can read and play one audio file but two files would require more than 2K of buffer.

The big problem is that SD cards were designed to transfer a single stream to/from a contiguous region of the card. When you switch between two areas there can be big latency problems. This latency is not acceptable for audio.

I have written two audio libraries for the Arduino and it is a challenge to just play/record one file without overruns due to latency problems. My libraries record/play uncompressed wave files so they have higher bandwidth requirements than mp3.

You can use any SD shield with SdFat. For quick development, shields from Adafruit or SparkFun would work.

SdFat is here: Google Code Archive - Long-term storage for Google Code Project Hosting.

would i be better off storing my audio (only small samples prob no more then 2megs worth) on some sort of eeprom/dataflash and using this storage to stream my data?

or maybe still use the sd card but use some external ram for buffering?

i forgot to add this project is for a slot machine were the samples will be very low quality maybe 22k or some thing im not trying to stream 320k mp3s or any thing!

i also haven't bought the arduino im going to prototype this on yet. im guessing a ATmega2560 with 8k of sram would give me the buffering i need?

:slight_smile:

I would try dataflash. I have played with dataflash but don't have much experience so get more opinions.

Hi,
I have tried out using multiple array of files in SD card.
I have posted the code in the below link, hope helps you.
http://arduino.cc/forum/index.php/topic,54014.0.html

Regards,
Bala
Tenet Technetronics