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.

преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. VERSION 2 - use modified library which has been changed to handle
  3. one channel instead of two
  4. Proc = 21 (22), Mem = 4 (6)
  5. 140529
  6. 2a
  7. - default at startup is to have passthru ON and the button
  8. switches the flange effect in.
  9. From: http://www.cs.cf.ac.uk/Dave/CM0268/PDF/10_CM0268_Audio_FX.pdf
  10. about Comb filter effects
  11. Effect Delay range (ms) Modulation
  12. Resonator 0 - 20 None
  13. Flanger 0 - 15 Sinusoidal (approx 1Hz)
  14. Chorus 25 - 50 None
  15. Echo >50 None
  16. FMI:
  17. The audio board uses the following pins.
  18. 6 - MEMCS
  19. 7 - MOSI
  20. 9 - BCLK
  21. 10 - SDCS
  22. 11 - MCLK
  23. 12 - MISO
  24. 13 - RX
  25. 14 - SCLK
  26. 15 - VOL
  27. 18 - SDA
  28. 19 - SCL
  29. 22 - TX
  30. 23 - LRCLK
  31. AudioProcessorUsage()
  32. AudioProcessorUsageMax()
  33. AudioProcessorUsageMaxReset()
  34. AudioMemoryUsage()
  35. AudioMemoryUsageMax()
  36. AudioMemoryUsageMaxReset()
  37. The CPU usage is an integer from 0 to 100, and the memory is from 0 to however
  38. many blocks you provided with AudioMemory().
  39. */
  40. #include <Audio.h>
  41. #include <Wire.h>
  42. #include <SD.h>
  43. #include <SPI.h>
  44. #include <Bounce.h>
  45. // Number of samples in each delay line
  46. #define FLANGE_DELAY_LENGTH (6*AUDIO_BLOCK_SAMPLES)
  47. // Allocate the delay lines for left and right channels
  48. short l_delayline[FLANGE_DELAY_LENGTH];
  49. short r_delayline[FLANGE_DELAY_LENGTH];
  50. // Default is to just pass the audio through. Grounding this pin
  51. // applies the flange effect
  52. // Don't use any of the pins listed above
  53. #define PASSTHRU_PIN 1
  54. Bounce b_passthru = Bounce(PASSTHRU_PIN,15);
  55. //const int myInput = AUDIO_INPUT_MIC;
  56. const int myInput = AUDIO_INPUT_LINEIN;
  57. AudioInputI2S audioInput; // audio shield: mic or line-in
  58. AudioEffectFlange l_myEffect;
  59. AudioEffectFlange r_myEffect;
  60. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  61. // Create Audio connections between the components
  62. // Both channels of the audio input go to the flange effect
  63. AudioConnection c1(audioInput, 0, l_myEffect, 0);
  64. AudioConnection c2(audioInput, 1, r_myEffect, 0);
  65. // both channels from the flange effect go to the audio output
  66. AudioConnection c3(l_myEffect, 0, audioOutput, 0);
  67. AudioConnection c4(r_myEffect, 0, audioOutput, 1);
  68. AudioControlSGTL5000 audioShield;
  69. int s_idx = FLANGE_DELAY_LENGTH/4;
  70. int s_depth = FLANGE_DELAY_LENGTH/4;
  71. double s_freq = .5;
  72. void setup() {
  73. Serial.begin(9600);
  74. while (!Serial) ;
  75. delay(3000);
  76. pinMode(PASSTHRU_PIN,INPUT_PULLUP);
  77. // It doesn't work properly with any less than 8
  78. // but that was an earlier version. Processor and
  79. // memory usage are now (ver j)
  80. // Proc = 24 (24), Mem = 4 (4)
  81. AudioMemory(8);
  82. audioShield.enable();
  83. audioShield.inputSelect(myInput);
  84. audioShield.volume(0.65);
  85. // Warn that the passthru pin is grounded
  86. if(!digitalRead(PASSTHRU_PIN)) {
  87. Serial.print("PASSTHRU_PIN (");
  88. Serial.print(PASSTHRU_PIN);
  89. Serial.println(") is grounded");
  90. }
  91. // Set up the flange effect:
  92. // address of delayline
  93. // total number of samples in the delay line
  94. // Index (in samples) into the delay line for the added voice
  95. // Depth of the flange effect
  96. // frequency of the flange effect
  97. l_myEffect.begin(l_delayline,FLANGE_DELAY_LENGTH,s_idx,s_depth,s_freq);
  98. r_myEffect.begin(r_delayline,FLANGE_DELAY_LENGTH,s_idx,s_depth,s_freq);
  99. // Initially the effect is off. It is switched on when the
  100. // PASSTHRU button is pushed.
  101. l_myEffect.voices(FLANGE_DELAY_PASSTHRU,0,0);
  102. r_myEffect.voices(FLANGE_DELAY_PASSTHRU,0,0);
  103. // I want output on the line out too
  104. audioShield.unmuteLineout();
  105. Serial.println("setup done");
  106. AudioProcessorUsageMaxReset();
  107. AudioMemoryUsageMaxReset();
  108. }
  109. // audio volume
  110. int volume = 0;
  111. unsigned long last_time = millis();
  112. void loop()
  113. {
  114. // Volume control
  115. int n = analogRead(15);
  116. if (n != volume) {
  117. volume = n;
  118. audioShield.volume((float)n / 10.23);
  119. }
  120. if(0) {
  121. if(millis() - last_time >= 5000) {
  122. Serial.print("Proc = ");
  123. Serial.print(AudioProcessorUsage());
  124. Serial.print(" (");
  125. Serial.print(AudioProcessorUsageMax());
  126. Serial.print("), Mem = ");
  127. Serial.print(AudioMemoryUsage());
  128. Serial.print(" (");
  129. Serial.print(AudioMemoryUsageMax());
  130. Serial.println(")");
  131. last_time = millis();
  132. }
  133. }
  134. // update the button
  135. b_passthru.update();
  136. // If the passthru button is pushed
  137. // turn the flange effect on
  138. // filter index and then switch the effect to passthru
  139. if(b_passthru.fallingEdge()) {
  140. l_myEffect.voices(s_idx,s_depth,s_freq);
  141. r_myEffect.voices(s_idx,s_depth,s_freq);
  142. }
  143. // If passthru button is released restore passthru
  144. if(b_passthru.risingEdge()) {
  145. l_myEffect.voices(FLANGE_DELAY_PASSTHRU,0,0);
  146. r_myEffect.voices(FLANGE_DELAY_PASSTHRU,0,0);
  147. }
  148. }