Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

80 rindas
1.8KB

  1. #include "Audio.h"
  2. #include "arm_math.h"
  3. #include "utility/dspinst.h"
  4. void AudioFilterBiquad::update(void)
  5. {
  6. audio_block_t *block;
  7. int32_t a0, a1, a2, b1, b2, sum;
  8. uint32_t in2, out2, aprev, bprev, flag;
  9. uint32_t *data, *end;
  10. int32_t *state;
  11. block = receiveWritable();
  12. if (!block) return;
  13. data = (uint32_t *)(block->data);
  14. end = data + AUDIO_BLOCK_SAMPLES/2;
  15. state = (int32_t *)definition;
  16. do {
  17. a0 = *state++;
  18. a1 = *state++;
  19. a2 = *state++;
  20. b1 = *state++;
  21. b2 = *state++;
  22. aprev = *state++;
  23. bprev = *state++;
  24. sum = *state & 0x3FFF;
  25. do {
  26. in2 = *data;
  27. sum = signed_multiply_accumulate_32x16b(sum, a0, in2);
  28. sum = signed_multiply_accumulate_32x16t(sum, a1, aprev);
  29. sum = signed_multiply_accumulate_32x16b(sum, a2, aprev);
  30. sum = signed_multiply_accumulate_32x16t(sum, b1, bprev);
  31. sum = signed_multiply_accumulate_32x16b(sum, b2, bprev);
  32. out2 = (uint32_t)sum >> 14;
  33. sum &= 0x3FFF;
  34. sum = signed_multiply_accumulate_32x16t(sum, a0, in2);
  35. sum = signed_multiply_accumulate_32x16b(sum, a1, in2);
  36. sum = signed_multiply_accumulate_32x16t(sum, a2, aprev);
  37. sum = signed_multiply_accumulate_32x16b(sum, b1, out2);
  38. sum = signed_multiply_accumulate_32x16t(sum, b2, bprev);
  39. aprev = in2;
  40. bprev = pack_16x16(sum >> 14, out2);
  41. sum &= 0x3FFF;
  42. aprev = in2;
  43. *data++ = bprev;
  44. } while (data < end);
  45. flag = *state & 0x80000000;
  46. *state++ = sum | flag;
  47. *(state-2) = bprev;
  48. *(state-3) = aprev;
  49. } while (flag);
  50. transmit(block);
  51. release(block);
  52. }
  53. void AudioFilterBiquad::updateCoefs(int *source, bool doReset)
  54. {
  55. int32_t *dest=(int32_t *)definition;
  56. int32_t *src=(int32_t *)source;
  57. __disable_irq();
  58. for(uint8_t index=0;index<5;index++)
  59. {
  60. *dest++=*src++;
  61. }
  62. if(doReset)
  63. {
  64. *dest++=0;
  65. *dest++=0;
  66. *dest++=0;
  67. }
  68. __enable_irq();
  69. }
  70. void AudioFilterBiquad::updateCoefs(int *source)
  71. {
  72. updateCoefs(source,false);
  73. }