Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

225 linhas
5.3KB

  1. /*
  2. Change the chorus code to produce a flange effect
  3. 140219
  4. e
  5. FMI:
  6. The audio board uses the following pins.
  7. 6 - MEMCS
  8. 7 - MOSI
  9. 9 - BCLK
  10. 10 - SDCS
  11. 11 - MCLK
  12. 12 - MISO
  13. 13 - RX
  14. 14 - SCLK
  15. 15 - VOL
  16. 18 - SDA
  17. 19 - SCL
  18. 22 - TX
  19. 23 - LRCLK
  20. AudioProcessorUsage()
  21. AudioProcessorUsageMax()
  22. AudioProcessorUsageMaxReset()
  23. AudioMemoryUsage()
  24. AudioMemoryUsageMax()
  25. AudioMemoryUsageMaxReset()
  26. The CPU usage is an integer from 0 to 100, and the memory is from 0 to however
  27. many blocks you provided with AudioMemory().
  28. */
  29. #include <Audio.h>
  30. #include <Wire.h>
  31. #include <SD.h>
  32. #include <SPI.h>
  33. #include <Bounce.h>
  34. // Number of samples in ONE channel
  35. #define FLANGE_DELAY_LENGTH (6*AUDIO_BLOCK_SAMPLES)
  36. // Allocate the delay line for left and right channels
  37. // The delayline will hold left and right samples so it
  38. // should be declared to be twice as long as the desired
  39. // number of samples in one channel
  40. #define FLANGE_DELAYLINE (FLANGE_DELAY_LENGTH*2)
  41. // The delay line for left and right channels
  42. short delayline[FLANGE_DELAYLINE];
  43. // If this pin is grounded the effect is turned off,
  44. // which makes it just pass through the audio
  45. // Don't use any of the pins listed above
  46. #define PASSTHRU_PIN 1
  47. Bounce b_passthru = Bounce(PASSTHRU_PIN,15);
  48. //const int myInput = AUDIO_INPUT_MIC;
  49. const int myInput = AUDIO_INPUT_LINEIN;
  50. AudioInputI2S audioInput; // audio shield: mic or line-in
  51. AudioEffectFlange myEffect;
  52. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  53. // Create Audio connections between the components
  54. // Both channels of the audio input go to the flange effect
  55. AudioConnection c1(audioInput, 0, myEffect, 0);
  56. AudioConnection c2(audioInput, 1, myEffect, 1);
  57. // both channels from the flange effect go to the audio output
  58. AudioConnection c3(myEffect, 0, audioOutput, 0);
  59. AudioConnection c4(myEffect, 1, audioOutput, 1);
  60. AudioControlSGTL5000 audioShield;
  61. /*
  62. int s_idx = FLANGE_DELAY_LENGTH/2;
  63. int s_depth = FLANGE_DELAY_LENGTH/16;
  64. double s_freq = 1;
  65. // <<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
  66. // 12
  67. int s_idx = FLANGE_DELAY_LENGTH/2;
  68. int s_depth = FLANGE_DELAY_LENGTH/8;
  69. double s_freq = .125;
  70. // with .125 the ticking is about 1Hz with music
  71. // but with the noise sample it is a bit slower than that
  72. // <<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
  73. */
  74. /*
  75. // <<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
  76. // 12
  77. int s_idx = FLANGE_DELAY_LENGTH/2;
  78. int s_depth = FLANGE_DELAY_LENGTH/12;
  79. double s_freq = .125;
  80. // with .125 the ticking is about 1Hz with music
  81. // but with the noise sample it is a bit slower than that
  82. // <<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
  83. */
  84. /*
  85. //12
  86. int s_idx = 15*FLANGE_DELAY_LENGTH/16;
  87. int s_depth = 15*FLANGE_DELAY_LENGTH/16;
  88. double s_freq = 0;
  89. */
  90. /*
  91. //12
  92. int s_idx = 2*FLANGE_DELAY_LENGTH/4;
  93. int s_depth = FLANGE_DELAY_LENGTH/8;
  94. double s_freq = .0625;
  95. */
  96. /*
  97. //12 - good with Eric Clapton Unplugged
  98. int s_idx = 3*FLANGE_DELAY_LENGTH/4;
  99. int s_depth = FLANGE_DELAY_LENGTH/8;
  100. double s_freq = .0625;
  101. */
  102. /*
  103. // Real flange effect! delay line is 2*
  104. int s_idx = 2*FLANGE_DELAY_LENGTH/4;
  105. int s_depth = FLANGE_DELAY_LENGTH/4;
  106. double s_freq = 2;
  107. */
  108. /* 2 -
  109. int s_idx = 2*FLANGE_DELAY_LENGTH/4;
  110. int s_depth = FLANGE_DELAY_LENGTH/8;
  111. double s_freq = 4;
  112. */
  113. /*
  114. // 4
  115. int s_idx = FLANGE_DELAY_LENGTH/4;
  116. int s_depth = FLANGE_DELAY_LENGTH/4;
  117. double s_freq = .25;
  118. */
  119. // 4
  120. int s_idx = FLANGE_DELAY_LENGTH/4;
  121. int s_depth = FLANGE_DELAY_LENGTH/4;
  122. double s_freq = .5;
  123. void setup() {
  124. Serial.begin(9600);
  125. while (!Serial) ;
  126. delay(3000);
  127. pinMode(PASSTHRU_PIN,INPUT_PULLUP);
  128. // It doesn't work properly with any less than 8
  129. // but that was an earlier version. Processor and
  130. // memory usage are now (ver j)
  131. // Proc = 24 (24), Mem = 4 (4)
  132. AudioMemory(8);
  133. audioShield.enable();
  134. audioShield.inputSelect(myInput);
  135. audioShield.volume(0.65);
  136. // Warn that the passthru pin is grounded
  137. if(!digitalRead(PASSTHRU_PIN)) {
  138. Serial.print("PASSTHRU_PIN (");
  139. Serial.print(PASSTHRU_PIN);
  140. Serial.println(") is grounded");
  141. }
  142. // Set up the flange effect
  143. // - address of delayline
  144. // - total number of samples (left AND right) in the delay line
  145. // - Index (in samples) into the delay line for the added voice
  146. // - Depth of the flange effect
  147. // - frequency of the flange effect
  148. myEffect.begin(delayline,FLANGE_DELAYLINE,s_idx,s_depth,s_freq);
  149. // I want output on the line out too
  150. audioShield.unmuteLineout();
  151. Serial.println("setup done");
  152. AudioProcessorUsageMaxReset();
  153. AudioMemoryUsageMaxReset();
  154. }
  155. // audio volume
  156. int volume = 0;
  157. unsigned long last_time = millis();
  158. void loop()
  159. {
  160. // Volume control
  161. int n = analogRead(15);
  162. if (n != volume) {
  163. volume = n;
  164. audioShield.volume((float)n / 10.23);
  165. }
  166. if(0) {
  167. if(millis() - last_time >= 5000) {
  168. Serial.print("Proc = ");
  169. Serial.print(AudioProcessorUsage());
  170. Serial.print(" (");
  171. Serial.print(AudioProcessorUsageMax());
  172. Serial.print("), Mem = ");
  173. Serial.print(AudioMemoryUsage());
  174. Serial.print(" (");
  175. Serial.print(AudioMemoryUsageMax());
  176. Serial.println(")");
  177. last_time = millis();
  178. }
  179. }
  180. // update the button
  181. b_passthru.update();
  182. // If the passthru button is pushed, save the current
  183. // filter index and then switch the effect to passthru
  184. if(b_passthru.fallingEdge()) {
  185. myEffect.modify(DELAY_PASSTHRU,0,0);
  186. }
  187. // If passthru button is released, restore the effect
  188. if(b_passthru.risingEdge()) {
  189. myEffect.modify(s_idx,s_depth,s_freq);
  190. }
  191. }