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.

65 lines
2.2KB

  1. /* Audio Library for Teensy 3.X
  2. * Copyright (c) 2014, Pete (El Supremo)
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. * THE SOFTWARE.
  21. */
  22. #ifndef filter_fir_h_
  23. #define filter_fir_h_
  24. #include "AudioStream.h"
  25. #include "arm_math.h"
  26. // Maximum number of coefficients in a FIR filter
  27. // The audio breaks up with 128 coefficients so a
  28. // maximum of 150 is more than sufficient
  29. #define MAX_COEFFS 150
  30. // Indicates that the code should just pass through the audio
  31. // without any filtering (as opposed to doing nothing at all)
  32. #define FIR_PASSTHRU ((short *) 1)
  33. class AudioFilterFIR :
  34. public AudioStream
  35. {
  36. public:
  37. AudioFilterFIR(void):
  38. AudioStream(2,inputQueueArray), coeff_p(NULL)
  39. {
  40. }
  41. void begin(short *coeff_p,int f_pin);
  42. virtual void update(void);
  43. void stop(void);
  44. private:
  45. audio_block_t *inputQueueArray[2];
  46. // arm state arrays and FIR instances for left and right channels
  47. // the state arrays are defined to handle a maximum of MAX_COEFFS
  48. // coefficients in a filter
  49. q15_t l_StateQ15[AUDIO_BLOCK_SAMPLES + MAX_COEFFS];
  50. q15_t r_StateQ15[AUDIO_BLOCK_SAMPLES + MAX_COEFFS];
  51. arm_fir_instance_q15 l_fir_inst;
  52. arm_fir_instance_q15 r_fir_inst;
  53. // pointer to current coefficients or NULL or FIR_PASSTHRU
  54. short *coeff_p;
  55. };
  56. #endif