annotate src/opus-1.3/silk/LPC_inv_pred_gain.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 4664ac0c1032
children
rev   line source
cannam@154 1 /***********************************************************************
cannam@154 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
cannam@154 3 Redistribution and use in source and binary forms, with or without
cannam@154 4 modification, are permitted provided that the following conditions
cannam@154 5 are met:
cannam@154 6 - Redistributions of source code must retain the above copyright notice,
cannam@154 7 this list of conditions and the following disclaimer.
cannam@154 8 - Redistributions in binary form must reproduce the above copyright
cannam@154 9 notice, this list of conditions and the following disclaimer in the
cannam@154 10 documentation and/or other materials provided with the distribution.
cannam@154 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the
cannam@154 12 names of specific contributors, may be used to endorse or promote
cannam@154 13 products derived from this software without specific prior written
cannam@154 14 permission.
cannam@154 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
cannam@154 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
cannam@154 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
cannam@154 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
cannam@154 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
cannam@154 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
cannam@154 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
cannam@154 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
cannam@154 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
cannam@154 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
cannam@154 25 POSSIBILITY OF SUCH DAMAGE.
cannam@154 26 ***********************************************************************/
cannam@154 27
cannam@154 28 #ifdef HAVE_CONFIG_H
cannam@154 29 #include "config.h"
cannam@154 30 #endif
cannam@154 31
cannam@154 32 #include "SigProc_FIX.h"
cannam@154 33 #include "define.h"
cannam@154 34
cannam@154 35 #define QA 24
cannam@154 36 #define A_LIMIT SILK_FIX_CONST( 0.99975, QA )
cannam@154 37
cannam@154 38 #define MUL32_FRAC_Q(a32, b32, Q) ((opus_int32)(silk_RSHIFT_ROUND64(silk_SMULL(a32, b32), Q)))
cannam@154 39
cannam@154 40 /* Compute inverse of LPC prediction gain, and */
cannam@154 41 /* test if LPC coefficients are stable (all poles within unit circle) */
cannam@154 42 static opus_int32 LPC_inverse_pred_gain_QA_c( /* O Returns inverse prediction gain in energy domain, Q30 */
cannam@154 43 opus_int32 A_QA[ SILK_MAX_ORDER_LPC ], /* I Prediction coefficients */
cannam@154 44 const opus_int order /* I Prediction order */
cannam@154 45 )
cannam@154 46 {
cannam@154 47 opus_int k, n, mult2Q;
cannam@154 48 opus_int32 invGain_Q30, rc_Q31, rc_mult1_Q30, rc_mult2, tmp1, tmp2;
cannam@154 49
cannam@154 50 invGain_Q30 = SILK_FIX_CONST( 1, 30 );
cannam@154 51 for( k = order - 1; k > 0; k-- ) {
cannam@154 52 /* Check for stability */
cannam@154 53 if( ( A_QA[ k ] > A_LIMIT ) || ( A_QA[ k ] < -A_LIMIT ) ) {
cannam@154 54 return 0;
cannam@154 55 }
cannam@154 56
cannam@154 57 /* Set RC equal to negated AR coef */
cannam@154 58 rc_Q31 = -silk_LSHIFT( A_QA[ k ], 31 - QA );
cannam@154 59
cannam@154 60 /* rc_mult1_Q30 range: [ 1 : 2^30 ] */
cannam@154 61 rc_mult1_Q30 = silk_SUB32( SILK_FIX_CONST( 1, 30 ), silk_SMMUL( rc_Q31, rc_Q31 ) );
cannam@154 62 silk_assert( rc_mult1_Q30 > ( 1 << 15 ) ); /* reduce A_LIMIT if fails */
cannam@154 63 silk_assert( rc_mult1_Q30 <= ( 1 << 30 ) );
cannam@154 64
cannam@154 65 /* Update inverse gain */
cannam@154 66 /* invGain_Q30 range: [ 0 : 2^30 ] */
cannam@154 67 invGain_Q30 = silk_LSHIFT( silk_SMMUL( invGain_Q30, rc_mult1_Q30 ), 2 );
cannam@154 68 silk_assert( invGain_Q30 >= 0 );
cannam@154 69 silk_assert( invGain_Q30 <= ( 1 << 30 ) );
cannam@154 70 if( invGain_Q30 < SILK_FIX_CONST( 1.0f / MAX_PREDICTION_POWER_GAIN, 30 ) ) {
cannam@154 71 return 0;
cannam@154 72 }
cannam@154 73
cannam@154 74 /* rc_mult2 range: [ 2^30 : silk_int32_MAX ] */
cannam@154 75 mult2Q = 32 - silk_CLZ32( silk_abs( rc_mult1_Q30 ) );
cannam@154 76 rc_mult2 = silk_INVERSE32_varQ( rc_mult1_Q30, mult2Q + 30 );
cannam@154 77
cannam@154 78 /* Update AR coefficient */
cannam@154 79 for( n = 0; n < (k + 1) >> 1; n++ ) {
cannam@154 80 opus_int64 tmp64;
cannam@154 81 tmp1 = A_QA[ n ];
cannam@154 82 tmp2 = A_QA[ k - n - 1 ];
cannam@154 83 tmp64 = silk_RSHIFT_ROUND64( silk_SMULL( silk_SUB_SAT32(tmp1,
cannam@154 84 MUL32_FRAC_Q( tmp2, rc_Q31, 31 ) ), rc_mult2 ), mult2Q);
cannam@154 85 if( tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN ) {
cannam@154 86 return 0;
cannam@154 87 }
cannam@154 88 A_QA[ n ] = ( opus_int32 )tmp64;
cannam@154 89 tmp64 = silk_RSHIFT_ROUND64( silk_SMULL( silk_SUB_SAT32(tmp2,
cannam@154 90 MUL32_FRAC_Q( tmp1, rc_Q31, 31 ) ), rc_mult2), mult2Q);
cannam@154 91 if( tmp64 > silk_int32_MAX || tmp64 < silk_int32_MIN ) {
cannam@154 92 return 0;
cannam@154 93 }
cannam@154 94 A_QA[ k - n - 1 ] = ( opus_int32 )tmp64;
cannam@154 95 }
cannam@154 96 }
cannam@154 97
cannam@154 98 /* Check for stability */
cannam@154 99 if( ( A_QA[ k ] > A_LIMIT ) || ( A_QA[ k ] < -A_LIMIT ) ) {
cannam@154 100 return 0;
cannam@154 101 }
cannam@154 102
cannam@154 103 /* Set RC equal to negated AR coef */
cannam@154 104 rc_Q31 = -silk_LSHIFT( A_QA[ 0 ], 31 - QA );
cannam@154 105
cannam@154 106 /* Range: [ 1 : 2^30 ] */
cannam@154 107 rc_mult1_Q30 = silk_SUB32( SILK_FIX_CONST( 1, 30 ), silk_SMMUL( rc_Q31, rc_Q31 ) );
cannam@154 108
cannam@154 109 /* Update inverse gain */
cannam@154 110 /* Range: [ 0 : 2^30 ] */
cannam@154 111 invGain_Q30 = silk_LSHIFT( silk_SMMUL( invGain_Q30, rc_mult1_Q30 ), 2 );
cannam@154 112 silk_assert( invGain_Q30 >= 0 );
cannam@154 113 silk_assert( invGain_Q30 <= ( 1 << 30 ) );
cannam@154 114 if( invGain_Q30 < SILK_FIX_CONST( 1.0f / MAX_PREDICTION_POWER_GAIN, 30 ) ) {
cannam@154 115 return 0;
cannam@154 116 }
cannam@154 117
cannam@154 118 return invGain_Q30;
cannam@154 119 }
cannam@154 120
cannam@154 121 /* For input in Q12 domain */
cannam@154 122 opus_int32 silk_LPC_inverse_pred_gain_c( /* O Returns inverse prediction gain in energy domain, Q30 */
cannam@154 123 const opus_int16 *A_Q12, /* I Prediction coefficients, Q12 [order] */
cannam@154 124 const opus_int order /* I Prediction order */
cannam@154 125 )
cannam@154 126 {
cannam@154 127 opus_int k;
cannam@154 128 opus_int32 Atmp_QA[ SILK_MAX_ORDER_LPC ];
cannam@154 129 opus_int32 DC_resp = 0;
cannam@154 130
cannam@154 131 /* Increase Q domain of the AR coefficients */
cannam@154 132 for( k = 0; k < order; k++ ) {
cannam@154 133 DC_resp += (opus_int32)A_Q12[ k ];
cannam@154 134 Atmp_QA[ k ] = silk_LSHIFT32( (opus_int32)A_Q12[ k ], QA - 12 );
cannam@154 135 }
cannam@154 136 /* If the DC is unstable, we don't even need to do the full calculations */
cannam@154 137 if( DC_resp >= 4096 ) {
cannam@154 138 return 0;
cannam@154 139 }
cannam@154 140 return LPC_inverse_pred_gain_QA_c( Atmp_QA, order );
cannam@154 141 }