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.

filter_fir.cpp 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "filter_fir.h"
  2. void AudioFilterFIR::begin(short *cp,int n_coeffs)
  3. {
  4. // pointer to coefficients
  5. coeff_p = cp;
  6. // Initialize FIR instances for the left and right channels
  7. if(coeff_p && (coeff_p != FIR_PASSTHRU)) {
  8. arm_fir_init_q15(&l_fir_inst, n_coeffs, coeff_p, &l_StateQ15[0], AUDIO_BLOCK_SAMPLES);
  9. arm_fir_init_q15(&r_fir_inst, n_coeffs, coeff_p, &r_StateQ15[0], AUDIO_BLOCK_SAMPLES);
  10. }
  11. }
  12. // This has the same effect as begin(NULL,0);
  13. void AudioFilterFIR::stop(void)
  14. {
  15. coeff_p = NULL;
  16. }
  17. void AudioFilterFIR::update(void)
  18. {
  19. audio_block_t *block,*b_new;
  20. // If there's no coefficient table, give up.
  21. if(coeff_p == NULL)return;
  22. // do passthru
  23. if(coeff_p == FIR_PASSTHRU) {
  24. // Just passthrough
  25. block = receiveWritable(0);
  26. if(block) {
  27. transmit(block,0);
  28. release(block);
  29. }
  30. block = receiveWritable(1);
  31. if(block) {
  32. transmit(block,1);
  33. release(block);
  34. }
  35. return;
  36. }
  37. // Left Channel
  38. block = receiveWritable(0);
  39. // get a block for the FIR output
  40. b_new = allocate();
  41. if(block && b_new) {
  42. arm_fir_q15(&l_fir_inst, (q15_t *)block->data, (q15_t *)b_new->data, AUDIO_BLOCK_SAMPLES);
  43. // send the FIR output to the left channel
  44. transmit(b_new,0);
  45. }
  46. if(block)release(block);
  47. if(b_new)release(b_new);
  48. // Right Channel
  49. block = receiveWritable(1);
  50. b_new = allocate();
  51. if(block && b_new) {
  52. arm_fir_q15(&r_fir_inst, (q15_t *)block->data, (q15_t *)b_new->data, AUDIO_BLOCK_SAMPLES);
  53. transmit(b_new,1);
  54. }
  55. if(block)release(block);
  56. if(b_new)release(b_new);
  57. }