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