You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.5KB

  1. #include <SD.h>
  2. #include <SPI.h>
  3. File root;
  4. // change this to match your SD shield or module;
  5. // Arduino Ethernet shield: pin 4
  6. // Adafruit SD shields and modules: pin 10
  7. // Sparkfun SD shield: pin 8
  8. // Teensy 2.0: pin 0
  9. // Teensy++ 2.0: pin 20
  10. const int chipSelect = 10;
  11. void setup()
  12. {
  13. // Open serial communications and wait for port to open:
  14. Serial.begin(9600);
  15. while (!Serial) {
  16. ; // wait for serial port to connect. Needed for Leonardo only
  17. }
  18. SPI.setMOSI(7);
  19. Serial.print("Initializing SD card...");
  20. // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  21. // Note that even if it's not used as the CS pin, the hardware SS pin
  22. // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  23. // or the SD library functions will not work.
  24. pinMode(10, OUTPUT);
  25. if (!SD.begin(chipSelect)) {
  26. Serial.println("initialization failed!");
  27. return;
  28. }
  29. Serial.println("initialization done.");
  30. root = SD.open("/");
  31. printDirectory(root, 0);
  32. Serial.println("done!");
  33. pinMode(2, OUTPUT);
  34. File f1 = SD.open("01_16S.WAV");
  35. File f2 = SD.open("01_16M.WAV");
  36. if (f1 && f2) {
  37. Serial.println("reading file");
  38. char buffer[512];
  39. int n, sum1=0, sum2=0;
  40. elapsedMillis ms;
  41. //while(f2.available()) {
  42. //f1.read(buffer, 44);
  43. //f2.read(buffer, 44);
  44. int size = 512;
  45. while (1) {
  46. digitalWriteFast(2, HIGH);
  47. n = f1.read(buffer, size);
  48. sum1 += n;
  49. digitalWriteFast(2, LOW);
  50. n = f2.read(buffer, size);
  51. sum2 += n;
  52. if (n < size || sum1 > 2000000) break;
  53. }
  54. float sec = (float)ms / 1000.0;
  55. Serial.print("seconds = ");
  56. Serial.println(sec);
  57. Serial.print("bytes per second = ");
  58. Serial.println((float)sum1 / sec);
  59. Serial.print("bytes per second = ");
  60. Serial.println((float)sum2 / sec);
  61. }
  62. }
  63. void loop()
  64. {
  65. // nothing happens after setup finishes.
  66. }
  67. void printDirectory(File dir, int numTabs) {
  68. while(true) {
  69. File entry = dir.openNextFile();
  70. if (! entry) {
  71. // no more files
  72. //Serial.println("**nomorefiles**");
  73. break;
  74. }
  75. for (uint8_t i=0; i<numTabs; i++) {
  76. Serial.print('\t');
  77. }
  78. Serial.print(entry.name());
  79. if (entry.isDirectory()) {
  80. Serial.println("/");
  81. //printDirectory(entry, numTabs+1);
  82. } else {
  83. // files have sizes, directories do not
  84. Serial.print("\t\t");
  85. Serial.println(entry.size(), DEC);
  86. }
  87. entry.close();
  88. }
  89. }