Mercurial > hg > qm-dsp
comparison dsp/rateconversion/Decimator.cpp @ 483:fdaa63607c15
Untabify, indent, tidy
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Fri, 31 May 2019 11:54:32 +0100 |
parents | fac4405e6937 |
children | af5b7ef02aa7 |
comparison
equal
deleted
inserted
replaced
482:cbe668c7d724 | 483:fdaa63607c15 |
---|---|
21 // Construction/Destruction | 21 // Construction/Destruction |
22 ////////////////////////////////////////////////////////////////////// | 22 ////////////////////////////////////////////////////////////////////// |
23 | 23 |
24 Decimator::Decimator( unsigned int inLength, unsigned int decFactor ) | 24 Decimator::Decimator( unsigned int inLength, unsigned int decFactor ) |
25 { | 25 { |
26 | |
27 m_inputLength = 0; | 26 m_inputLength = 0; |
28 m_outputLength = 0; | 27 m_outputLength = 0; |
29 m_decFactor = 1; | 28 m_decFactor = 1; |
30 | 29 |
31 initialise( inLength, decFactor ); | 30 initialise( inLength, decFactor ); |
45 decBuffer = new double[ m_inputLength ]; | 44 decBuffer = new double[ m_inputLength ]; |
46 | 45 |
47 // If adding new factors here, add them to | 46 // If adding new factors here, add them to |
48 // getHighestSupportedFactor in the header as well | 47 // getHighestSupportedFactor in the header as well |
49 | 48 |
50 if(m_decFactor == 8) | 49 if(m_decFactor == 8) { |
51 { | 50 |
52 ////////////////////////////////////////////////// | 51 ////////////////////////////////////////////////// |
53 b[0] = 0.060111378492136; | 52 b[0] = 0.060111378492136; |
54 b[1] = -0.257323420830598; | 53 b[1] = -0.257323420830598; |
55 b[2] = 0.420583503165928; | 54 b[2] = 0.420583503165928; |
56 b[3] = -0.222750785197418; | 55 b[3] = -0.222750785197418; |
66 a[4] = 16.889698874608641; | 65 a[4] = 16.889698874608641; |
67 a[5] = -8.796600612325928; | 66 a[5] = -8.796600612325928; |
68 a[6] = 2.577553446979888; | 67 a[6] = 2.577553446979888; |
69 a[7] = -0.326903916815751; | 68 a[7] = -0.326903916815751; |
70 ////////////////////////////////////////////////// | 69 ////////////////////////////////////////////////// |
71 } | 70 |
72 else if( m_decFactor == 4 ) | 71 } else if( m_decFactor == 4 ) { |
73 { | 72 |
74 ////////////////////////////////////////////////// | 73 ////////////////////////////////////////////////// |
75 b[ 0 ] = 0.10133306904918619; | 74 b[ 0 ] = 0.10133306904918619; |
76 b[ 1 ] = -0.2447523353702363; | 75 b[ 1 ] = -0.2447523353702363; |
77 b[ 2 ] = 0.33622528590120965; | 76 b[ 2 ] = 0.33622528590120965; |
78 b[ 3 ] = -0.13936581560633518; | 77 b[ 3 ] = -0.13936581560633518; |
79 b[ 4 ] = -0.13936581560633382; | 78 b[ 4 ] = -0.13936581560633382; |
80 b[ 5 ] = 0.3362252859012087; | 79 b[ 5 ] = 0.3362252859012087; |
81 b[ 6 ] = -0.2447523353702358; | 80 b[ 6 ] = -0.2447523353702358; |
82 b[ 7 ] = 0.10133306904918594; | 81 b[ 7 ] = 0.10133306904918594; |
83 | 82 |
84 a[ 0 ] = 1; | 83 a[ 0 ] = 1; |
85 a[ 1 ] = -3.9035590278139427; | 84 a[ 1 ] = -3.9035590278139427; |
86 a[ 2 ] = 7.5299379980621133; | 85 a[ 2 ] = 7.5299379980621133; |
87 a[ 3 ] = -8.6890803793177511; | 86 a[ 3 ] = -8.6890803793177511; |
88 a[ 4 ] = 6.4578667096099176; | 87 a[ 4 ] = 6.4578667096099176; |
89 a[ 5 ] = -3.0242979431223631; | 88 a[ 5 ] = -3.0242979431223631; |
90 a[ 6 ] = 0.83043385136748382; | 89 a[ 6 ] = 0.83043385136748382; |
91 a[ 7 ] = -0.094420800837809335; | 90 a[ 7 ] = -0.094420800837809335; |
92 ////////////////////////////////////////////////// | 91 ////////////////////////////////////////////////// |
93 } | 92 |
94 else if( m_decFactor == 2 ) | 93 } else if( m_decFactor == 2 ) { |
95 { | 94 |
96 ////////////////////////////////////////////////// | 95 ////////////////////////////////////////////////// |
97 b[ 0 ] = 0.20898944260075727; | 96 b[ 0 ] = 0.20898944260075727; |
98 b[ 1 ] = 0.40011234879814367; | 97 b[ 1 ] = 0.40011234879814367; |
99 b[ 2 ] = 0.819741973072733; | 98 b[ 2 ] = 0.819741973072733; |
100 b[ 3 ] = 1.0087419911682323; | 99 b[ 3 ] = 1.0087419911682323; |
101 b[ 4 ] = 1.0087419911682325; | 100 b[ 4 ] = 1.0087419911682325; |
102 b[ 5 ] = 0.81974197307273156; | 101 b[ 5 ] = 0.81974197307273156; |
103 b[ 6 ] = 0.40011234879814295; | 102 b[ 6 ] = 0.40011234879814295; |
104 b[ 7 ] = 0.20898944260075661; | 103 b[ 7 ] = 0.20898944260075661; |
105 | 104 |
106 a[ 0 ] = 1; | 105 a[ 0 ] = 1; |
107 a[ 1 ] = 0.0077331184208358217; | 106 a[ 1 ] = 0.0077331184208358217; |
108 a[ 2 ] = 1.9853971155964376; | 107 a[ 2 ] = 1.9853971155964376; |
109 a[ 3 ] = 0.19296739275341004; | 108 a[ 3 ] = 0.19296739275341004; |
110 a[ 4 ] = 1.2330748872852182; | 109 a[ 4 ] = 1.2330748872852182; |
111 a[ 5 ] = 0.18705341389316466; | 110 a[ 5 ] = 0.18705341389316466; |
112 a[ 6 ] = 0.23659265908013868; | 111 a[ 6 ] = 0.23659265908013868; |
113 a[ 7 ] = 0.032352924250533946; | 112 a[ 7 ] = 0.032352924250533946; |
114 } | 113 |
115 else | 114 } else { |
116 { | 115 |
117 if ( m_decFactor != 1 ) { | 116 if ( m_decFactor != 1 ) { |
118 std::cerr << "WARNING: Decimator::initialise: unsupported decimation factor " << m_decFactor << ", no antialiasing filter will be used" << std::endl; | 117 std::cerr << "WARNING: Decimator::initialise: unsupported decimation factor " << m_decFactor << ", no antialiasing filter will be used" << std::endl; |
119 } | 118 } |
120 | 119 |
121 ////////////////////////////////////////////////// | 120 ////////////////////////////////////////////////// |
122 b[ 0 ] = 1; | 121 b[ 0 ] = 1; |
123 b[ 1 ] = 0; | 122 b[ 1 ] = 0; |
124 b[ 2 ] = 0; | 123 b[ 2 ] = 0; |
125 b[ 3 ] = 0; | 124 b[ 3 ] = 0; |
126 b[ 4 ] = 0; | 125 b[ 4 ] = 0; |
127 b[ 5 ] = 0; | 126 b[ 5 ] = 0; |
128 b[ 6 ] = 0; | 127 b[ 6 ] = 0; |
129 b[ 7 ] = 0; | 128 b[ 7 ] = 0; |
130 | 129 |
131 a[ 0 ] = 1; | 130 a[ 0 ] = 1; |
132 a[ 1 ] = 0; | 131 a[ 1 ] = 0; |
133 a[ 2 ] = 0; | 132 a[ 2 ] = 0; |
134 a[ 3 ] = 0; | 133 a[ 3 ] = 0; |
135 a[ 4 ] = 0; | 134 a[ 4 ] = 0; |
136 a[ 5 ] = 0; | 135 a[ 5 ] = 0; |
137 a[ 6 ] = 0; | 136 a[ 6 ] = 0; |
138 a[ 7 ] = 0; | 137 a[ 7 ] = 0; |
139 } | 138 } |
140 | 139 |
141 resetFilter(); | 140 resetFilter(); |
142 } | 141 } |
143 | 142 |
153 o1=o2=o3=o4=o5=o6=o7=0; | 152 o1=o2=o3=o4=o5=o6=o7=0; |
154 } | 153 } |
155 | 154 |
156 void Decimator::doAntiAlias(const double *src, double *dst, unsigned int length) | 155 void Decimator::doAntiAlias(const double *src, double *dst, unsigned int length) |
157 { | 156 { |
158 | 157 for( unsigned int i = 0; i < length; i++ ) { |
159 for( unsigned int i = 0; i < length; i++ ) | 158 |
160 { | 159 Input = (double)src[ i ]; |
161 Input = (double)src[ i ]; | 160 |
162 | 161 Output = Input * b[ 0 ] + o1; |
163 Output = Input * b[ 0 ] + o1; | 162 |
164 | 163 o1 = Input * b[ 1 ] - Output * a[ 1 ] + o2; |
165 o1 = Input * b[ 1 ] - Output * a[ 1 ] + o2; | 164 o2 = Input * b[ 2 ] - Output * a[ 2 ] + o3; |
166 o2 = Input * b[ 2 ] - Output * a[ 2 ] + o3; | 165 o3 = Input * b[ 3 ] - Output * a[ 3 ] + o4; |
167 o3 = Input * b[ 3 ] - Output * a[ 3 ] + o4; | 166 o4 = Input * b[ 4 ] - Output * a[ 4 ] + o5; |
168 o4 = Input * b[ 4 ] - Output * a[ 4 ] + o5; | 167 o5 = Input * b[ 5 ] - Output * a[ 5 ] + o6; |
169 o5 = Input * b[ 5 ] - Output * a[ 5 ] + o6; | 168 o6 = Input * b[ 6 ] - Output * a[ 6 ] + o7; |
170 o6 = Input * b[ 6 ] - Output * a[ 6 ] + o7; | 169 o7 = Input * b[ 7 ] - Output * a[ 7 ] ; |
171 o7 = Input * b[ 7 ] - Output * a[ 7 ] ; | 170 |
172 | 171 dst[ i ] = Output; |
173 dst[ i ] = Output; | 172 } |
174 } | |
175 | |
176 } | 173 } |
177 | 174 |
178 void Decimator::doAntiAlias(const float *src, double *dst, unsigned int length) | 175 void Decimator::doAntiAlias(const float *src, double *dst, unsigned int length) |
179 { | 176 { |
180 | 177 for( unsigned int i = 0; i < length; i++ ) { |
181 for( unsigned int i = 0; i < length; i++ ) | 178 |
182 { | 179 Input = (double)src[ i ]; |
183 Input = (double)src[ i ]; | 180 |
184 | 181 Output = Input * b[ 0 ] + o1; |
185 Output = Input * b[ 0 ] + o1; | 182 |
186 | 183 o1 = Input * b[ 1 ] - Output * a[ 1 ] + o2; |
187 o1 = Input * b[ 1 ] - Output * a[ 1 ] + o2; | 184 o2 = Input * b[ 2 ] - Output * a[ 2 ] + o3; |
188 o2 = Input * b[ 2 ] - Output * a[ 2 ] + o3; | 185 o3 = Input * b[ 3 ] - Output * a[ 3 ] + o4; |
189 o3 = Input * b[ 3 ] - Output * a[ 3 ] + o4; | 186 o4 = Input * b[ 4 ] - Output * a[ 4 ] + o5; |
190 o4 = Input * b[ 4 ] - Output * a[ 4 ] + o5; | 187 o5 = Input * b[ 5 ] - Output * a[ 5 ] + o6; |
191 o5 = Input * b[ 5 ] - Output * a[ 5 ] + o6; | 188 o6 = Input * b[ 6 ] - Output * a[ 6 ] + o7; |
192 o6 = Input * b[ 6 ] - Output * a[ 6 ] + o7; | 189 o7 = Input * b[ 7 ] - Output * a[ 7 ] ; |
193 o7 = Input * b[ 7 ] - Output * a[ 7 ] ; | 190 |
194 | 191 dst[ i ] = Output; |
195 dst[ i ] = Output; | 192 } |
196 } | |
197 | |
198 } | 193 } |
199 | 194 |
200 void Decimator::process(const double *src, double *dst) | 195 void Decimator::process(const double *src, double *dst) |
201 { | 196 { |
202 if (m_decFactor == 1) { | 197 if (m_decFactor == 1) { |
208 | 203 |
209 doAntiAlias( src, decBuffer, m_inputLength ); | 204 doAntiAlias( src, decBuffer, m_inputLength ); |
210 | 205 |
211 unsigned idx = 0; | 206 unsigned idx = 0; |
212 | 207 |
213 for( unsigned int i = 0; i < m_outputLength; i++ ) | 208 for( unsigned int i = 0; i < m_outputLength; i++ ) { |
214 { | 209 dst[ idx++ ] = decBuffer[ m_decFactor * i ]; |
215 dst[ idx++ ] = decBuffer[ m_decFactor * i ]; | |
216 } | 210 } |
217 } | 211 } |
218 | 212 |
219 void Decimator::process(const float *src, float *dst) | 213 void Decimator::process(const float *src, float *dst) |
220 { | 214 { |
227 | 221 |
228 doAntiAlias( src, decBuffer, m_inputLength ); | 222 doAntiAlias( src, decBuffer, m_inputLength ); |
229 | 223 |
230 unsigned idx = 0; | 224 unsigned idx = 0; |
231 | 225 |
232 for( unsigned int i = 0; i < m_outputLength; i++ ) | 226 for( unsigned int i = 0; i < m_outputLength; i++ ) { |
233 { | 227 dst[ idx++ ] = decBuffer[ m_decFactor * i ]; |
234 dst[ idx++ ] = decBuffer[ m_decFactor * i ]; | 228 } |
235 } | 229 } |
236 } |