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.

76 lines
2.4KB

  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. #include "filter_fir.h"
  23. void AudioFilterFIR::begin(short *cp,int n_coeffs)
  24. {
  25. // pointer to coefficients
  26. coeff_p = cp;
  27. // Initialize FIR instances for the left and right channels
  28. if(coeff_p && (coeff_p != FIR_PASSTHRU)) {
  29. arm_fir_init_q15(&l_fir_inst, n_coeffs, coeff_p, &l_StateQ15[0], AUDIO_BLOCK_SAMPLES);
  30. }
  31. }
  32. // This has the same effect as begin(NULL,0);
  33. void AudioFilterFIR::stop(void)
  34. {
  35. coeff_p = NULL;
  36. }
  37. void AudioFilterFIR::update(void)
  38. {
  39. audio_block_t *block,*b_new;
  40. // If there's no coefficient table, give up.
  41. if(coeff_p == NULL)return;
  42. // do passthru
  43. if(coeff_p == FIR_PASSTHRU) {
  44. // Just passthrough
  45. block = receiveReadOnly(0);
  46. if(block) {
  47. transmit(block,0);
  48. release(block);
  49. }
  50. return;
  51. }
  52. // Left Channel
  53. block = receiveReadOnly(0);
  54. // get a block for the FIR output
  55. b_new = allocate();
  56. if(block && b_new) {
  57. if(arm_fast)
  58. arm_fir_fast_q15(&l_fir_inst, (q15_t *)block->data, (q15_t *)b_new->data, AUDIO_BLOCK_SAMPLES);
  59. else
  60. arm_fir_q15(&l_fir_inst, (q15_t *)block->data, (q15_t *)b_new->data, AUDIO_BLOCK_SAMPLES);
  61. // send the FIR output to the left channel
  62. transmit(b_new,0);
  63. }
  64. if(block)release(block);
  65. if(b_new)release(b_new);
  66. }