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.

71 lines
1.6KB

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