Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: third_party/opus/src/silk/fixed/noise_shape_analysis_FIX.c

Issue 2962373002: [Opus] Update to v1.2.1 (Closed)
Patch Set: Pre-increment instead of post-increment Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /*********************************************************************** 1 /***********************************************************************
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved. 2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3 Redistribution and use in source and binary forms, with or without 3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions 4 modification, are permitted provided that the following conditions
5 are met: 5 are met:
6 - Redistributions of source code must retain the above copyright notice, 6 - Redistributions of source code must retain the above copyright notice,
7 this list of conditions and the following disclaimer. 7 this list of conditions and the following disclaimer.
8 - Redistributions in binary form must reproduce the above copyright 8 - Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the 9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution. 10 documentation and/or other materials provided with the distribution.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 for( i = order - 2; i >= 0; i-- ) { 50 for( i = order - 2; i >= 0; i-- ) {
51 gain_Q24 = silk_SMLAWB( coefs_Q24[ i ], gain_Q24, lambda_Q16 ); 51 gain_Q24 = silk_SMLAWB( coefs_Q24[ i ], gain_Q24, lambda_Q16 );
52 } 52 }
53 gain_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), gain_Q24, -lambda_Q16 ); 53 gain_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), gain_Q24, -lambda_Q16 );
54 return silk_INVERSE32_varQ( gain_Q24, 40 ); 54 return silk_INVERSE32_varQ( gain_Q24, 40 );
55 } 55 }
56 56
57 /* Convert warped filter coefficients to monic pseudo-warped coefficients and li mit maximum */ 57 /* Convert warped filter coefficients to monic pseudo-warped coefficients and li mit maximum */
58 /* amplitude of monic warped coefficients by using bandwidth expansion on the tr ue coefficients */ 58 /* amplitude of monic warped coefficients by using bandwidth expansion on the tr ue coefficients */
59 static OPUS_INLINE void limit_warped_coefs( 59 static OPUS_INLINE void limit_warped_coefs(
60 opus_int32 *coefs_syn_Q24, 60 opus_int32 *coefs_Q24,
61 opus_int32 *coefs_ana_Q24,
62 opus_int lambda_Q16, 61 opus_int lambda_Q16,
63 opus_int32 limit_Q24, 62 opus_int32 limit_Q24,
64 opus_int order 63 opus_int order
65 ) { 64 ) {
66 opus_int i, iter, ind = 0; 65 opus_int i, iter, ind = 0;
67 opus_int32 tmp, maxabs_Q24, chirp_Q16, gain_syn_Q16, gain_ana_Q16; 66 opus_int32 tmp, maxabs_Q24, chirp_Q16, gain_Q16;
68 opus_int32 nom_Q16, den_Q24; 67 opus_int32 nom_Q16, den_Q24;
68 opus_int32 limit_Q20, maxabs_Q20;
69 69
70 /* Convert to monic coefficients */ 70 /* Convert to monic coefficients */
71 lambda_Q16 = -lambda_Q16; 71 lambda_Q16 = -lambda_Q16;
72 for( i = order - 1; i > 0; i-- ) { 72 for( i = order - 1; i > 0; i-- ) {
73 coefs_syn_Q24[ i - 1 ] = silk_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_syn_ Q24[ i ], lambda_Q16 ); 73 coefs_Q24[ i - 1 ] = silk_SMLAWB( coefs_Q24[ i - 1 ], coefs_Q24[ i ], la mbda_Q16 );
74 coefs_ana_Q24[ i - 1 ] = silk_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_ Q24[ i ], lambda_Q16 );
75 } 74 }
76 lambda_Q16 = -lambda_Q16; 75 lambda_Q16 = -lambda_Q16;
77 nom_Q16 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 16 ), -(opus_int32)lambda_Q16, lambda_Q16 ); 76 nom_Q16 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 16 ), -(opus_int32)lambda_Q16, lambda_Q16 );
78 den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_syn_Q24[ 0 ], lambd a_Q16 ); 77 den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_Q24[ 0 ], lambda_Q1 6 );
79 gain_syn_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 ); 78 gain_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 );
80 den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_ana_Q24[ 0 ], lambd a_Q16 );
81 gain_ana_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 );
82 for( i = 0; i < order; i++ ) { 79 for( i = 0; i < order; i++ ) {
83 coefs_syn_Q24[ i ] = silk_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] ); 80 coefs_Q24[ i ] = silk_SMULWW( gain_Q16, coefs_Q24[ i ] );
84 coefs_ana_Q24[ i ] = silk_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] );
85 } 81 }
86 82 limit_Q20 = silk_RSHIFT(limit_Q24, 4);
87 for( iter = 0; iter < 10; iter++ ) { 83 for( iter = 0; iter < 10; iter++ ) {
88 /* Find maximum absolute value */ 84 /* Find maximum absolute value */
89 maxabs_Q24 = -1; 85 maxabs_Q24 = -1;
90 for( i = 0; i < order; i++ ) { 86 for( i = 0; i < order; i++ ) {
91 tmp = silk_max( silk_abs_int32( coefs_syn_Q24[ i ] ), silk_abs_int32 ( coefs_ana_Q24[ i ] ) ); 87 tmp = silk_abs_int32( coefs_Q24[ i ] );
92 if( tmp > maxabs_Q24 ) { 88 if( tmp > maxabs_Q24 ) {
93 maxabs_Q24 = tmp; 89 maxabs_Q24 = tmp;
94 ind = i; 90 ind = i;
95 } 91 }
96 } 92 }
97 if( maxabs_Q24 <= limit_Q24 ) { 93 /* Use Q20 to avoid any overflow when multiplying by (ind + 1) later. */
94 maxabs_Q20 = silk_RSHIFT(maxabs_Q24, 4);
95 if( maxabs_Q20 <= limit_Q20 ) {
98 /* Coefficients are within range - done */ 96 /* Coefficients are within range - done */
99 return; 97 return;
100 } 98 }
101 99
102 /* Convert back to true warped coefficients */ 100 /* Convert back to true warped coefficients */
103 for( i = 1; i < order; i++ ) { 101 for( i = 1; i < order; i++ ) {
104 coefs_syn_Q24[ i - 1 ] = silk_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_ syn_Q24[ i ], lambda_Q16 ); 102 coefs_Q24[ i - 1 ] = silk_SMLAWB( coefs_Q24[ i - 1 ], coefs_Q24[ i ] , lambda_Q16 );
105 coefs_ana_Q24[ i - 1 ] = silk_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ ana_Q24[ i ], lambda_Q16 );
106 } 103 }
107 gain_syn_Q16 = silk_INVERSE32_varQ( gain_syn_Q16, 32 ); 104 gain_Q16 = silk_INVERSE32_varQ( gain_Q16, 32 );
108 gain_ana_Q16 = silk_INVERSE32_varQ( gain_ana_Q16, 32 );
109 for( i = 0; i < order; i++ ) { 105 for( i = 0; i < order; i++ ) {
110 coefs_syn_Q24[ i ] = silk_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] ) ; 106 coefs_Q24[ i ] = silk_SMULWW( gain_Q16, coefs_Q24[ i ] );
111 coefs_ana_Q24[ i ] = silk_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] ) ;
112 } 107 }
113 108
114 /* Apply bandwidth expansion */ 109 /* Apply bandwidth expansion */
115 chirp_Q16 = SILK_FIX_CONST( 0.99, 16 ) - silk_DIV32_varQ( 110 chirp_Q16 = SILK_FIX_CONST( 0.99, 16 ) - silk_DIV32_varQ(
116 silk_SMULWB( maxabs_Q24 - limit_Q24, silk_SMLABB( SILK_FIX_CONST( 0. 8, 10 ), SILK_FIX_CONST( 0.1, 10 ), iter ) ), 111 silk_SMULWB( maxabs_Q20 - limit_Q20, silk_SMLABB( SILK_FIX_CONST( 0. 8, 10 ), SILK_FIX_CONST( 0.1, 10 ), iter ) ),
117 silk_MUL( maxabs_Q24, ind + 1 ), 22 ); 112 silk_MUL( maxabs_Q20, ind + 1 ), 22 );
118 silk_bwexpander_32( coefs_syn_Q24, order, chirp_Q16 ); 113 silk_bwexpander_32( coefs_Q24, order, chirp_Q16 );
119 silk_bwexpander_32( coefs_ana_Q24, order, chirp_Q16 );
120 114
121 /* Convert to monic warped coefficients */ 115 /* Convert to monic warped coefficients */
122 lambda_Q16 = -lambda_Q16; 116 lambda_Q16 = -lambda_Q16;
123 for( i = order - 1; i > 0; i-- ) { 117 for( i = order - 1; i > 0; i-- ) {
124 coefs_syn_Q24[ i - 1 ] = silk_SMLAWB( coefs_syn_Q24[ i - 1 ], coefs_ syn_Q24[ i ], lambda_Q16 ); 118 coefs_Q24[ i - 1 ] = silk_SMLAWB( coefs_Q24[ i - 1 ], coefs_Q24[ i ] , lambda_Q16 );
125 coefs_ana_Q24[ i - 1 ] = silk_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ ana_Q24[ i ], lambda_Q16 );
126 } 119 }
127 lambda_Q16 = -lambda_Q16; 120 lambda_Q16 = -lambda_Q16;
128 nom_Q16 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 16 ), -(opus_int32)lambda_Q 16, lambda_Q16 ); 121 nom_Q16 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 16 ), -(opus_int32)lambda_Q 16, lambda_Q16 );
129 den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_syn_Q24[ 0 ], l ambda_Q16 ); 122 den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_Q24[ 0 ], lambd a_Q16 );
130 gain_syn_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 ); 123 gain_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 );
131 den_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), coefs_ana_Q24[ 0 ], l ambda_Q16 );
132 gain_ana_Q16 = silk_DIV32_varQ( nom_Q16, den_Q24, 24 );
133 for( i = 0; i < order; i++ ) { 124 for( i = 0; i < order; i++ ) {
134 coefs_syn_Q24[ i ] = silk_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] ) ; 125 coefs_Q24[ i ] = silk_SMULWW( gain_Q16, coefs_Q24[ i ] );
135 coefs_ana_Q24[ i ] = silk_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] ) ;
136 } 126 }
137 } 127 }
138 silk_assert( 0 ); 128 silk_assert( 0 );
139 } 129 }
140 130
141 #if defined(MIPSr1_ASM) 131 /* Disable MIPS version until it's updated. */
132 #if 0 && defined(MIPSr1_ASM)
142 #include "mips/noise_shape_analysis_FIX_mipsr1.h" 133 #include "mips/noise_shape_analysis_FIX_mipsr1.h"
143 #endif 134 #endif
144 135
145 /**************************************************************/ 136 /**************************************************************/
146 /* Compute noise shaping coefficients and initial gain values */ 137 /* Compute noise shaping coefficients and initial gain values */
147 /**************************************************************/ 138 /**************************************************************/
148 #ifndef OVERRIDE_silk_noise_shape_analysis_FIX 139 #ifndef OVERRIDE_silk_noise_shape_analysis_FIX
149 void silk_noise_shape_analysis_FIX( 140 void silk_noise_shape_analysis_FIX(
150 silk_encoder_state_FIX *psEnc, /* I /O Encoder state FIX */ 141 silk_encoder_state_FIX *psEnc, /* I /O Encoder state FIX */
151 silk_encoder_control_FIX *psEncCtrl, /* I /O Encoder control FIX */ 142 silk_encoder_control_FIX *psEncCtrl, /* I /O Encoder control FIX */
152 const opus_int16 *pitch_res, /* I LPC residual from pitch analysis */ 143 const opus_int16 *pitch_res, /* I LPC residual from pitch analysis */
153 const opus_int16 *x, /* I Input signal [ frame_length + la_shape ] */ 144 const opus_int16 *x, /* I Input signal [ frame_length + la_shape ] */
154 int arch /* I Run-time architecture */ 145 int arch /* I Run-time architecture */
155 ) 146 )
156 { 147 {
157 silk_shape_state_FIX *psShapeSt = &psEnc->sShape; 148 silk_shape_state_FIX *psShapeSt = &psEnc->sShape;
158 opus_int k, i, nSamples, Qnrg, b_Q14, warping_Q16, scale = 0; 149 opus_int k, i, nSamples, nSegs, Qnrg, b_Q14, warping_Q16, scale = 0;
159 opus_int32 SNR_adj_dB_Q7, HarmBoost_Q16, HarmShapeGain_Q16, Tilt_Q16, tmp3 2; 150 opus_int32 SNR_adj_dB_Q7, HarmShapeGain_Q16, Tilt_Q16, tmp32;
160 opus_int32 nrg, pre_nrg_Q30, log_energy_Q7, log_energy_prev_Q7, energy_var iation_Q7; 151 opus_int32 nrg, log_energy_Q7, log_energy_prev_Q7, energy_variation_Q7;
161 opus_int32 delta_Q16, BWExp1_Q16, BWExp2_Q16, gain_mult_Q16, gain_add_Q16, strength_Q16, b_Q8; 152 opus_int32 BWExp_Q16, gain_mult_Q16, gain_add_Q16, strength_Q16, b_Q8;
162 opus_int32 auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; 153 opus_int32 auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ];
163 opus_int32 refl_coef_Q16[ MAX_SHAPE_LPC_ORDER ]; 154 opus_int32 refl_coef_Q16[ MAX_SHAPE_LPC_ORDER ];
164 opus_int32 AR1_Q24[ MAX_SHAPE_LPC_ORDER ]; 155 opus_int32 AR_Q24[ MAX_SHAPE_LPC_ORDER ];
165 opus_int32 AR2_Q24[ MAX_SHAPE_LPC_ORDER ];
166 VARDECL( opus_int16, x_windowed ); 156 VARDECL( opus_int16, x_windowed );
167 const opus_int16 *x_ptr, *pitch_res_ptr; 157 const opus_int16 *x_ptr, *pitch_res_ptr;
168 SAVE_STACK; 158 SAVE_STACK;
169 159
170 /* Point to start of first LPC analysis block */ 160 /* Point to start of first LPC analysis block */
171 x_ptr = x - psEnc->sCmn.la_shape; 161 x_ptr = x - psEnc->sCmn.la_shape;
172 162
173 /****************/ 163 /****************/
174 /* GAIN CONTROL */ 164 /* GAIN CONTROL */
175 /****************/ 165 /****************/
(...skipping 26 matching lines...) Expand all
202 SILK_FIX_CONST( 1.0, 14 ) - psEncCtrl->input_quality_Q14 ); 192 SILK_FIX_CONST( 1.0, 14 ) - psEncCtrl->input_quality_Q14 );
203 } 193 }
204 194
205 /*************************/ 195 /*************************/
206 /* SPARSENESS PROCESSING */ 196 /* SPARSENESS PROCESSING */
207 /*************************/ 197 /*************************/
208 /* Set quantizer offset */ 198 /* Set quantizer offset */
209 if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { 199 if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) {
210 /* Initially set to 0; may be overruled in process_gains(..) */ 200 /* Initially set to 0; may be overruled in process_gains(..) */
211 psEnc->sCmn.indices.quantOffsetType = 0; 201 psEnc->sCmn.indices.quantOffsetType = 0;
212 psEncCtrl->sparseness_Q8 = 0;
213 } else { 202 } else {
214 /* Sparseness measure, based on relative fluctuations of energy per 2 mi lliseconds */ 203 /* Sparseness measure, based on relative fluctuations of energy per 2 mi lliseconds */
215 nSamples = silk_LSHIFT( psEnc->sCmn.fs_kHz, 1 ); 204 nSamples = silk_LSHIFT( psEnc->sCmn.fs_kHz, 1 );
216 energy_variation_Q7 = 0; 205 energy_variation_Q7 = 0;
217 log_energy_prev_Q7 = 0; 206 log_energy_prev_Q7 = 0;
218 pitch_res_ptr = pitch_res; 207 pitch_res_ptr = pitch_res;
219 for( k = 0; k < silk_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) / 2; k++ ) { 208 nSegs = silk_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) / 2;
209 for( k = 0; k < nSegs; k++ ) {
220 silk_sum_sqr_shift( &nrg, &scale, pitch_res_ptr, nSamples ); 210 silk_sum_sqr_shift( &nrg, &scale, pitch_res_ptr, nSamples );
221 nrg += silk_RSHIFT( nSamples, scale ); /* Q(-scale)*/ 211 nrg += silk_RSHIFT( nSamples, scale ); /* Q(-scale)*/
222 212
223 log_energy_Q7 = silk_lin2log( nrg ); 213 log_energy_Q7 = silk_lin2log( nrg );
224 if( k > 0 ) { 214 if( k > 0 ) {
225 energy_variation_Q7 += silk_abs( log_energy_Q7 - log_energy_prev _Q7 ); 215 energy_variation_Q7 += silk_abs( log_energy_Q7 - log_energy_prev _Q7 );
226 } 216 }
227 log_energy_prev_Q7 = log_energy_Q7; 217 log_energy_prev_Q7 = log_energy_Q7;
228 pitch_res_ptr += nSamples; 218 pitch_res_ptr += nSamples;
229 } 219 }
230 220
231 psEncCtrl->sparseness_Q8 = silk_RSHIFT( silk_sigm_Q15( silk_SMULWB( ener gy_variation_Q7 -
232 SILK_FIX_CONST( 5.0, 7 ), SILK_FIX_CONST( 0.1, 16 ) ) ), 7 );
233
234 /* Set quantization offset depending on sparseness measure */ 221 /* Set quantization offset depending on sparseness measure */
235 if( psEncCtrl->sparseness_Q8 > SILK_FIX_CONST( SPARSENESS_THRESHOLD_QNT_ OFFSET, 8 ) ) { 222 if( energy_variation_Q7 > SILK_FIX_CONST( ENERGY_VARIATION_THRESHOLD_QNT _OFFSET, 7 ) * (nSegs-1) ) {
236 psEnc->sCmn.indices.quantOffsetType = 0; 223 psEnc->sCmn.indices.quantOffsetType = 0;
237 } else { 224 } else {
238 psEnc->sCmn.indices.quantOffsetType = 1; 225 psEnc->sCmn.indices.quantOffsetType = 1;
239 } 226 }
240
241 /* Increase coding SNR for sparse signals */
242 SNR_adj_dB_Q7 = silk_SMLAWB( SNR_adj_dB_Q7, SILK_FIX_CONST( SPARSE_SNR_I NCR_dB, 15 ), psEncCtrl->sparseness_Q8 - SILK_FIX_CONST( 0.5, 8 ) );
243 } 227 }
244 228
245 /*******************************/ 229 /*******************************/
246 /* Control bandwidth expansion */ 230 /* Control bandwidth expansion */
247 /*******************************/ 231 /*******************************/
248 /* More BWE for signals with high prediction gain */ 232 /* More BWE for signals with high prediction gain */
249 strength_Q16 = silk_SMULWB( psEncCtrl->predGain_Q16, SILK_FIX_CONST( FIND_PI TCH_WHITE_NOISE_FRACTION, 16 ) ); 233 strength_Q16 = silk_SMULWB( psEncCtrl->predGain_Q16, SILK_FIX_CONST( FIND_PI TCH_WHITE_NOISE_FRACTION, 16 ) );
250 BWExp1_Q16 = BWExp2_Q16 = silk_DIV32_varQ( SILK_FIX_CONST( BANDWIDTH_EXPANSI ON, 16 ), 234 BWExp_Q16 = silk_DIV32_varQ( SILK_FIX_CONST( BANDWIDTH_EXPANSION, 16 ),
251 silk_SMLAWW( SILK_FIX_CONST( 1.0, 16 ), strength_Q16, strength_Q16 ), 16 ); 235 silk_SMLAWW( SILK_FIX_CONST( 1.0, 16 ), strength_Q16, strength_Q16 ), 16 );
252 delta_Q16 = silk_SMULWB( SILK_FIX_CONST( 1.0, 16 ) - silk_SMULBB( 3, psEncC trl->coding_quality_Q14 ),
253 SILK_FIX_CONST( LOW_RATE_BANDWIDTH_EXPANSION_DELTA, 16 ) );
254 BWExp1_Q16 = silk_SUB32( BWExp1_Q16, delta_Q16 );
255 BWExp2_Q16 = silk_ADD32( BWExp2_Q16, delta_Q16 );
256 /* BWExp1 will be applied after BWExp2, so make it relative */
257 BWExp1_Q16 = silk_DIV32_16( silk_LSHIFT( BWExp1_Q16, 14 ), silk_RSHIFT( BWEx p2_Q16, 2 ) );
258 236
259 if( psEnc->sCmn.warping_Q16 > 0 ) { 237 if( psEnc->sCmn.warping_Q16 > 0 ) {
260 /* Slightly more warping in analysis will move quantization noise up in frequency, where it's better masked */ 238 /* Slightly more warping in analysis will move quantization noise up in frequency, where it's better masked */
261 warping_Q16 = silk_SMLAWB( psEnc->sCmn.warping_Q16, (opus_int32)psEncCtr l->coding_quality_Q14, SILK_FIX_CONST( 0.01, 18 ) ); 239 warping_Q16 = silk_SMLAWB( psEnc->sCmn.warping_Q16, (opus_int32)psEncCtr l->coding_quality_Q14, SILK_FIX_CONST( 0.01, 18 ) );
262 } else { 240 } else {
263 warping_Q16 = 0; 241 warping_Q16 = 0;
264 } 242 }
265 243
266 /********************************************/ 244 /********************************************/
267 /* Compute noise shaping AR coefs and gains */ 245 /* Compute noise shaping AR coefs and gains */
268 /********************************************/ 246 /********************************************/
269 ALLOC( x_windowed, psEnc->sCmn.shapeWinLength, opus_int16 ); 247 ALLOC( x_windowed, psEnc->sCmn.shapeWinLength, opus_int16 );
270 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { 248 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) {
271 /* Apply window: sine slope followed by flat part followed by cosine slo pe */ 249 /* Apply window: sine slope followed by flat part followed by cosine slo pe */
272 opus_int shift, slope_part, flat_part; 250 opus_int shift, slope_part, flat_part;
273 flat_part = psEnc->sCmn.fs_kHz * 3; 251 flat_part = psEnc->sCmn.fs_kHz * 3;
274 slope_part = silk_RSHIFT( psEnc->sCmn.shapeWinLength - flat_part, 1 ); 252 slope_part = silk_RSHIFT( psEnc->sCmn.shapeWinLength - flat_part, 1 );
275 253
276 silk_apply_sine_window( x_windowed, x_ptr, 1, slope_part ); 254 silk_apply_sine_window( x_windowed, x_ptr, 1, slope_part );
277 shift = slope_part; 255 shift = slope_part;
278 silk_memcpy( x_windowed + shift, x_ptr + shift, flat_part * sizeof(opus_ int16) ); 256 silk_memcpy( x_windowed + shift, x_ptr + shift, flat_part * sizeof(opus_ int16) );
279 shift += flat_part; 257 shift += flat_part;
280 silk_apply_sine_window( x_windowed + shift, x_ptr + shift, 2, slope_part ); 258 silk_apply_sine_window( x_windowed + shift, x_ptr + shift, 2, slope_part );
281 259
282 /* Update pointer: next LPC analysis block */ 260 /* Update pointer: next LPC analysis block */
283 x_ptr += psEnc->sCmn.subfr_length; 261 x_ptr += psEnc->sCmn.subfr_length;
284 262
285 if( psEnc->sCmn.warping_Q16 > 0 ) { 263 if( psEnc->sCmn.warping_Q16 > 0 ) {
286 /* Calculate warped auto correlation */ 264 /* Calculate warped auto correlation */
287 silk_warped_autocorrelation_FIX( auto_corr, &scale, x_windowed, warp ing_Q16, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder ); 265 silk_warped_autocorrelation_FIX( auto_corr, &scale, x_windowed, warp ing_Q16, psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder, arch );
288 } else { 266 } else {
289 /* Calculate regular auto correlation */ 267 /* Calculate regular auto correlation */
290 silk_autocorr( auto_corr, &scale, x_windowed, psEnc->sCmn.shapeWinLe ngth, psEnc->sCmn.shapingLPCOrder + 1, arch ); 268 silk_autocorr( auto_corr, &scale, x_windowed, psEnc->sCmn.shapeWinLe ngth, psEnc->sCmn.shapingLPCOrder + 1, arch );
291 } 269 }
292 270
293 /* Add white noise, as a fraction of energy */ 271 /* Add white noise, as a fraction of energy */
294 auto_corr[0] = silk_ADD32( auto_corr[0], silk_max_32( silk_SMULWB( silk_ RSHIFT( auto_corr[ 0 ], 4 ), 272 auto_corr[0] = silk_ADD32( auto_corr[0], silk_max_32( silk_SMULWB( silk_ RSHIFT( auto_corr[ 0 ], 4 ),
295 SILK_FIX_CONST( SHAPE_WHITE_NOISE_FRACTION, 20 ) ), 1 ) ); 273 SILK_FIX_CONST( SHAPE_WHITE_NOISE_FRACTION, 20 ) ), 1 ) );
296 274
297 /* Calculate the reflection coefficients using schur */ 275 /* Calculate the reflection coefficients using schur */
298 nrg = silk_schur64( refl_coef_Q16, auto_corr, psEnc->sCmn.shapingLPCOrde r ); 276 nrg = silk_schur64( refl_coef_Q16, auto_corr, psEnc->sCmn.shapingLPCOrde r );
299 silk_assert( nrg >= 0 ); 277 silk_assert( nrg >= 0 );
300 278
301 /* Convert reflection coefficients to prediction coefficients */ 279 /* Convert reflection coefficients to prediction coefficients */
302 silk_k2a_Q16( AR2_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder ); 280 silk_k2a_Q16( AR_Q24, refl_coef_Q16, psEnc->sCmn.shapingLPCOrder );
303 281
304 Qnrg = -scale; /* range: -12...30*/ 282 Qnrg = -scale; /* range: -12...30*/
305 silk_assert( Qnrg >= -12 ); 283 silk_assert( Qnrg >= -12 );
306 silk_assert( Qnrg <= 30 ); 284 silk_assert( Qnrg <= 30 );
307 285
308 /* Make sure that Qnrg is an even number */ 286 /* Make sure that Qnrg is an even number */
309 if( Qnrg & 1 ) { 287 if( Qnrg & 1 ) {
310 Qnrg -= 1; 288 Qnrg -= 1;
311 nrg >>= 1; 289 nrg >>= 1;
312 } 290 }
313 291
314 tmp32 = silk_SQRT_APPROX( nrg ); 292 tmp32 = silk_SQRT_APPROX( nrg );
315 Qnrg >>= 1; /* range: -6...15*/ 293 Qnrg >>= 1; /* range: -6...15*/
316 294
317 psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT_SAT32( tmp32, 16 - Qnrg ); 295 psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT_SAT32( tmp32, 16 - Qnrg );
318 296
319 if( psEnc->sCmn.warping_Q16 > 0 ) { 297 if( psEnc->sCmn.warping_Q16 > 0 ) {
320 /* Adjust gain for warping */ 298 /* Adjust gain for warping */
321 gain_mult_Q16 = warped_gain( AR2_Q24, warping_Q16, psEnc->sCmn.shapi ngLPCOrder ); 299 gain_mult_Q16 = warped_gain( AR_Q24, warping_Q16, psEnc->sCmn.shapin gLPCOrder );
322 silk_assert( psEncCtrl->Gains_Q16[ k ] >= 0 ); 300 silk_assert( psEncCtrl->Gains_Q16[ k ] > 0 );
323 if ( silk_SMULWW( silk_RSHIFT_ROUND( psEncCtrl->Gains_Q16[ k ], 1 ), gain_mult_Q16 ) >= ( silk_int32_MAX >> 1 ) ) { 301 if( psEncCtrl->Gains_Q16[ k ] < SILK_FIX_CONST( 0.25, 16 ) ) {
324 psEncCtrl->Gains_Q16[ k ] = silk_int32_MAX; 302 psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 );
325 } else { 303 } else {
326 psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k ], gain_mult_Q16 ); 304 psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( silk_RSHIFT_ROUND( psEn cCtrl->Gains_Q16[ k ], 1 ), gain_mult_Q16 );
305 if ( psEncCtrl->Gains_Q16[ k ] >= ( silk_int32_MAX >> 1 ) ) {
306 psEncCtrl->Gains_Q16[ k ] = silk_int32_MAX;
307 } else {
308 psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT32( psEncCtrl->Gains_ Q16[ k ], 1 );
309 }
327 } 310 }
311 silk_assert( psEncCtrl->Gains_Q16[ k ] > 0 );
328 } 312 }
329 313
330 /* Bandwidth expansion for synthesis filter shaping */ 314 /* Bandwidth expansion */
331 silk_bwexpander_32( AR2_Q24, psEnc->sCmn.shapingLPCOrder, BWExp2_Q16 ); 315 silk_bwexpander_32( AR_Q24, psEnc->sCmn.shapingLPCOrder, BWExp_Q16 );
332 316
333 /* Compute noise shaping filter coefficients */ 317 if( psEnc->sCmn.warping_Q16 > 0 ) {
334 silk_memcpy( AR1_Q24, AR2_Q24, psEnc->sCmn.shapingLPCOrder * sizeof( opu s_int32 ) ); 318 /* Convert to monic warped prediction coefficients and limit absolut e values */
319 limit_warped_coefs( AR_Q24, warping_Q16, SILK_FIX_CONST( 3.999, 24 ) , psEnc->sCmn.shapingLPCOrder );
335 320
336 /* Bandwidth expansion for analysis filter shaping */ 321 /* Convert from Q24 to Q13 and store in int16 */
337 silk_assert( BWExp1_Q16 <= SILK_FIX_CONST( 1.0, 16 ) ); 322 for( i = 0; i < psEnc->sCmn.shapingLPCOrder; i++ ) {
338 silk_bwexpander_32( AR1_Q24, psEnc->sCmn.shapingLPCOrder, BWExp1_Q16 ); 323 psEncCtrl->AR_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (opus_int16)s ilk_SAT16( silk_RSHIFT_ROUND( AR_Q24[ i ], 11 ) );
339 324 }
340 /* Ratio of prediction gains, in energy domain */ 325 } else {
341 pre_nrg_Q30 = silk_LPC_inverse_pred_gain_Q24( AR2_Q24, psEnc->sCmn.shapi ngLPCOrder ); 326 silk_LPC_fit( &psEncCtrl->AR_Q13[ k * MAX_SHAPE_LPC_ORDER ], AR_Q24, 13, 24, psEnc->sCmn.shapingLPCOrder );
342 nrg = silk_LPC_inverse_pred_gain_Q24( AR1_Q24, psEnc->sCmn.shapi ngLPCOrder );
343
344 /*psEncCtrl->GainsPre[ k ] = 1.0f - 0.7f * ( 1.0f - pre_nrg / nrg ) = 0. 3f + 0.7f * pre_nrg / nrg;*/
345 pre_nrg_Q30 = silk_LSHIFT32( silk_SMULWB( pre_nrg_Q30, SILK_FIX_CONST( 0 .7, 15 ) ), 1 );
346 psEncCtrl->GainsPre_Q14[ k ] = ( opus_int ) SILK_FIX_CONST( 0.3, 14 ) + silk_DIV32_varQ( pre_nrg_Q30, nrg, 14 );
347
348 /* Convert to monic warped prediction coefficients and limit absolute va lues */
349 limit_warped_coefs( AR2_Q24, AR1_Q24, warping_Q16, SILK_FIX_CONST( 3.999 , 24 ), psEnc->sCmn.shapingLPCOrder );
350
351 /* Convert from Q24 to Q13 and store in int16 */
352 for( i = 0; i < psEnc->sCmn.shapingLPCOrder; i++ ) {
353 psEncCtrl->AR1_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (opus_int16)silk _SAT16( silk_RSHIFT_ROUND( AR1_Q24[ i ], 11 ) );
354 psEncCtrl->AR2_Q13[ k * MAX_SHAPE_LPC_ORDER + i ] = (opus_int16)silk _SAT16( silk_RSHIFT_ROUND( AR2_Q24[ i ], 11 ) );
355 } 327 }
356 } 328 }
357 329
358 /*****************/ 330 /*****************/
359 /* Gain tweaking */ 331 /* Gain tweaking */
360 /*****************/ 332 /*****************/
361 /* Increase gains during low speech activity and put lower limit on gains */ 333 /* Increase gains during low speech activity and put lower limit on gains */
362 gain_mult_Q16 = silk_log2lin( -silk_SMLAWB( -SILK_FIX_CONST( 16.0, 7 ), SNR_ adj_dB_Q7, SILK_FIX_CONST( 0.16, 16 ) ) ); 334 gain_mult_Q16 = silk_log2lin( -silk_SMLAWB( -SILK_FIX_CONST( 16.0, 7 ), SNR_ adj_dB_Q7, SILK_FIX_CONST( 0.16, 16 ) ) );
363 gain_add_Q16 = silk_log2lin( silk_SMLAWB( SILK_FIX_CONST( 16.0, 7 ), SILK _FIX_CONST( MIN_QGAIN_DB, 7 ), SILK_FIX_CONST( 0.16, 16 ) ) ); 335 gain_add_Q16 = silk_log2lin( silk_SMLAWB( SILK_FIX_CONST( 16.0, 7 ), SILK _FIX_CONST( MIN_QGAIN_DB, 7 ), SILK_FIX_CONST( 0.16, 16 ) ) );
364 silk_assert( gain_mult_Q16 > 0 ); 336 silk_assert( gain_mult_Q16 > 0 );
365 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { 337 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) {
366 psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k ], gain _mult_Q16 ); 338 psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k ], gain _mult_Q16 );
367 silk_assert( psEncCtrl->Gains_Q16[ k ] >= 0 ); 339 silk_assert( psEncCtrl->Gains_Q16[ k ] >= 0 );
368 psEncCtrl->Gains_Q16[ k ] = silk_ADD_POS_SAT32( psEncCtrl->Gains_Q16[ k ], gain_add_Q16 ); 340 psEncCtrl->Gains_Q16[ k ] = silk_ADD_POS_SAT32( psEncCtrl->Gains_Q16[ k ], gain_add_Q16 );
369 } 341 }
370 342
371 gain_mult_Q16 = SILK_FIX_CONST( 1.0, 16 ) + silk_RSHIFT_ROUND( silk_MLA( SIL K_FIX_CONST( INPUT_TILT, 26 ),
372 psEncCtrl->coding_quality_Q14, SILK_FIX_CONST( HIGH_RATE_INPUT_TILT, 12 ) ), 10 );
373 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) {
374 psEncCtrl->GainsPre_Q14[ k ] = silk_SMULWB( gain_mult_Q16, psEncCtrl->Ga insPre_Q14[ k ] );
375 }
376 343
377 /************************************************/ 344 /************************************************/
378 /* Control low-frequency shaping and noise tilt */ 345 /* Control low-frequency shaping and noise tilt */
379 /************************************************/ 346 /************************************************/
380 /* Less low frequency shaping for noisy inputs */ 347 /* Less low frequency shaping for noisy inputs */
381 strength_Q16 = silk_MUL( SILK_FIX_CONST( LOW_FREQ_SHAPING, 4 ), silk_SMLAWB( SILK_FIX_CONST( 1.0, 12 ), 348 strength_Q16 = silk_MUL( SILK_FIX_CONST( LOW_FREQ_SHAPING, 4 ), silk_SMLAWB( SILK_FIX_CONST( 1.0, 12 ),
382 SILK_FIX_CONST( LOW_QUALITY_LOW_FREQ_SHAPING_DECR, 13 ), psEnc->sCmn.inp ut_quality_bands_Q15[ 0 ] - SILK_FIX_CONST( 1.0, 15 ) ) ); 349 SILK_FIX_CONST( LOW_QUALITY_LOW_FREQ_SHAPING_DECR, 13 ), psEnc->sCmn.inp ut_quality_bands_Q15[ 0 ] - SILK_FIX_CONST( 1.0, 15 ) ) );
383 strength_Q16 = silk_RSHIFT( silk_MUL( strength_Q16, psEnc->sCmn.speech_activ ity_Q8 ), 8 ); 350 strength_Q16 = silk_RSHIFT( silk_MUL( strength_Q16, psEnc->sCmn.speech_activ ity_Q8 ), 8 );
384 if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { 351 if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) {
385 /* Reduce low frequencies quantization noise for periodic signals, depen ding on pitch lag */ 352 /* Reduce low frequencies quantization noise for periodic signals, depen ding on pitch lag */
(...skipping 17 matching lines...) Expand all
403 psEncCtrl->LF_shp_Q14[ 0 ] |= (opus_uint16)( b_Q14 - SILK_FIX_CONST( 1.0 , 14 ) ); 370 psEncCtrl->LF_shp_Q14[ 0 ] |= (opus_uint16)( b_Q14 - SILK_FIX_CONST( 1.0 , 14 ) );
404 for( k = 1; k < psEnc->sCmn.nb_subfr; k++ ) { 371 for( k = 1; k < psEnc->sCmn.nb_subfr; k++ ) {
405 psEncCtrl->LF_shp_Q14[ k ] = psEncCtrl->LF_shp_Q14[ 0 ]; 372 psEncCtrl->LF_shp_Q14[ k ] = psEncCtrl->LF_shp_Q14[ 0 ];
406 } 373 }
407 Tilt_Q16 = -SILK_FIX_CONST( HP_NOISE_COEF, 16 ); 374 Tilt_Q16 = -SILK_FIX_CONST( HP_NOISE_COEF, 16 );
408 } 375 }
409 376
410 /****************************/ 377 /****************************/
411 /* HARMONIC SHAPING CONTROL */ 378 /* HARMONIC SHAPING CONTROL */
412 /****************************/ 379 /****************************/
413 /* Control boosting of harmonic frequencies */
414 HarmBoost_Q16 = silk_SMULWB( silk_SMULWB( SILK_FIX_CONST( 1.0, 17 ) - silk_L SHIFT( psEncCtrl->coding_quality_Q14, 3 ),
415 psEnc->LTPCorr_Q15 ), SILK_FIX_CONST( LOW_RATE_HARMONIC_BOOST, 16 ) );
416
417 /* More harmonic boost for noisy input signals */
418 HarmBoost_Q16 = silk_SMLAWB( HarmBoost_Q16,
419 SILK_FIX_CONST( 1.0, 16 ) - silk_LSHIFT( psEncCtrl->input_quality_Q14, 2 ), SILK_FIX_CONST( LOW_INPUT_QUALITY_HARMONIC_BOOST, 16 ) );
420
421 if( USE_HARM_SHAPING && psEnc->sCmn.indices.signalType == TYPE_VOICED ) { 380 if( USE_HARM_SHAPING && psEnc->sCmn.indices.signalType == TYPE_VOICED ) {
422 /* More harmonic noise shaping for high bitrates or noisy input */ 381 /* More harmonic noise shaping for high bitrates or noisy input */
423 HarmShapeGain_Q16 = silk_SMLAWB( SILK_FIX_CONST( HARMONIC_SHAPING, 16 ), 382 HarmShapeGain_Q16 = silk_SMLAWB( SILK_FIX_CONST( HARMONIC_SHAPING, 16 ),
424 SILK_FIX_CONST( 1.0, 16 ) - silk_SMULWB( SILK_FIX_CONST( 1.0, 18 ) - silk_LSHIFT( psEncCtrl->coding_quality_Q14, 4 ), 383 SILK_FIX_CONST( 1.0, 16 ) - silk_SMULWB( SILK_FIX_CONST( 1.0, 18 ) - silk_LSHIFT( psEncCtrl->coding_quality_Q14, 4 ),
425 psEncCtrl->input_quality_Q14 ), SILK_FIX_CONST( HIGH_RATE_OR_LOW _QUALITY_HARMONIC_SHAPING, 16 ) ); 384 psEncCtrl->input_quality_Q14 ), SILK_FIX_CONST( HIGH_RATE_OR_LOW _QUALITY_HARMONIC_SHAPING, 16 ) );
426 385
427 /* Less harmonic noise shaping for less periodic signals */ 386 /* Less harmonic noise shaping for less periodic signals */
428 HarmShapeGain_Q16 = silk_SMULWB( silk_LSHIFT( HarmShapeGain_Q16, 1 ), 387 HarmShapeGain_Q16 = silk_SMULWB( silk_LSHIFT( HarmShapeGain_Q16, 1 ),
429 silk_SQRT_APPROX( silk_LSHIFT( psEnc->LTPCorr_Q15, 15 ) ) ); 388 silk_SQRT_APPROX( silk_LSHIFT( psEnc->LTPCorr_Q15, 15 ) ) );
430 } else { 389 } else {
431 HarmShapeGain_Q16 = 0; 390 HarmShapeGain_Q16 = 0;
432 } 391 }
433 392
434 /*************************/ 393 /*************************/
435 /* Smooth over subframes */ 394 /* Smooth over subframes */
436 /*************************/ 395 /*************************/
437 for( k = 0; k < MAX_NB_SUBFR; k++ ) { 396 for( k = 0; k < MAX_NB_SUBFR; k++ ) {
438 psShapeSt->HarmBoost_smth_Q16 =
439 silk_SMLAWB( psShapeSt->HarmBoost_smth_Q16, HarmBoost_Q16 - psShapeSt->HarmBoost_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );
440 psShapeSt->HarmShapeGain_smth_Q16 = 397 psShapeSt->HarmShapeGain_smth_Q16 =
441 silk_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 - psShapeSt->HarmShapeGain_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); 398 silk_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 - psShapeSt->HarmShapeGain_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );
442 psShapeSt->Tilt_smth_Q16 = 399 psShapeSt->Tilt_smth_Q16 =
443 silk_SMLAWB( psShapeSt->Tilt_smth_Q16, Tilt_Q16 - psShapeSt->Tilt_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); 400 silk_SMLAWB( psShapeSt->Tilt_smth_Q16, Tilt_Q16 - psShapeSt->Tilt_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) );
444 401
445 psEncCtrl->HarmBoost_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha peSt->HarmBoost_smth_Q16, 2 );
446 psEncCtrl->HarmShapeGain_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha peSt->HarmShapeGain_smth_Q16, 2 ); 402 psEncCtrl->HarmShapeGain_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha peSt->HarmShapeGain_smth_Q16, 2 );
447 psEncCtrl->Tilt_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha peSt->Tilt_smth_Q16, 2 ); 403 psEncCtrl->Tilt_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha peSt->Tilt_smth_Q16, 2 );
448 } 404 }
449 RESTORE_STACK; 405 RESTORE_STACK;
450 } 406 }
451 #endif /* OVERRIDE_silk_noise_shape_analysis_FIX */ 407 #endif /* OVERRIDE_silk_noise_shape_analysis_FIX */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698