Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

165 lines
3.8KB

  1. /*
  2. PROC/MEM 9/4
  3. 140219
  4. p
  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 CHORUS_DELAY_LENGTH (16*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 CHORUS_DELAYLINE (CHORUS_DELAY_LENGTH*2)
  41. // The delay line for left and right channels
  42. short delayline[CHORUS_DELAYLINE];
  43. // If this pin is grounded the chorus 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. AudioEffectChorus 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 chorus effect
  55. AudioConnection c1(audioInput, 0, myEffect, 0);
  56. AudioConnection c2(audioInput, 1, myEffect, 1);
  57. // both channels from the chorus effect go to the audio output
  58. AudioConnection c3(myEffect, 0, audioOutput, 0);
  59. AudioConnection c4(myEffect, 1, audioOutput, 1);
  60. AudioControlSGTL5000 audioShield;
  61. // number of "voices" in the chorus which INCLUDES the original voice
  62. int n_chorus = 2;
  63. // <<<<<<<<<<<<<<>>>>>>>>>>>>>>>>
  64. void setup() {
  65. Serial.begin(9600);
  66. while (!Serial) ;
  67. delay(3000);
  68. pinMode(PASSTHRU_PIN,INPUT_PULLUP);
  69. // Maximum memory usage was reported as 4
  70. // Proc = 9 (9), Mem = 4 (4)
  71. AudioMemory(4);
  72. audioShield.enable();
  73. audioShield.inputSelect(myInput);
  74. audioShield.volume(0.65);
  75. // Warn that the passthru pin is grounded
  76. if(!digitalRead(PASSTHRU_PIN)) {
  77. Serial.print("PASSTHRU_PIN (");
  78. Serial.print(PASSTHRU_PIN);
  79. Serial.println(") is grounded");
  80. }
  81. // Initialize the effect
  82. // - address of delayline
  83. // - total number of samples (left AND right) in the delay line
  84. // - number of voices in the chorus INCLUDING the original voice
  85. if(!myEffect.begin(delayline,CHORUS_DELAYLINE,n_chorus)) {
  86. Serial.println("AudioEffectChorus - begin failed");
  87. while(1);
  88. }
  89. // I want output on the line out too
  90. audioShield.unmuteLineout();
  91. // audioShield.muteHeadphone();
  92. Serial.println("setup done");
  93. AudioProcessorUsageMaxReset();
  94. AudioMemoryUsageMaxReset();
  95. }
  96. // audio volume
  97. int volume = 0;
  98. unsigned long last_time = millis();
  99. void loop()
  100. {
  101. // Volume control
  102. int n = analogRead(15);
  103. if (n != volume) {
  104. volume = n;
  105. audioShield.volume((float)n / 1023);
  106. }
  107. if(0) {
  108. if(millis() - last_time >= 5000) {
  109. Serial.print("Proc = ");
  110. Serial.print(AudioProcessorUsage());
  111. Serial.print(" (");
  112. Serial.print(AudioProcessorUsageMax());
  113. Serial.print("), Mem = ");
  114. Serial.print(AudioMemoryUsage());
  115. Serial.print(" (");
  116. Serial.print(AudioMemoryUsageMax());
  117. Serial.println(")");
  118. last_time = millis();
  119. }
  120. }
  121. // update the button
  122. b_passthru.update();
  123. // If the passthru button is pushed, switch the effect to passthru
  124. if(b_passthru.fallingEdge()) {
  125. myEffect.modify(0);
  126. }
  127. // If passthru button is released, restore the previous chorus
  128. if(b_passthru.risingEdge()) {
  129. myEffect.modify(n_chorus);
  130. }
  131. }