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

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