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.

77 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 <SPI.h>
  7. #include <SD.h>
  8. const int myInput = AUDIO_INPUT_LINEIN;
  9. // const int myInput = AUDIO_INPUT_MIC;
  10. 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
  11. 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.
  12. int updateFilter[5];
  13. AudioInputI2S audioInput; // audio shield: mic or line-in
  14. AudioFilterBiquad filterTone_L(ToneFilter_L);
  15. AudioFilterBiquad filterTone_R(ToneFilter_R);
  16. AudioOutputI2S audioOutput; // audio shield: headphones & line-out
  17. // Create Audio connections between the components
  18. //
  19. AudioConnection c1(audioInput,0,filterTone_L,0);
  20. AudioConnection c2(audioInput,1,filterTone_R,0);
  21. AudioConnection c3(filterTone_L,0,audioOutput,0);
  22. AudioConnection c4(filterTone_R,0,audioOutput,1);
  23. // Create an object to control the audio shield.
  24. //
  25. AudioControlSGTL5000 audioShield;
  26. void setup() {
  27. // Audio connections require memory to work. For more
  28. // detailed information, see the MemoryAndCpuUsage example
  29. AudioMemory(6);
  30. // Enable the audio shield, select the input and set the output volume.
  31. audioShield.enable();
  32. audioShield.inputSelect(myInput);
  33. audioShield.volume(0.75);
  34. audioShield.unmuteLineout();
  35. calcBiquad(FILTER_PARAEQ,110,0,0.2,2147483648,44100,updateFilter);
  36. filterTone_L.updateCoefs(updateFilter); // default set updateCoefs(0,updateFilter);
  37. filterTone_R.updateCoefs(updateFilter);
  38. calcBiquad(FILTER_PARAEQ,4400,0,0.167,2147483648,44100,updateFilter);
  39. filterTone_L.updateCoefs(1,updateFilter);
  40. filterTone_R.updateCoefs(1,updateFilter);
  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. }