PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
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.

138 lines
3.9KB

  1. // Freeverb - High quality reverb effect
  2. //
  3. //
  4. // The SD card may connect to different pins, depending on the
  5. // hardware you are using. Uncomment or configure the SD card
  6. // pins to match your hardware.
  7. //
  8. // Data files to put on your SD card can be downloaded here:
  9. // http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
  10. //
  11. // This example code is in the public domain.
  12. #include <Audio.h>
  13. #include <Wire.h>
  14. #include <SPI.h>
  15. #include <SD.h>
  16. #include <SerialFlash.h>
  17. // GUItool: begin automatically generated code
  18. AudioPlaySdWav playSdWav1; //xy=163,135
  19. AudioMixer4 mixer1; //xy=332,167
  20. AudioEffectFreeverb freeverb1; //xy=497,105
  21. AudioMixer4 mixer2; //xy=650,190
  22. AudioOutputI2S i2s1; //xy=815,198
  23. AudioConnection patchCord1(playSdWav1, 0, mixer1, 0);
  24. AudioConnection patchCord2(playSdWav1, 1, mixer1, 1);
  25. AudioConnection patchCord3(mixer1, freeverb1);
  26. AudioConnection patchCord4(mixer1, 0, mixer2, 1);
  27. AudioConnection patchCord5(freeverb1, 0, mixer2, 0);
  28. AudioConnection patchCord6(mixer2, 0, i2s1, 0);
  29. AudioConnection patchCord7(mixer2, 0, i2s1, 1);
  30. AudioControlSGTL5000 sgtl5000_1; //xy=236,248
  31. // GUItool: end automatically generated code
  32. // Use these with the Teensy Audio Shield
  33. #define SDCARD_CS_PIN 10
  34. #define SDCARD_MOSI_PIN 7
  35. #define SDCARD_SCK_PIN 14
  36. // Use these with the Teensy 3.5 & 3.6 SD card
  37. //#define SDCARD_CS_PIN BUILTIN_SDCARD
  38. //#define SDCARD_MOSI_PIN 11 // not actually used
  39. //#define SDCARD_SCK_PIN 13 // not actually used
  40. // Use these for the SD+Wiz820 or other adaptors
  41. //#define SDCARD_CS_PIN 4
  42. //#define SDCARD_MOSI_PIN 11
  43. //#define SDCARD_SCK_PIN 13
  44. void setup() {
  45. Serial.begin(9600);
  46. // Audio connections require memory to work. For more
  47. // detailed information, see the MemoryAndCpuUsage example
  48. AudioMemory(10);
  49. // Comment these out if not using the audio adaptor board.
  50. // This may wait forever if the SDA & SCL pins lack
  51. // pullup resistors
  52. sgtl5000_1.enable();
  53. sgtl5000_1.volume(0.5);
  54. SPI.setMOSI(SDCARD_MOSI_PIN);
  55. SPI.setSCK(SDCARD_SCK_PIN);
  56. if (!(SD.begin(SDCARD_CS_PIN))) {
  57. // stop here, but print a message repetitively
  58. while (1) {
  59. Serial.println("Unable to access the SD card");
  60. delay(500);
  61. }
  62. }
  63. mixer1.gain(0, 0.5);
  64. mixer1.gain(1, 0.5);
  65. mixer2.gain(0, 0.9); // hear 90% "wet"
  66. mixer2.gain(1, 0.1); // and 10% "dry"
  67. }
  68. void playFile(const char *filename)
  69. {
  70. Serial.print("Playing file: ");
  71. Serial.println(filename);
  72. // Start playing the file. This sketch continues to
  73. // run while the file plays.
  74. playSdWav1.play(filename);
  75. // A brief delay for the library read WAV info
  76. delay(5);
  77. elapsedMillis msec;
  78. // Simply wait for the file to finish playing.
  79. while (playSdWav1.isPlaying()) {
  80. // while the music plays, adjust parameters and print info
  81. if (msec > 250) {
  82. msec = 0;
  83. float knob_A1 = 0.9;
  84. float knob_A2 = 0.5;
  85. float knob_A3 = 0.5;
  86. // Uncomment these lines to adjust parameters with analog inputs
  87. //knob_A1 = (float)analogRead(A1) / 1023.0;
  88. //knob_A2 = (float)analogRead(A2) / 1023.0;
  89. //knob_A3 = (float)analogRead(A3) / 1023.0;
  90. mixer2.gain(0, knob_A1);
  91. mixer2.gain(1, 1.0 - knob_A1);
  92. freeverb1.roomsize(knob_A2);
  93. freeverb1.damping(knob_A3);
  94. Serial.print("Reverb: mix=");
  95. Serial.print(knob_A1 * 100.0);
  96. Serial.print("%, roomsize=");
  97. Serial.print(knob_A2 * 100.0);
  98. Serial.print("%, damping=");
  99. Serial.print(knob_A3 * 100.0);
  100. Serial.print("%, CPU Usage=");
  101. Serial.print(freeverb1.processorUsage());
  102. Serial.println("%");
  103. }
  104. }
  105. }
  106. void loop() {
  107. playFile("SDTEST1.WAV"); // filenames are always uppercase 8.3 format
  108. delay(500);
  109. playFile("SDTEST2.WAV");
  110. delay(500);
  111. playFile("SDTEST3.WAV");
  112. delay(500);
  113. playFile("SDTEST4.WAV");
  114. delay(1500);
  115. }