選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

WavFilePlayerUSB.ino 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <Audio.h>
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. #include <SD.h>
  5. #include <SerialFlash.h>
  6. AudioPlaySdWav playWav1;
  7. AudioOutputUSB audioOutput; // must set Tools > USB Type to Audio
  8. AudioOutputAnalog dac;
  9. AudioConnection patchCord1(playWav1, 0, audioOutput, 0);
  10. AudioConnection patchCord2(playWav1, 1, audioOutput, 1);
  11. AudioConnection patchCord3(playWav1, 0, dac, 0);
  12. // Use these with the audio adaptor board
  13. #define SDCARD_CS_PIN 10
  14. #define SDCARD_MOSI_PIN 7
  15. #define SDCARD_SCK_PIN 14
  16. void setup() {
  17. Serial.begin(9600);
  18. // Audio connections require memory to work. For more
  19. // detailed information, see the MemoryAndCpuUsage example
  20. AudioMemory(20);
  21. SPI.setMOSI(SDCARD_MOSI_PIN);
  22. SPI.setSCK(SDCARD_SCK_PIN);
  23. if (!(SD.begin(SDCARD_CS_PIN))) {
  24. // stop here, but print a message repetitively
  25. while (1) {
  26. Serial.println("Unable to access the SD card");
  27. delay(500);
  28. }
  29. }
  30. }
  31. void playFile(const char *filename)
  32. {
  33. playWav1.play(filename);
  34. // A brief delay for the library read WAV info
  35. delay(5);
  36. // Simply wait for the file to finish playing.
  37. while (playWav1.isPlaying()) {
  38. }
  39. }
  40. void loop() {
  41. playFile("SDTEST1.WAV"); // filenames are always uppercase 8.3 format
  42. delay(500);
  43. playFile("SDTEST2.WAV");
  44. delay(500);
  45. playFile("SDTEST3.WAV");
  46. delay(500);
  47. playFile("SDTEST4.WAV");
  48. delay(1500);
  49. }
  50. // A known problem occurs on Macintosh computers, where the Mac's driver
  51. // does not seem to be able to adapt and transmit horribly distorted
  52. // audio to Teensy after a matter of minutes. An imperfect workaround
  53. // can be enabled by editing usb_audio.cpp. Find and uncomment
  54. // "#define MACOSX_ADAPTIVE_LIMIT". More detailed info is available here:
  55. // https://forum.pjrc.com/threads/34855-Distorted-audio-when-using-USB-input-on-Teensy-3-1?p=110392&viewfull=1#post110392