STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
arm_biquad_cascade_df1_f32.c
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
3 *
4 * $Date: 19. March 2015
5 * $Revision: V.1.4.5
6 *
7 * Project: CMSIS DSP Library
8 * Title: arm_biquad_cascade_df1_f32.c
9 *
10 * Description: Processing function for the
11 * floating-point Biquad cascade DirectFormI(DF1) filter.
12 *
13 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * - Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * - Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided with the
23 * distribution.
24 * - Neither the name of ARM LIMITED nor the names of its contributors
25 * may be used to endorse or promote products derived from this
26 * software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 * -------------------------------------------------------------------- */
41 
42 #include "arm_math.h"
43 
180  float32_t * pSrc,
181  float32_t * pDst,
182  uint32_t blockSize)
183 {
184  float32_t *pIn = pSrc; /* source pointer */
185  float32_t *pOut = pDst; /* destination pointer */
186  float32_t *pState = S->pState; /* pState pointer */
187  float32_t *pCoeffs = S->pCoeffs; /* coefficient pointer */
188  float32_t acc; /* Simulates the accumulator */
189  float32_t b0, b1, b2, a1, a2; /* Filter coefficients */
190  float32_t Xn1, Xn2, Yn1, Yn2; /* Filter pState variables */
191  float32_t Xn; /* temporary input */
192  uint32_t sample, stage = S->numStages; /* loop counters */
193 
194 
195 #ifndef ARM_MATH_CM0_FAMILY
196 
197  /* Run the below code for Cortex-M4 and Cortex-M3 */
198 
199  do
200  {
201  /* Reading the coefficients */
202  b0 = *pCoeffs++;
203  b1 = *pCoeffs++;
204  b2 = *pCoeffs++;
205  a1 = *pCoeffs++;
206  a2 = *pCoeffs++;
207 
208  /* Reading the pState values */
209  Xn1 = pState[0];
210  Xn2 = pState[1];
211  Yn1 = pState[2];
212  Yn2 = pState[3];
213 
214  /* Apply loop unrolling and compute 4 output values simultaneously. */
215  /* The variable acc hold output values that are being computed:
216  *
217  * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2]
218  * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2]
219  * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2]
220  * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2]
221  */
222 
223  sample = blockSize >> 2u;
224 
225  /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
226  ** a second loop below computes the remaining 1 to 3 samples. */
227  while(sample > 0u)
228  {
229  /* Read the first input */
230  Xn = *pIn++;
231 
232  /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */
233  Yn2 = (b0 * Xn) + (b1 * Xn1) + (b2 * Xn2) + (a1 * Yn1) + (a2 * Yn2);
234 
235  /* Store the result in the accumulator in the destination buffer. */
236  *pOut++ = Yn2;
237 
238  /* Every time after the output is computed state should be updated. */
239  /* The states should be updated as: */
240  /* Xn2 = Xn1 */
241  /* Xn1 = Xn */
242  /* Yn2 = Yn1 */
243  /* Yn1 = acc */
244 
245  /* Read the second input */
246  Xn2 = *pIn++;
247 
248  /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */
249  Yn1 = (b0 * Xn2) + (b1 * Xn) + (b2 * Xn1) + (a1 * Yn2) + (a2 * Yn1);
250 
251  /* Store the result in the accumulator in the destination buffer. */
252  *pOut++ = Yn1;
253 
254  /* Every time after the output is computed state should be updated. */
255  /* The states should be updated as: */
256  /* Xn2 = Xn1 */
257  /* Xn1 = Xn */
258  /* Yn2 = Yn1 */
259  /* Yn1 = acc */
260 
261  /* Read the third input */
262  Xn1 = *pIn++;
263 
264  /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */
265  Yn2 = (b0 * Xn1) + (b1 * Xn2) + (b2 * Xn) + (a1 * Yn1) + (a2 * Yn2);
266 
267  /* Store the result in the accumulator in the destination buffer. */
268  *pOut++ = Yn2;
269 
270  /* Every time after the output is computed state should be updated. */
271  /* The states should be updated as: */
272  /* Xn2 = Xn1 */
273  /* Xn1 = Xn */
274  /* Yn2 = Yn1 */
275  /* Yn1 = acc */
276 
277  /* Read the forth input */
278  Xn = *pIn++;
279 
280  /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */
281  Yn1 = (b0 * Xn) + (b1 * Xn1) + (b2 * Xn2) + (a1 * Yn2) + (a2 * Yn1);
282 
283  /* Store the result in the accumulator in the destination buffer. */
284  *pOut++ = Yn1;
285 
286  /* Every time after the output is computed state should be updated. */
287  /* The states should be updated as: */
288  /* Xn2 = Xn1 */
289  /* Xn1 = Xn */
290  /* Yn2 = Yn1 */
291  /* Yn1 = acc */
292  Xn2 = Xn1;
293  Xn1 = Xn;
294 
295  /* decrement the loop counter */
296  sample--;
297 
298  }
299 
300  /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
301  ** No loop unrolling is used. */
302  sample = blockSize & 0x3u;
303 
304  while(sample > 0u)
305  {
306  /* Read the input */
307  Xn = *pIn++;
308 
309  /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */
310  acc = (b0 * Xn) + (b1 * Xn1) + (b2 * Xn2) + (a1 * Yn1) + (a2 * Yn2);
311 
312  /* Store the result in the accumulator in the destination buffer. */
313  *pOut++ = acc;
314 
315  /* Every time after the output is computed state should be updated. */
316  /* The states should be updated as: */
317  /* Xn2 = Xn1 */
318  /* Xn1 = Xn */
319  /* Yn2 = Yn1 */
320  /* Yn1 = acc */
321  Xn2 = Xn1;
322  Xn1 = Xn;
323  Yn2 = Yn1;
324  Yn1 = acc;
325 
326  /* decrement the loop counter */
327  sample--;
328 
329  }
330 
331  /* Store the updated state variables back into the pState array */
332  *pState++ = Xn1;
333  *pState++ = Xn2;
334  *pState++ = Yn1;
335  *pState++ = Yn2;
336 
337  /* The first stage goes from the input buffer to the output buffer. */
338  /* Subsequent numStages occur in-place in the output buffer */
339  pIn = pDst;
340 
341  /* Reset the output pointer */
342  pOut = pDst;
343 
344  /* decrement the loop counter */
345  stage--;
346 
347  } while(stage > 0u);
348 
349 #else
350 
351  /* Run the below code for Cortex-M0 */
352 
353  do
354  {
355  /* Reading the coefficients */
356  b0 = *pCoeffs++;
357  b1 = *pCoeffs++;
358  b2 = *pCoeffs++;
359  a1 = *pCoeffs++;
360  a2 = *pCoeffs++;
361 
362  /* Reading the pState values */
363  Xn1 = pState[0];
364  Xn2 = pState[1];
365  Yn1 = pState[2];
366  Yn2 = pState[3];
367 
368  /* The variables acc holds the output value that is computed:
369  * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2]
370  */
371 
372  sample = blockSize;
373 
374  while(sample > 0u)
375  {
376  /* Read the input */
377  Xn = *pIn++;
378 
379  /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */
380  acc = (b0 * Xn) + (b1 * Xn1) + (b2 * Xn2) + (a1 * Yn1) + (a2 * Yn2);
381 
382  /* Store the result in the accumulator in the destination buffer. */
383  *pOut++ = acc;
384 
385  /* Every time after the output is computed state should be updated. */
386  /* The states should be updated as: */
387  /* Xn2 = Xn1 */
388  /* Xn1 = Xn */
389  /* Yn2 = Yn1 */
390  /* Yn1 = acc */
391  Xn2 = Xn1;
392  Xn1 = Xn;
393  Yn2 = Yn1;
394  Yn1 = acc;
395 
396  /* decrement the loop counter */
397  sample--;
398  }
399 
400  /* Store the updated state variables back into the pState array */
401  *pState++ = Xn1;
402  *pState++ = Xn2;
403  *pState++ = Yn1;
404  *pState++ = Yn2;
405 
406  /* The first stage goes from the input buffer to the output buffer. */
407  /* Subsequent numStages occur in-place in the output buffer */
408  pIn = pDst;
409 
410  /* Reset the output pointer */
411  pOut = pDst;
412 
413  /* decrement the loop counter */
414  stage--;
415 
416  } while(stage > 0u);
417 
418 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
419 
420 }
421 
422 
float float32_t
32-bit floating-point type definition.
Definition: arm_math.h:407
void arm_biquad_cascade_df1_f32(const arm_biquad_casd_df1_inst_f32 *S, float32_t *pSrc, float32_t *pDst, uint32_t blockSize)
Processing function for the floating-point Biquad cascade filter.
Instance structure for the floating-point Biquad cascade filter.
Definition: arm_math.h:1242