Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

146 lines
4.3KB

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