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.

64 line
1.5KB

  1. /* Stereo peak meter example, assumes Audio adapter but just uses terminal so no more parts required.
  2. This example code is in the public domain
  3. */
  4. #include <Audio.h>
  5. #include <Wire.h>
  6. #include <SPI.h>
  7. #include <SD.h>
  8. const int myInput = AUDIO_INPUT_LINEIN;
  9. // const int myInput = AUDIO_INPUT_MIC;
  10. AudioInputI2S audioInput; // audio shield: mic or line-in
  11. AudioAnalyzePeak peak_L;
  12. AudioAnalyzePeak peak_R;
  13. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  14. AudioConnection c1(audioInput,0,peak_L,0);
  15. AudioConnection c2(audioInput,1,peak_R,0);
  16. AudioConnection c3(audioInput,0,audioOutput,0);
  17. AudioConnection c4(audioInput,1,audioOutput,1);
  18. AudioControlSGTL5000 audioShield;
  19. void setup() {
  20. AudioMemory(6);
  21. audioShield.enable();
  22. audioShield.inputSelect(myInput);
  23. audioShield.volume(0.5);
  24. Serial.begin(9600);
  25. }
  26. // for best effect make your terminal/monitor a minimum of 62 chars wide and as high as you can.
  27. elapsedMillis fps;
  28. uint8_t cnt=0;
  29. void loop() {
  30. if(fps > 24) {
  31. if (peak_L.available() && peak_R.available()) {
  32. fps=0;
  33. uint8_t leftPeak=peak_L.read() * 30.0;
  34. uint8_t rightPeak=peak_R.read() * 30.0;
  35. for(cnt=0;cnt<30-leftPeak;cnt++) {
  36. Serial.print(" ");
  37. }
  38. while(cnt++<30) {
  39. Serial.print("<");
  40. }
  41. Serial.print("||");
  42. for(cnt=0;cnt<rightPeak;cnt++) {
  43. Serial.print(">");
  44. }
  45. while(cnt++<30) {
  46. Serial.print(" ");
  47. }
  48. Serial.println();
  49. }
  50. }
  51. }