Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

113 lines
3.0KB

  1. #include <Audio.h>
  2. #include <Wire.h>
  3. #include <SPI.h>
  4. #include <SD.h>
  5. #include <SerialFlash.h>
  6. #include <Bounce.h>
  7. AudioPlaySdWav playSdWav1; //xy=163,135
  8. AudioMixer4 mixer1; //xy=332,167
  9. AudioEffectGranular granular1; //xy=504,155
  10. AudioOutputI2S i2s1; //xy=664,185
  11. AudioConnection patchCord1(playSdWav1, 0, mixer1, 0);
  12. AudioConnection patchCord2(playSdWav1, 1, mixer1, 1);
  13. AudioConnection patchCord3(mixer1, granular1);
  14. AudioConnection patchCord4(granular1, 0, i2s1, 0);
  15. AudioConnection patchCord5(granular1, 0, i2s1, 1);
  16. AudioControlSGTL5000 sgtl5000_1; //xy=236,248
  17. Bounce button0 = Bounce(0, 15);
  18. Bounce button1 = Bounce(1, 15);
  19. Bounce button2 = Bounce(2, 15);
  20. #define GRANULAR_MEMORY_SIZE 12800 // enough for 290 ms at 44.1 kHz
  21. int16_t granularMemory[GRANULAR_MEMORY_SIZE];
  22. // Use these with the Teensy Audio Shield
  23. #define SDCARD_CS_PIN 10
  24. #define SDCARD_MOSI_PIN 7
  25. #define SDCARD_SCK_PIN 14
  26. // Use these with the Teensy 3.5 & 3.6 SD card
  27. //#define SDCARD_CS_PIN BUILTIN_SDCARD
  28. //#define SDCARD_MOSI_PIN 11 // not actually used
  29. //#define SDCARD_SCK_PIN 13 // not actually used
  30. // Use these for the SD+Wiz820 or other adaptors
  31. //#define SDCARD_CS_PIN 4
  32. //#define SDCARD_MOSI_PIN 11
  33. //#define SDCARD_SCK_PIN 13
  34. #define NUM_FILES 4
  35. const char *filenames[NUM_FILES]={"SDTEST1.WAV", "SDTEST2.WAV", "SDTEST3.WAV", "SDTEST4.WAV"};
  36. int nextfile=0;
  37. void setup() {
  38. Serial.begin(9600);
  39. AudioMemory(10);
  40. pinMode(0, INPUT_PULLUP);
  41. pinMode(1, INPUT_PULLUP);
  42. pinMode(2, INPUT_PULLUP);
  43. sgtl5000_1.enable();
  44. sgtl5000_1.volume(0.5);
  45. mixer1.gain(0, 0.5);
  46. mixer1.gain(1, 0.5);
  47. // the Granular effect requires memory to operate
  48. granular1.begin(granularMemory, GRANULAR_MEMORY_SIZE);
  49. SPI.setMOSI(SDCARD_MOSI_PIN);
  50. SPI.setSCK(SDCARD_SCK_PIN);
  51. if (!(SD.begin(SDCARD_CS_PIN))) {
  52. // stop here, but print a message repetitively
  53. while (1) {
  54. Serial.println("Unable to access the SD card");
  55. delay(500);
  56. }
  57. }
  58. }
  59. void loop() {
  60. if (playSdWav1.isPlaying() == false) {
  61. // start the next song playing
  62. playSdWav1.play(filenames[nextfile]);
  63. Serial.print("Playing: ");
  64. Serial.println(filenames[nextfile]);
  65. delay(5); // brief delay for the library read WAV info
  66. nextfile = nextfile + 1;
  67. if (nextfile >= NUM_FILES) {
  68. nextfile = 0;
  69. }
  70. }
  71. // read pushbuttons
  72. button0.update();
  73. button1.update();
  74. button2.update();
  75. // read knobs, scale to 0-1.0 numbers
  76. float knobA2 = (float)analogRead(A2) / 1023.0;
  77. float knobA3 = (float)analogRead(A3) / 1023.0;
  78. if (button0.fallingEdge()) {
  79. // Button 0 starts Freeze effect
  80. granular1.beginFreeze(knobA3 * 290.0);
  81. }
  82. if (button0.risingEdge()) {
  83. granular1.stop();
  84. }
  85. if (button1.fallingEdge()) {
  86. // Button 1 starts Pitch Shift effect
  87. granular1.beginPitchShift(knobA3 * 100.0);
  88. }
  89. if (button1.risingEdge()) {
  90. granular1.stop();
  91. }
  92. // continuously adjust pitch bend
  93. granular1.rate(knobA2 * 1023.0);
  94. }