Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

66 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. const int myInput = AUDIO_INPUT_LINEIN;
  9. // const int myInput = AUDIO_INPUT_MIC;
  10. int updateFilter[5];
  11. AudioInputI2S audioInput; // audio shield: mic or line-in
  12. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  13. // Create Audio connections between the components
  14. //
  15. AudioConnection c1(audioInput, 0, audioOutput, 0); // left passing through
  16. AudioConnection c2(audioInput, 1, audioOutput, 1); // right passing through
  17. // Create an object to control the audio shield.
  18. //
  19. AudioControlSGTL5000 audioShield;
  20. void setup() {
  21. // Audio connections require memory to work. For more
  22. // detailed information, see the MemoryAndCpuUsage example
  23. AudioMemory(4);
  24. // Enable the audio shield, select the input and set the output volume.
  25. audioShield.enable();
  26. audioShield.inputSelect(myInput);
  27. audioShield.volume(0.5);
  28. audioShield.audioPostProcessorEnable(); // enable the DAP block in SGTL5000
  29. // audioShield.eqSelect(1); // using PEQ Biquad filters
  30. // audioShield.eqFilterCount(2); // enable filter 0 & filter 1
  31. calcBiquad(FILTER_PARAEQ,110,0,0.2,524288,44100,updateFilter); // automation negates the need
  32. audioShield.eqFilter(0,updateFilter); // for the three lines commented out above.
  33. calcBiquad(FILTER_PARAEQ,4400,0,0.167,524288,44100,updateFilter);
  34. audioShield.eqFilter(1,updateFilter);
  35. }
  36. elapsedMillis chgMsec=0;
  37. float tone1=0;
  38. void loop() {
  39. // every 10 ms, check for adjustment
  40. if (chgMsec > 10) {
  41. float tone2=analogRead(15);
  42. tone2=floor(((tone2-512)/512)*70)/10;
  43. if(tone2!=tone1)
  44. {
  45. // calcBiquad(FilterType,FrequencyC,dBgain,Q,QuantizationUnit,SampleRate,int*);
  46. calcBiquad(FILTER_PARAEQ,110,-tone2,0.2,524288,44100,updateFilter);
  47. audioShield.eqFilter(0,updateFilter);
  48. calcBiquad(FILTER_PARAEQ,4400,tone2,0.167,524288,44100,updateFilter);
  49. audioShield.eqFilter(1,updateFilter);
  50. tone1=tone2;
  51. }
  52. chgMsec = 0;
  53. }
  54. }