blob: 617b33ab231b34dd01c015216709a192116de408 [file] [log] [blame]
Gregory Maxwellae231142011-07-30 08:18:48 -04001/***********************************************************************
2Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3Redistribution and use in source and binary forms, with or without
4modification, (subject to the limitations in the disclaimer below)
5are permitted provided that the following conditions are met:
6- Redistributions of source code must retain the above copyright notice,
7this list of conditions and the following disclaimer.
8- Redistributions in binary form must reproduce the above copyright
9notice, this list of conditions and the following disclaimer in the
10documentation and/or other materials provided with the distribution.
11- Neither the name of Skype Limited, nor the names of specific
12contributors, may be used to endorse or promote products derived from
13this software without specific prior written permission.
14NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
15BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
16CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26***********************************************************************/
27
28/* *
29 * silk_biquad_alt.c *
30 * *
31 * Second order ARMA filter *
32 * Can handle slowly varying filter coefficients *
33 * */
Jean-Marc Valin5a484122011-08-15 10:49:53 -040034
35#ifdef HAVE_CONFIG_H
36#include "config.h"
37#endif
38
Jean-Marc Valin1c2f5632011-09-16 01:16:53 -070039#include "SigProc_FIX.h"
Gregory Maxwellae231142011-07-30 08:18:48 -040040
41
42/* Second order ARMA filter, alternative implementation */
43void silk_biquad_alt(
44 const opus_int16 *in, /* I: Input signal */
45 const opus_int32 *B_Q28, /* I: MA coefficients [3] */
46 const opus_int32 *A_Q28, /* I: AR coefficients [2] */
47 opus_int32 *S, /* I/O: State vector [2] */
48 opus_int16 *out, /* O: Output signal */
Jean-Marc Valin957f7f12011-09-01 18:02:43 -040049 const opus_int32 len, /* I: Signal length (must be even) */
50 int stride
Gregory Maxwellae231142011-07-30 08:18:48 -040051)
52{
53 /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */
54 opus_int k;
55 opus_int32 inval, A0_U_Q28, A0_L_Q28, A1_U_Q28, A1_L_Q28, out32_Q14;
56
57 /* Negate A_Q28 values and split in two parts */
58 A0_L_Q28 = ( -A_Q28[ 0 ] ) & 0x00003FFF; /* lower part */
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070059 A0_U_Q28 = silk_RSHIFT( -A_Q28[ 0 ], 14 ); /* upper part */
Gregory Maxwellae231142011-07-30 08:18:48 -040060 A1_L_Q28 = ( -A_Q28[ 1 ] ) & 0x00003FFF; /* lower part */
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070061 A1_U_Q28 = silk_RSHIFT( -A_Q28[ 1 ], 14 ); /* upper part */
Gregory Maxwellae231142011-07-30 08:18:48 -040062
63 for( k = 0; k < len; k++ ) {
64 /* S[ 0 ], S[ 1 ]: Q12 */
Jean-Marc Valin957f7f12011-09-01 18:02:43 -040065 inval = in[ k*stride ];
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070066 out32_Q14 = silk_LSHIFT( silk_SMLAWB( S[ 0 ], B_Q28[ 0 ], inval ), 2 );
Gregory Maxwellae231142011-07-30 08:18:48 -040067
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070068 S[ 0 ] = S[1] + silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14, A0_L_Q28 ), 14 );
69 S[ 0 ] = silk_SMLAWB( S[ 0 ], out32_Q14, A0_U_Q28 );
70 S[ 0 ] = silk_SMLAWB( S[ 0 ], B_Q28[ 1 ], inval);
Gregory Maxwellae231142011-07-30 08:18:48 -040071
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070072 S[ 1 ] = silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14, A1_L_Q28 ), 14 );
73 S[ 1 ] = silk_SMLAWB( S[ 1 ], out32_Q14, A1_U_Q28 );
74 S[ 1 ] = silk_SMLAWB( S[ 1 ], B_Q28[ 2 ], inval );
Gregory Maxwellae231142011-07-30 08:18:48 -040075
76 /* Scale back to Q0 and saturate */
Jean-Marc Valinfb3a4372011-09-16 00:58:26 -070077 out[ k*stride ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14 + (1<<14) - 1, 14 ) );
Gregory Maxwellae231142011-07-30 08:18:48 -040078 }
79}