Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

67 lines
2.1KB

  1. /* Tone example using SGTL5000 DAP PEQ filters and calcBiquad filter calculator routine.
  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. int updateFilter[5];
  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, select the input and set the output volume.
  26. audioShield.enable();
  27. audioShield.inputSelect(myInput);
  28. audioShield.volume(0.5);
  29. audioShield.audioPostProcessorEnable(); // enable the DAP block in SGTL5000
  30. // audioShield.eqSelect(1); // using PEQ Biquad filters
  31. // audioShield.eqFilterCount(2); // enable filter 0 & filter 1
  32. calcBiquad(FILTER_PARAEQ,110,0,0.2,524288,44100,updateFilter); // automation negates the need
  33. audioShield.eqFilter(0,updateFilter); // for the three lines commented out above.
  34. calcBiquad(FILTER_PARAEQ,4400,0,0.167,524288,44100,updateFilter);
  35. audioShield.eqFilter(1,updateFilter);
  36. }
  37. elapsedMillis chgMsec=0;
  38. float tone1=0;
  39. void loop() {
  40. // every 10 ms, check for adjustment
  41. if (chgMsec > 10) {
  42. float tone2=analogRead(15);
  43. tone2=floor(((tone2-512)/512)*70)/10;
  44. if(tone2!=tone1)
  45. {
  46. // calcBiquad(FilterType,FrequencyC,dBgain,Q,QuantizationUnit,SampleRate,int*);
  47. calcBiquad(FILTER_PARAEQ,110,-tone2,0.2,524288,44100,updateFilter);
  48. audioShield.eqFilter(0,updateFilter);
  49. calcBiquad(FILTER_PARAEQ,4400,tone2,0.167,524288,44100,updateFilter);
  50. audioShield.eqFilter(1,updateFilter);
  51. tone1=tone2;
  52. }
  53. chgMsec = 0;
  54. }
  55. }