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.

CalcBiquadToneControl.ino 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 BassFilter_L[]={0,0,0,0,0,0,0,0};
  10. int BassFilter_R[]={0,0,0,0,0,0,0,0};
  11. int TrebFilter_L[]={0,0,0,0,0,0,0,0};
  12. int TrebFilter_R[]={0,0,0,0,0,0,0,0};
  13. int updateFilter[5];
  14. AudioInputI2S audioInput; // audio shield: mic or line-in
  15. AudioFilterBiquad filterBass_L(BassFilter_L);
  16. AudioFilterBiquad filterBass_R(BassFilter_R);
  17. AudioFilterBiquad filterTreb_L(TrebFilter_L);
  18. AudioFilterBiquad filterTreb_R(TrebFilter_R);
  19. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  20. // Create Audio connections between the components
  21. //
  22. AudioConnection c1(audioInput,0,filterBass_L,0);
  23. AudioConnection c2(audioInput,1,filterBass_R,0);
  24. AudioConnection c3(filterBass_L,0,filterTreb_L,0);
  25. AudioConnection c4(filterBass_R,0,filterTreb_R,0);
  26. AudioConnection c5(filterTreb_L,0,audioOutput,0);
  27. AudioConnection c6(filterTreb_R,0,audioOutput,1);
  28. // Create an object to control the audio shield.
  29. //
  30. AudioControlSGTL5000 audioShield;
  31. void setup() {
  32. // Audio connections require memory to work. For more
  33. // detailed information, see the MemoryAndCpuUsage example
  34. AudioMemory(12);
  35. // Enable the audio shield, select the input and set the output volume.
  36. audioShield.enable();
  37. audioShield.inputSelect(myInput);
  38. audioShield.volume(75);
  39. audioShield.unmuteLineout();
  40. calcBiquad(FILTER_PARAEQ,110,0,0.2,2147483648,44100,updateFilter);
  41. filterBass_L.updateCoefs(updateFilter);
  42. filterBass_R.updateCoefs(updateFilter);
  43. calcBiquad(FILTER_PARAEQ,4400,0,0.167,2147483648,44100,updateFilter);
  44. filterTreb_L.updateCoefs(updateFilter);
  45. filterTreb_R.updateCoefs(updateFilter);
  46. }
  47. elapsedMillis chgMsec=0;
  48. float tone1=0;
  49. void loop() {
  50. // every 10 ms, check for adjustment the tone & vol
  51. if (chgMsec > 10) { // more regular updates for actual changes seems better.
  52. float tone2=analogRead(15);
  53. tone2=floor(((tone2-512)/512)*70)/10;
  54. if(tone2!=tone1)
  55. {
  56. // calcBiquad(FilterType,FrequencyC,dBgain,Q,QuantizationUnit,SampleRate,int*);
  57. calcBiquad(FILTER_PARAEQ,110,-tone2,0.2,2147483648,44100,updateFilter);
  58. filterBass_L.updateCoefs(updateFilter);
  59. filterBass_R.updateCoefs(updateFilter);
  60. calcBiquad(FILTER_PARAEQ,4400,tone2,0.167,2147483648,44100,updateFilter);
  61. filterTreb_L.updateCoefs(updateFilter);
  62. filterTreb_R.updateCoefs(updateFilter);
  63. tone1=tone2;
  64. }
  65. chgMsec = 0;
  66. }
  67. }