Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

76 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(0.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. }
  41. elapsedMillis chgMsec=0;
  42. float tone1=0;
  43. void loop() {
  44. // every 10 ms, check for adjustment
  45. if (chgMsec > 10) {
  46. float tone2=analogRead(15);
  47. tone2=floor(((tone2-512)/512)*70)/10;
  48. if(tone2!=tone1)
  49. {
  50. // calcBiquad(FilterType,FrequencyC,dBgain,Q,QuantizationUnit,SampleRate,int*);
  51. calcBiquad(FILTER_PARAEQ,110,-tone2,0.2,2147483648,44100,updateFilter);
  52. filterTone_L.updateCoefs(updateFilter);
  53. filterTone_R.updateCoefs(updateFilter);
  54. calcBiquad(FILTER_PARAEQ,4400,tone2,0.167,2147483648,44100,updateFilter);
  55. filterTone_L.updateCoefs(1,updateFilter);
  56. filterTone_R.updateCoefs(1,updateFilter);
  57. tone1=tone2;
  58. }
  59. chgMsec = 0;
  60. }
  61. }