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 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 <SerialFlash.h>
  46. #include <Bounce.h>
  47. // Number of samples in each delay line
  48. #define CHORUS_DELAY_LENGTH (16*AUDIO_BLOCK_SAMPLES)
  49. // Allocate the delay lines for left and right channels
  50. short l_delayline[CHORUS_DELAY_LENGTH];
  51. short r_delayline[CHORUS_DELAY_LENGTH];
  52. // Default is to just pass the audio through. Grounding this pin
  53. // applies the chorus effect
  54. // Don't use any of the pins listed above
  55. #define PASSTHRU_PIN 1
  56. Bounce b_passthru = Bounce(PASSTHRU_PIN,15);
  57. //const int myInput = AUDIO_INPUT_MIC;
  58. const int myInput = AUDIO_INPUT_LINEIN;
  59. AudioInputI2S audioInput; // audio shield: mic or line-in
  60. AudioEffectChorus l_myEffect;
  61. AudioEffectChorus r_myEffect;
  62. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  63. // Create Audio connections between the components
  64. // Both channels of the audio input go to the chorus effect
  65. AudioConnection c1(audioInput, 0, l_myEffect, 0);
  66. AudioConnection c2(audioInput, 1, r_myEffect, 0);
  67. // both channels chorus effects go to the audio output
  68. AudioConnection c3(l_myEffect, 0, audioOutput, 0);
  69. AudioConnection c4(r_myEffect, 0, audioOutput, 1);
  70. AudioControlSGTL5000 audioShield;
  71. // number of "voices" in the chorus which INCLUDES the original voice
  72. int n_chorus = 2;
  73. // <<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
  74. void setup() {
  75. Serial.begin(9600);
  76. while (!Serial) ;
  77. delay(3000);
  78. pinMode(PASSTHRU_PIN,INPUT_PULLUP);
  79. // Maximum memory usage was reported as 4
  80. // Proc = 9 (9), Mem = 4 (4)
  81. AudioMemory(4);
  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. // Initialize the effect - left channel
  92. // address of delayline
  93. // total number of samples in the delay line
  94. // number of voices in the chorus INCLUDING the original voice
  95. if(!l_myEffect.begin(l_delayline,CHORUS_DELAY_LENGTH,n_chorus)) {
  96. Serial.println("AudioEffectChorus - left channel begin failed");
  97. while(1);
  98. }
  99. // Initialize the effect - right channel
  100. // address of delayline
  101. // total number of samples in the delay line
  102. // number of voices in the chorus INCLUDING the original voice
  103. if(!r_myEffect.begin(r_delayline,CHORUS_DELAY_LENGTH,n_chorus)) {
  104. Serial.println("AudioEffectChorus - left channel begin failed");
  105. while(1);
  106. }
  107. // Initially the effect is off. It is switched on when the
  108. // PASSTHRU button is pushed.
  109. l_myEffect.voices(0);
  110. r_myEffect.voices(0);
  111. Serial.println("setup done");
  112. AudioProcessorUsageMaxReset();
  113. AudioMemoryUsageMaxReset();
  114. }
  115. // audio volume
  116. int volume = 0;
  117. unsigned long last_time = millis();
  118. void loop()
  119. {
  120. // Volume control
  121. int n = analogRead(15);
  122. if (n != volume) {
  123. volume = n;
  124. audioShield.volume((float)n / 1023);
  125. }
  126. if(0) {
  127. if(millis() - last_time >= 5000) {
  128. Serial.print("Proc = ");
  129. Serial.print(AudioProcessorUsage());
  130. Serial.print(" (");
  131. Serial.print(AudioProcessorUsageMax());
  132. Serial.print("), Mem = ");
  133. Serial.print(AudioMemoryUsage());
  134. Serial.print(" (");
  135. Serial.print(AudioMemoryUsageMax());
  136. Serial.println(")");
  137. last_time = millis();
  138. }
  139. }
  140. // update the button
  141. b_passthru.update();
  142. // If the passthru button is pushed, switch the chorus on
  143. if(b_passthru.fallingEdge()) {
  144. l_myEffect.voices(n_chorus);
  145. r_myEffect.voices(n_chorus);
  146. }
  147. // If passthru button is released, turn on passthru
  148. if(b_passthru.risingEdge()) {
  149. l_myEffect.voices(0);
  150. r_myEffect.voices(0);
  151. }
  152. }