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.

78 lines
2.5KB

  1. /* Tone example using AudioFilterBiquad object 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 <SD.h>
  7. const int myInput = AUDIO_INPUT_LINEIN;
  8. // const int myInput = AUDIO_INPUT_MIC;
  9. int ToneFilter_L[]={0,0,0,0,0,0,0,0x80000000,0,0,0,0,0,0,0,0}; // defines 2 sets of coefficients, not sure max possible in
  10. int ToneFilter_R[]={0,0,0,0,0,0,0,0x80000000,0,0,0,0,0,0,0,0}; // time frame but probably quite a few.
  11. int updateFilter[5];
  12. AudioInputI2S audioInput; // audio shield: mic or line-in
  13. AudioFilterBiquad filterTone_L(ToneFilter_L);
  14. AudioFilterBiquad filterTone_R(ToneFilter_R);
  15. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  16. // Create Audio connections between the components
  17. //
  18. AudioConnection c1(audioInput,0,filterTone_L,0);
  19. AudioConnection c2(audioInput,1,filterTone_R,0);
  20. AudioConnection c3(filterTone_L,0,audioOutput,0);
  21. AudioConnection c4(filterTone_R,0,audioOutput,1);
  22. // Create an object to control the audio shield.
  23. //
  24. AudioControlSGTL5000 audioShield;
  25. void setup() {
  26. // Audio connections require memory to work. For more
  27. // detailed information, see the MemoryAndCpuUsage example
  28. AudioMemory(6);
  29. // Enable the audio shield, select the input and set the output volume.
  30. audioShield.enable();
  31. audioShield.inputSelect(myInput);
  32. audioShield.volume(75);
  33. audioShield.unmuteLineout();
  34. calcBiquad(FILTER_PARAEQ,110,0,0.2,2147483648,44100,updateFilter);
  35. filterTone_L.updateCoefs(updateFilter); // default set updateCoefs(0,updateFilter);
  36. filterTone_R.updateCoefs(updateFilter);
  37. calcBiquad(FILTER_PARAEQ,4400,0,0.167,2147483648,44100,updateFilter);
  38. filterTone_L.updateCoefs(1,updateFilter);
  39. filterTone_R.updateCoefs(1,updateFilter);
  40. Serial.begin(9600);
  41. }
  42. elapsedMillis chgMsec=0;
  43. float tone1=0;
  44. void loop() {
  45. // every 10 ms, check for adjustment
  46. if (chgMsec > 10) {
  47. float tone2=analogRead(15);
  48. tone2=floor(((tone2-512)/512)*70)/10;
  49. if(tone2!=tone1)
  50. {
  51. // calcBiquad(FilterType,FrequencyC,dBgain,Q,QuantizationUnit,SampleRate,int*);
  52. calcBiquad(FILTER_PARAEQ,110,-tone2,0.2,2147483648,44100,updateFilter);
  53. filterTone_L.updateCoefs(updateFilter);
  54. filterTone_R.updateCoefs(updateFilter);
  55. calcBiquad(FILTER_PARAEQ,4400,tone2,0.167,2147483648,44100,updateFilter);
  56. filterTone_L.updateCoefs(1,updateFilter);
  57. filterTone_R.updateCoefs(1,updateFilter);
  58. tone1=tone2;
  59. }
  60. chgMsec = 0;
  61. }
  62. }