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.

PeakAndRMSMeterStereo.ino 2.1KB

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