diff options
Diffstat (limited to 'lib/rbcodec/codecs/libopus/silk/NLSF2A.c')
-rw-r--r-- | lib/rbcodec/codecs/libopus/silk/NLSF2A.c | 59 |
1 files changed, 11 insertions, 48 deletions
diff --git a/lib/rbcodec/codecs/libopus/silk/NLSF2A.c b/lib/rbcodec/codecs/libopus/silk/NLSF2A.c index b1c559ea68..d5b7730638 100644 --- a/lib/rbcodec/codecs/libopus/silk/NLSF2A.c +++ b/lib/rbcodec/codecs/libopus/silk/NLSF2A.c | |||
@@ -66,7 +66,8 @@ static OPUS_INLINE void silk_NLSF2A_find_poly( | |||
66 | void silk_NLSF2A( | 66 | void silk_NLSF2A( |
67 | opus_int16 *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */ | 67 | opus_int16 *a_Q12, /* O monic whitening filter coefficients in Q12, [ d ] */ |
68 | const opus_int16 *NLSF, /* I normalized line spectral frequencies in Q15, [ d ] */ | 68 | const opus_int16 *NLSF, /* I normalized line spectral frequencies in Q15, [ d ] */ |
69 | const opus_int d /* I filter order (should be even) */ | 69 | const opus_int d, /* I filter order (should be even) */ |
70 | int arch /* I Run-time architecture */ | ||
70 | ) | 71 | ) |
71 | { | 72 | { |
72 | /* This ordering was found to maximize quality. It improves numerical accuracy of | 73 | /* This ordering was found to maximize quality. It improves numerical accuracy of |
@@ -83,15 +84,14 @@ void silk_NLSF2A( | |||
83 | opus_int32 P[ SILK_MAX_ORDER_LPC / 2 + 1 ], Q[ SILK_MAX_ORDER_LPC / 2 + 1 ]; | 84 | opus_int32 P[ SILK_MAX_ORDER_LPC / 2 + 1 ], Q[ SILK_MAX_ORDER_LPC / 2 + 1 ]; |
84 | opus_int32 Ptmp, Qtmp, f_int, f_frac, cos_val, delta; | 85 | opus_int32 Ptmp, Qtmp, f_int, f_frac, cos_val, delta; |
85 | opus_int32 a32_QA1[ SILK_MAX_ORDER_LPC ]; | 86 | opus_int32 a32_QA1[ SILK_MAX_ORDER_LPC ]; |
86 | opus_int32 maxabs, absval, idx=0, sc_Q16; | ||
87 | 87 | ||
88 | silk_assert( LSF_COS_TAB_SZ_FIX == 128 ); | 88 | silk_assert( LSF_COS_TAB_SZ_FIX == 128 ); |
89 | silk_assert( d==10||d==16 ); | 89 | celt_assert( d==10 || d==16 ); |
90 | 90 | ||
91 | /* convert LSFs to 2*cos(LSF), using piecewise linear curve from table */ | 91 | /* convert LSFs to 2*cos(LSF), using piecewise linear curve from table */ |
92 | ordering = d == 16 ? ordering16 : ordering10; | 92 | ordering = d == 16 ? ordering16 : ordering10; |
93 | for( k = 0; k < d; k++ ) { | 93 | for( k = 0; k < d; k++ ) { |
94 | silk_assert(NLSF[k] >= 0 ); | 94 | silk_assert( NLSF[k] >= 0 ); |
95 | 95 | ||
96 | /* f_int on a scale 0-127 (rounded down) */ | 96 | /* f_int on a scale 0-127 (rounded down) */ |
97 | f_int = silk_RSHIFT( NLSF[k], 15 - 7 ); | 97 | f_int = silk_RSHIFT( NLSF[k], 15 - 7 ); |
@@ -126,52 +126,15 @@ void silk_NLSF2A( | |||
126 | a32_QA1[ d-k-1 ] = Qtmp - Ptmp; /* QA+1 */ | 126 | a32_QA1[ d-k-1 ] = Qtmp - Ptmp; /* QA+1 */ |
127 | } | 127 | } |
128 | 128 | ||
129 | /* Limit the maximum absolute value of the prediction coefficients, so that they'll fit in int16 */ | 129 | /* Convert int32 coefficients to Q12 int16 coefs */ |
130 | for( i = 0; i < 10; i++ ) { | 130 | silk_LPC_fit( a_Q12, a32_QA1, 12, QA + 1, d ); |
131 | /* Find maximum absolute value and its index */ | ||
132 | maxabs = 0; | ||
133 | for( k = 0; k < d; k++ ) { | ||
134 | absval = silk_abs( a32_QA1[k] ); | ||
135 | if( absval > maxabs ) { | ||
136 | maxabs = absval; | ||
137 | idx = k; | ||
138 | } | ||
139 | } | ||
140 | maxabs = silk_RSHIFT_ROUND( maxabs, QA + 1 - 12 ); /* QA+1 -> Q12 */ | ||
141 | |||
142 | if( maxabs > silk_int16_MAX ) { | ||
143 | /* Reduce magnitude of prediction coefficients */ | ||
144 | maxabs = silk_min( maxabs, 163838 ); /* ( silk_int32_MAX >> 14 ) + silk_int16_MAX = 163838 */ | ||
145 | sc_Q16 = SILK_FIX_CONST( 0.999, 16 ) - silk_DIV32( silk_LSHIFT( maxabs - silk_int16_MAX, 14 ), | ||
146 | silk_RSHIFT32( silk_MUL( maxabs, idx + 1), 2 ) ); | ||
147 | silk_bwexpander_32( a32_QA1, d, sc_Q16 ); | ||
148 | } else { | ||
149 | break; | ||
150 | } | ||
151 | } | ||
152 | 131 | ||
153 | if( i == 10 ) { | 132 | for( i = 0; silk_LPC_inverse_pred_gain( a_Q12, d, arch ) == 0 && i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) { |
154 | /* Reached the last iteration, clip the coefficients */ | 133 | /* Prediction coefficients are (too close to) unstable; apply bandwidth expansion */ |
134 | /* on the unscaled coefficients, convert to Q12 and measure again */ | ||
135 | silk_bwexpander_32( a32_QA1, d, 65536 - silk_LSHIFT( 2, i ) ); | ||
155 | for( k = 0; k < d; k++ ) { | 136 | for( k = 0; k < d; k++ ) { |
156 | a_Q12[ k ] = (opus_int16)silk_SAT16( silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ) ); /* QA+1 -> Q12 */ | 137 | a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ); /* QA+1 -> Q12 */ |
157 | a32_QA1[ k ] = silk_LSHIFT( (opus_int32)a_Q12[ k ], QA + 1 - 12 ); | ||
158 | } | ||
159 | } else { | ||
160 | for( k = 0; k < d; k++ ) { | ||
161 | a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ); /* QA+1 -> Q12 */ | ||
162 | } | ||
163 | } | ||
164 | |||
165 | for( i = 0; i < MAX_LPC_STABILIZE_ITERATIONS; i++ ) { | ||
166 | if( silk_LPC_inverse_pred_gain( a_Q12, d ) < SILK_FIX_CONST( 1.0 / MAX_PREDICTION_POWER_GAIN, 30 ) ) { | ||
167 | /* Prediction coefficients are (too close to) unstable; apply bandwidth expansion */ | ||
168 | /* on the unscaled coefficients, convert to Q12 and measure again */ | ||
169 | silk_bwexpander_32( a32_QA1, d, 65536 - silk_LSHIFT( 2, i ) ); | ||
170 | for( k = 0; k < d; k++ ) { | ||
171 | a_Q12[ k ] = (opus_int16)silk_RSHIFT_ROUND( a32_QA1[ k ], QA + 1 - 12 ); /* QA+1 -> Q12 */ | ||
172 | } | ||
173 | } else { | ||
174 | break; | ||
175 | } | 138 | } |
176 | } | 139 | } |
177 | } | 140 | } |