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.

dap_avc_agc.ino 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* DAP AVC example; AVC is SGTL5000 equiv of AGC
  2. This example code is in the public domain
  3. */
  4. #include <Audio.h>
  5. #include <Wire.h>
  6. #include <SD.h>
  7. const int myInput = AUDIO_INPUT_LINEIN;
  8. // const int myInput = AUDIO_INPUT_MIC;
  9. // Create the Audio components. These should be created in the
  10. // order data flows, inputs/sources -> processing -> outputs
  11. //
  12. AudioInputI2S audioInput; // audio shield: mic or line-in
  13. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  14. // Create Audio connections between the components
  15. //
  16. AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through
  17. AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through
  18. // Create an object to control the audio shield.
  19. //
  20. AudioControlSGTL5000 audioShield;
  21. void setup() {
  22. // Audio connections require memory to work. For more
  23. // detailed information, see the MemoryAndCpuUsage example
  24. AudioMemory(4);
  25. // Enable the audio shield and set the output volume.
  26. audioShield.enable();
  27. audioShield.inputSelect(myInput);
  28. audioShield.volume(0.75);
  29. audioShield.unmuteLineout();
  30. // here are some settings for AVC that have a fairly obvious effect
  31. audioShield.autoVolumeControl(2,1,0,-5,0.5,0.5); // see comments starting line #699 of control_sgtl5000.cpp in ./libraries/audio/
  32. // AVC has its own enable/disable bit
  33. // you can use audioShield.autoVolumeEnable(0); to turn off AVC
  34. }
  35. elapsedMillis chgMsec=0;
  36. float lastVol=1024;
  37. void loop() {
  38. // every 10 ms, check for adjustment
  39. if (chgMsec > 10) {
  40. float vol1=analogRead(15)/10.23;
  41. vol1=(int)vol1;
  42. if(lastVol!=vol1)
  43. {
  44. audioShield.volume(vol1);
  45. lastVol=vol1;
  46. }
  47. chgMsec = 0;
  48. }
  49. }