Pages: [1]   Go Down
Author Topic: using two files at once  (Read 2610 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley
Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1631
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1631
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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: http://code.google.com/p/sdfatlib/
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

smiley
« Last Edit: February 04, 2011, 04:18:25 pm by russdx » Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1631
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 29
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: