annotate src/opus-1.3/silk/biquad_alt.c @ 73:02caadb7509e

Rebuild with --disable-stack-protector for mingw32
author Chris Cannam
date Fri, 25 Jan 2019 14:31:07 +0000
parents 7aeed7906520
children
rev   line source
Chris@69 1 /***********************************************************************
Chris@69 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
Chris@69 3 Redistribution and use in source and binary forms, with or without
Chris@69 4 modification, are permitted provided that the following conditions
Chris@69 5 are met:
Chris@69 6 - Redistributions of source code must retain the above copyright notice,
Chris@69 7 this list of conditions and the following disclaimer.
Chris@69 8 - Redistributions in binary form must reproduce the above copyright
Chris@69 9 notice, this list of conditions and the following disclaimer in the
Chris@69 10 documentation and/or other materials provided with the distribution.
Chris@69 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
Chris@69 12 names of specific contributors, may be used to endorse or promote
Chris@69 13 products derived from this software without specific prior written
Chris@69 14 permission.
Chris@69 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Chris@69 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Chris@69 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Chris@69 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Chris@69 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Chris@69 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Chris@69 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Chris@69 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Chris@69 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Chris@69 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Chris@69 25 POSSIBILITY OF SUCH DAMAGE.
Chris@69 26 ***********************************************************************/
Chris@69 27
Chris@69 28 /* *
Chris@69 29 * silk_biquad_alt.c *
Chris@69 30 * *
Chris@69 31 * Second order ARMA filter *
Chris@69 32 * Can handle slowly varying filter coefficients *
Chris@69 33 * */
Chris@69 34
Chris@69 35 #ifdef HAVE_CONFIG_H
Chris@69 36 #include "config.h"
Chris@69 37 #endif
Chris@69 38
Chris@69 39 #include "SigProc_FIX.h"
Chris@69 40
Chris@69 41 /* Second order ARMA filter, alternative implementation */
Chris@69 42 void silk_biquad_alt_stride1(
Chris@69 43 const opus_int16 *in, /* I input signal */
Chris@69 44 const opus_int32 *B_Q28, /* I MA coefficients [3] */
Chris@69 45 const opus_int32 *A_Q28, /* I AR coefficients [2] */
Chris@69 46 opus_int32 *S, /* I/O State vector [2] */
Chris@69 47 opus_int16 *out, /* O output signal */
Chris@69 48 const opus_int32 len /* I signal length (must be even) */
Chris@69 49 )
Chris@69 50 {
Chris@69 51 /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */
Chris@69 52 opus_int k;
Chris@69 53 opus_int32 inval, A0_U_Q28, A0_L_Q28, A1_U_Q28, A1_L_Q28, out32_Q14;
Chris@69 54
Chris@69 55 /* Negate A_Q28 values and split in two parts */
Chris@69 56 A0_L_Q28 = ( -A_Q28[ 0 ] ) & 0x00003FFF; /* lower part */
Chris@69 57 A0_U_Q28 = silk_RSHIFT( -A_Q28[ 0 ], 14 ); /* upper part */
Chris@69 58 A1_L_Q28 = ( -A_Q28[ 1 ] ) & 0x00003FFF; /* lower part */
Chris@69 59 A1_U_Q28 = silk_RSHIFT( -A_Q28[ 1 ], 14 ); /* upper part */
Chris@69 60
Chris@69 61 for( k = 0; k < len; k++ ) {
Chris@69 62 /* S[ 0 ], S[ 1 ]: Q12 */
Chris@69 63 inval = in[ k ];
Chris@69 64 out32_Q14 = silk_LSHIFT( silk_SMLAWB( S[ 0 ], B_Q28[ 0 ], inval ), 2 );
Chris@69 65
Chris@69 66 S[ 0 ] = S[1] + silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14, A0_L_Q28 ), 14 );
Chris@69 67 S[ 0 ] = silk_SMLAWB( S[ 0 ], out32_Q14, A0_U_Q28 );
Chris@69 68 S[ 0 ] = silk_SMLAWB( S[ 0 ], B_Q28[ 1 ], inval);
Chris@69 69
Chris@69 70 S[ 1 ] = silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14, A1_L_Q28 ), 14 );
Chris@69 71 S[ 1 ] = silk_SMLAWB( S[ 1 ], out32_Q14, A1_U_Q28 );
Chris@69 72 S[ 1 ] = silk_SMLAWB( S[ 1 ], B_Q28[ 2 ], inval );
Chris@69 73
Chris@69 74 /* Scale back to Q0 and saturate */
Chris@69 75 out[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14 + (1<<14) - 1, 14 ) );
Chris@69 76 }
Chris@69 77 }
Chris@69 78
Chris@69 79 void silk_biquad_alt_stride2_c(
Chris@69 80 const opus_int16 *in, /* I input signal */
Chris@69 81 const opus_int32 *B_Q28, /* I MA coefficients [3] */
Chris@69 82 const opus_int32 *A_Q28, /* I AR coefficients [2] */
Chris@69 83 opus_int32 *S, /* I/O State vector [4] */
Chris@69 84 opus_int16 *out, /* O output signal */
Chris@69 85 const opus_int32 len /* I signal length (must be even) */
Chris@69 86 )
Chris@69 87 {
Chris@69 88 /* DIRECT FORM II TRANSPOSED (uses 2 element state vector) */
Chris@69 89 opus_int k;
Chris@69 90 opus_int32 A0_U_Q28, A0_L_Q28, A1_U_Q28, A1_L_Q28, out32_Q14[ 2 ];
Chris@69 91
Chris@69 92 /* Negate A_Q28 values and split in two parts */
Chris@69 93 A0_L_Q28 = ( -A_Q28[ 0 ] ) & 0x00003FFF; /* lower part */
Chris@69 94 A0_U_Q28 = silk_RSHIFT( -A_Q28[ 0 ], 14 ); /* upper part */
Chris@69 95 A1_L_Q28 = ( -A_Q28[ 1 ] ) & 0x00003FFF; /* lower part */
Chris@69 96 A1_U_Q28 = silk_RSHIFT( -A_Q28[ 1 ], 14 ); /* upper part */
Chris@69 97
Chris@69 98 for( k = 0; k < len; k++ ) {
Chris@69 99 /* S[ 0 ], S[ 1 ], S[ 2 ], S[ 3 ]: Q12 */
Chris@69 100 out32_Q14[ 0 ] = silk_LSHIFT( silk_SMLAWB( S[ 0 ], B_Q28[ 0 ], in[ 2 * k + 0 ] ), 2 );
Chris@69 101 out32_Q14[ 1 ] = silk_LSHIFT( silk_SMLAWB( S[ 2 ], B_Q28[ 0 ], in[ 2 * k + 1 ] ), 2 );
Chris@69 102
Chris@69 103 S[ 0 ] = S[ 1 ] + silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 0 ], A0_L_Q28 ), 14 );
Chris@69 104 S[ 2 ] = S[ 3 ] + silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 1 ], A0_L_Q28 ), 14 );
Chris@69 105 S[ 0 ] = silk_SMLAWB( S[ 0 ], out32_Q14[ 0 ], A0_U_Q28 );
Chris@69 106 S[ 2 ] = silk_SMLAWB( S[ 2 ], out32_Q14[ 1 ], A0_U_Q28 );
Chris@69 107 S[ 0 ] = silk_SMLAWB( S[ 0 ], B_Q28[ 1 ], in[ 2 * k + 0 ] );
Chris@69 108 S[ 2 ] = silk_SMLAWB( S[ 2 ], B_Q28[ 1 ], in[ 2 * k + 1 ] );
Chris@69 109
Chris@69 110 S[ 1 ] = silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 0 ], A1_L_Q28 ), 14 );
Chris@69 111 S[ 3 ] = silk_RSHIFT_ROUND( silk_SMULWB( out32_Q14[ 1 ], A1_L_Q28 ), 14 );
Chris@69 112 S[ 1 ] = silk_SMLAWB( S[ 1 ], out32_Q14[ 0 ], A1_U_Q28 );
Chris@69 113 S[ 3 ] = silk_SMLAWB( S[ 3 ], out32_Q14[ 1 ], A1_U_Q28 );
Chris@69 114 S[ 1 ] = silk_SMLAWB( S[ 1 ], B_Q28[ 2 ], in[ 2 * k + 0 ] );
Chris@69 115 S[ 3 ] = silk_SMLAWB( S[ 3 ], B_Q28[ 2 ], in[ 2 * k + 1 ] );
Chris@69 116
Chris@69 117 /* Scale back to Q0 and saturate */
Chris@69 118 out[ 2 * k + 0 ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14[ 0 ] + (1<<14) - 1, 14 ) );
Chris@69 119 out[ 2 * k + 1 ] = (opus_int16)silk_SAT16( silk_RSHIFT( out32_Q14[ 1 ] + (1<<14) - 1, 14 ) );
Chris@69 120 }
Chris@69 121 }