|
1 | 1 | #pragma once
|
2 | 2 | #include "AudioTools/Converter.h"
|
| 3 | +#include <type_traits> |
3 | 4 |
|
4 | 5 | namespace audio_tools {
|
5 | 6 |
|
@@ -57,8 +58,14 @@ class FIR : public Filter<T> {
|
57 | 58 | x[i_b] = value;
|
58 | 59 | T b_terms = 0;
|
59 | 60 | T *b_shift = &coeff_b[lenB - i_b - 1];
|
60 |
| - for (uint8_t i = 0; i < lenB; i++) { |
61 |
| - b_terms += b_shift[i] * x[i] / factor; |
| 61 | + if (std::is_same<T, float>::value || std::is_same<T, double>::value) { |
| 62 | + for (uint8_t i = 0; i < lenB; i++) { |
| 63 | + b_terms += b_shift[i] * x[i] ; |
| 64 | + } |
| 65 | + } else { |
| 66 | + for (uint8_t i = 0; i < lenB; i++) { |
| 67 | + b_terms += b_shift[i] * x[i] / factor; |
| 68 | + } |
62 | 69 | }
|
63 | 70 | i_b++;
|
64 | 71 | if(i_b == lenB)
|
@@ -111,14 +118,26 @@ class IIR : public Filter<T> {
|
111 | 118 | x[i_b] = value;
|
112 | 119 | T b_terms = 0;
|
113 | 120 | T *b_shift = &coeff_b[lenB - i_b - 1];
|
114 |
| - for (uint8_t i = 0; i < lenB; i++) { |
115 |
| - b_terms += x[i] * b_shift[i] / factor; |
116 |
| - } |
| 121 | + |
117 | 122 | T a_terms = 0;
|
118 | 123 | T *a_shift = &coeff_a[lenA - i_a - 1];
|
119 |
| - for (uint8_t i = 0; i < lenA; i++) { |
120 |
| - a_terms += y[i] * a_shift[i] / factor; |
| 124 | + |
| 125 | + if (std::is_same<T, float>::value || std::is_same<T, double>::value) { |
| 126 | + for (uint8_t i = 0; i < lenB; i++) { |
| 127 | + b_terms += x[i] * b_shift[i]; |
| 128 | + } |
| 129 | + for (uint8_t i = 0; i < lenA; i++) { |
| 130 | + a_terms += y[i] * a_shift[i]; |
| 131 | + } |
| 132 | + } else { |
| 133 | + for (uint8_t i = 0; i < lenB; i++) { |
| 134 | + b_terms += x[i] * b_shift[i] / factor; |
| 135 | + } |
| 136 | + for (uint8_t i = 0; i < lenA; i++) { |
| 137 | + a_terms += y[i] * a_shift[i] / factor; |
| 138 | + } |
121 | 139 | }
|
| 140 | + |
122 | 141 | T filtered = b_terms - a_terms;
|
123 | 142 | y[i_a] = filtered;
|
124 | 143 | i_b++;
|
|
0 commit comments