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.

65 lines
1.9KB

  1. /* DAP Bass enhance example SGTL5000 only
  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. #include <SerialFlash.h>
  9. const int myInput = AUDIO_INPUT_LINEIN;
  10. // const int myInput = AUDIO_INPUT_MIC;
  11. // Create the Audio components. These should be created in the
  12. // order data flows, inputs/sources -> processing -> outputs
  13. //
  14. AudioInputI2S audioInput; // audio shield: mic or line-in
  15. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  16. // Create Audio connections between the components
  17. //
  18. AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through
  19. AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through
  20. // Create an object to control the audio shield.
  21. //
  22. AudioControlSGTL5000 audioShield;
  23. void setup() {
  24. // Audio connections require memory to work. For more
  25. // detailed information, see the MemoryAndCpuUsage example
  26. AudioMemory(4);
  27. // Enable the audio shield and set the output volume.
  28. audioShield.enable();
  29. audioShield.inputSelect(myInput);
  30. audioShield.volume(0.5);
  31. // just enable it to use default settings.
  32. audioShield.audioPostProcessorEnable();
  33. audioShield.enhanceBassEnable(); // all we need to do for default bass enhancement settings.
  34. // audioShield.enhanceBass((float)lr_level,(float)bass_level);
  35. // audioShield.enhanceBass((float)lr_level,(float)bass_level,(uint8_t)hpf_bypass,(uint8_t)cutoff);
  36. // please see http://www.pjrc.com/teensy/SGTL5000.pdf page 50 for valid values for BYPASS_HPF and CUTOFF
  37. }
  38. elapsedMillis chgMsec=0;
  39. float lastVol=1024;
  40. void loop() {
  41. // every 10 ms, check for adjustment
  42. if (chgMsec > 10) { // more regular updates for actual changes seems better.
  43. float vol1=analogRead(15)/1023.0;
  44. vol1=(int)vol1;
  45. if(lastVol!=vol1)
  46. {
  47. audioShield.volume(vol1);
  48. lastVol=vol1;
  49. }
  50. chgMsec = 0;
  51. }
  52. }