OLD | NEW |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 gain = coefs[ order - 1 ]; | 48 gain = coefs[ order - 1 ]; |
49 for( i = order - 2; i >= 0; i-- ) { | 49 for( i = order - 2; i >= 0; i-- ) { |
50 gain = lambda * gain + coefs[ i ]; | 50 gain = lambda * gain + coefs[ i ]; |
51 } | 51 } |
52 return (silk_float)( 1.0f / ( 1.0f - lambda * gain ) ); | 52 return (silk_float)( 1.0f / ( 1.0f - lambda * gain ) ); |
53 } | 53 } |
54 | 54 |
55 /* Convert warped filter coefficients to monic pseudo-warped coefficients and li
mit maximum */ | 55 /* Convert warped filter coefficients to monic pseudo-warped coefficients and li
mit maximum */ |
56 /* amplitude of monic warped coefficients by using bandwidth expansion on the tr
ue coefficients */ | 56 /* amplitude of monic warped coefficients by using bandwidth expansion on the tr
ue coefficients */ |
57 static OPUS_INLINE void warped_true2monic_coefs( | 57 static OPUS_INLINE void warped_true2monic_coefs( |
58 silk_float *coefs_syn, | 58 silk_float *coefs, |
59 silk_float *coefs_ana, | |
60 silk_float lambda, | 59 silk_float lambda, |
61 silk_float limit, | 60 silk_float limit, |
62 opus_int order | 61 opus_int order |
63 ) { | 62 ) { |
64 opus_int i, iter, ind = 0; | 63 opus_int i, iter, ind = 0; |
65 silk_float tmp, maxabs, chirp, gain_syn, gain_ana; | 64 silk_float tmp, maxabs, chirp, gain; |
66 | 65 |
67 /* Convert to monic coefficients */ | 66 /* Convert to monic coefficients */ |
68 for( i = order - 1; i > 0; i-- ) { | 67 for( i = order - 1; i > 0; i-- ) { |
69 coefs_syn[ i - 1 ] -= lambda * coefs_syn[ i ]; | 68 coefs[ i - 1 ] -= lambda * coefs[ i ]; |
70 coefs_ana[ i - 1 ] -= lambda * coefs_ana[ i ]; | |
71 } | 69 } |
72 gain_syn = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs_syn[ 0 ] ); | 70 gain = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs[ 0 ] ); |
73 gain_ana = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs_ana[ 0 ] ); | |
74 for( i = 0; i < order; i++ ) { | 71 for( i = 0; i < order; i++ ) { |
75 coefs_syn[ i ] *= gain_syn; | 72 coefs[ i ] *= gain; |
76 coefs_ana[ i ] *= gain_ana; | |
77 } | 73 } |
78 | 74 |
79 /* Limit */ | 75 /* Limit */ |
80 for( iter = 0; iter < 10; iter++ ) { | 76 for( iter = 0; iter < 10; iter++ ) { |
81 /* Find maximum absolute value */ | 77 /* Find maximum absolute value */ |
82 maxabs = -1.0f; | 78 maxabs = -1.0f; |
83 for( i = 0; i < order; i++ ) { | 79 for( i = 0; i < order; i++ ) { |
84 tmp = silk_max( silk_abs_float( coefs_syn[ i ] ), silk_abs_float( co
efs_ana[ i ] ) ); | 80 tmp = silk_abs_float( coefs[ i ] ); |
85 if( tmp > maxabs ) { | 81 if( tmp > maxabs ) { |
86 maxabs = tmp; | 82 maxabs = tmp; |
87 ind = i; | 83 ind = i; |
88 } | 84 } |
89 } | 85 } |
90 if( maxabs <= limit ) { | 86 if( maxabs <= limit ) { |
91 /* Coefficients are within range - done */ | 87 /* Coefficients are within range - done */ |
92 return; | 88 return; |
93 } | 89 } |
94 | 90 |
95 /* Convert back to true warped coefficients */ | 91 /* Convert back to true warped coefficients */ |
96 for( i = 1; i < order; i++ ) { | 92 for( i = 1; i < order; i++ ) { |
97 coefs_syn[ i - 1 ] += lambda * coefs_syn[ i ]; | 93 coefs[ i - 1 ] += lambda * coefs[ i ]; |
98 coefs_ana[ i - 1 ] += lambda * coefs_ana[ i ]; | |
99 } | 94 } |
100 gain_syn = 1.0f / gain_syn; | 95 gain = 1.0f / gain; |
101 gain_ana = 1.0f / gain_ana; | |
102 for( i = 0; i < order; i++ ) { | 96 for( i = 0; i < order; i++ ) { |
103 coefs_syn[ i ] *= gain_syn; | 97 coefs[ i ] *= gain; |
104 coefs_ana[ i ] *= gain_ana; | |
105 } | 98 } |
106 | 99 |
107 /* Apply bandwidth expansion */ | 100 /* Apply bandwidth expansion */ |
108 chirp = 0.99f - ( 0.8f + 0.1f * iter ) * ( maxabs - limit ) / ( maxabs *
( ind + 1 ) ); | 101 chirp = 0.99f - ( 0.8f + 0.1f * iter ) * ( maxabs - limit ) / ( maxabs *
( ind + 1 ) ); |
109 silk_bwexpander_FLP( coefs_syn, order, chirp ); | 102 silk_bwexpander_FLP( coefs, order, chirp ); |
110 silk_bwexpander_FLP( coefs_ana, order, chirp ); | |
111 | 103 |
112 /* Convert to monic warped coefficients */ | 104 /* Convert to monic warped coefficients */ |
113 for( i = order - 1; i > 0; i-- ) { | 105 for( i = order - 1; i > 0; i-- ) { |
114 coefs_syn[ i - 1 ] -= lambda * coefs_syn[ i ]; | 106 coefs[ i - 1 ] -= lambda * coefs[ i ]; |
115 coefs_ana[ i - 1 ] -= lambda * coefs_ana[ i ]; | |
116 } | 107 } |
117 gain_syn = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs_syn[ 0 ]
); | 108 gain = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs[ 0 ] ); |
118 gain_ana = ( 1.0f - lambda * lambda ) / ( 1.0f + lambda * coefs_ana[ 0 ]
); | |
119 for( i = 0; i < order; i++ ) { | 109 for( i = 0; i < order; i++ ) { |
120 coefs_syn[ i ] *= gain_syn; | 110 coefs[ i ] *= gain; |
121 coefs_ana[ i ] *= gain_ana; | |
122 } | 111 } |
123 } | 112 } |
124 silk_assert( 0 ); | 113 silk_assert( 0 ); |
125 } | 114 } |
126 | 115 |
| 116 static OPUS_INLINE void limit_coefs( |
| 117 silk_float *coefs, |
| 118 silk_float limit, |
| 119 opus_int order |
| 120 ) { |
| 121 opus_int i, iter, ind = 0; |
| 122 silk_float tmp, maxabs, chirp; |
| 123 |
| 124 for( iter = 0; iter < 10; iter++ ) { |
| 125 /* Find maximum absolute value */ |
| 126 maxabs = -1.0f; |
| 127 for( i = 0; i < order; i++ ) { |
| 128 tmp = silk_abs_float( coefs[ i ] ); |
| 129 if( tmp > maxabs ) { |
| 130 maxabs = tmp; |
| 131 ind = i; |
| 132 } |
| 133 } |
| 134 if( maxabs <= limit ) { |
| 135 /* Coefficients are within range - done */ |
| 136 return; |
| 137 } |
| 138 |
| 139 /* Apply bandwidth expansion */ |
| 140 chirp = 0.99f - ( 0.8f + 0.1f * iter ) * ( maxabs - limit ) / ( maxabs *
( ind + 1 ) ); |
| 141 silk_bwexpander_FLP( coefs, order, chirp ); |
| 142 } |
| 143 silk_assert( 0 ); |
| 144 } |
| 145 |
127 /* Compute noise shaping coefficients and initial gain values */ | 146 /* Compute noise shaping coefficients and initial gain values */ |
128 void silk_noise_shape_analysis_FLP( | 147 void silk_noise_shape_analysis_FLP( |
129 silk_encoder_state_FLP *psEnc, /* I/O
Encoder state FLP */ | 148 silk_encoder_state_FLP *psEnc, /* I/O
Encoder state FLP */ |
130 silk_encoder_control_FLP *psEncCtrl, /* I/O
Encoder control FLP */ | 149 silk_encoder_control_FLP *psEncCtrl, /* I/O
Encoder control FLP */ |
131 const silk_float *pitch_res, /* I
LPC residual from pitch analysis */ | 150 const silk_float *pitch_res, /* I
LPC residual from pitch analysis */ |
132 const silk_float *x /* I
Input signal [frame_length + la_shape] */ | 151 const silk_float *x /* I
Input signal [frame_length + la_shape] */ |
133 ) | 152 ) |
134 { | 153 { |
135 silk_shape_state_FLP *psShapeSt = &psEnc->sShape; | 154 silk_shape_state_FLP *psShapeSt = &psEnc->sShape; |
136 opus_int k, nSamples; | 155 opus_int k, nSamples, nSegs; |
137 silk_float SNR_adj_dB, HarmBoost, HarmShapeGain, Tilt; | 156 silk_float SNR_adj_dB, HarmShapeGain, Tilt; |
138 silk_float nrg, pre_nrg, log_energy, log_energy_prev, energy_variation; | 157 silk_float nrg, log_energy, log_energy_prev, energy_variation; |
139 silk_float delta, BWExp1, BWExp2, gain_mult, gain_add, strength, b, warpin
g; | 158 silk_float BWExp, gain_mult, gain_add, strength, b, warping; |
140 silk_float x_windowed[ SHAPE_LPC_WIN_MAX ]; | 159 silk_float x_windowed[ SHAPE_LPC_WIN_MAX ]; |
141 silk_float auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; | 160 silk_float auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; |
| 161 silk_float rc[ MAX_SHAPE_LPC_ORDER + 1 ]; |
142 const silk_float *x_ptr, *pitch_res_ptr; | 162 const silk_float *x_ptr, *pitch_res_ptr; |
143 | 163 |
144 /* Point to start of first LPC analysis block */ | 164 /* Point to start of first LPC analysis block */ |
145 x_ptr = x - psEnc->sCmn.la_shape; | 165 x_ptr = x - psEnc->sCmn.la_shape; |
146 | 166 |
147 /****************/ | 167 /****************/ |
148 /* GAIN CONTROL */ | 168 /* GAIN CONTROL */ |
149 /****************/ | 169 /****************/ |
150 SNR_adj_dB = psEnc->sCmn.SNR_dB_Q7 * ( 1 / 128.0f ); | 170 SNR_adj_dB = psEnc->sCmn.SNR_dB_Q7 * ( 1 / 128.0f ); |
151 | 171 |
(...skipping 17 matching lines...) Expand all Loading... |
169 SNR_adj_dB += ( -0.4f * psEnc->sCmn.SNR_dB_Q7 * ( 1 / 128.0f ) + 6.0f )
* ( 1.0f - psEncCtrl->input_quality ); | 189 SNR_adj_dB += ( -0.4f * psEnc->sCmn.SNR_dB_Q7 * ( 1 / 128.0f ) + 6.0f )
* ( 1.0f - psEncCtrl->input_quality ); |
170 } | 190 } |
171 | 191 |
172 /*************************/ | 192 /*************************/ |
173 /* SPARSENESS PROCESSING */ | 193 /* SPARSENESS PROCESSING */ |
174 /*************************/ | 194 /*************************/ |
175 /* Set quantizer offset */ | 195 /* Set quantizer offset */ |
176 if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | 196 if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { |
177 /* Initially set to 0; may be overruled in process_gains(..) */ | 197 /* Initially set to 0; may be overruled in process_gains(..) */ |
178 psEnc->sCmn.indices.quantOffsetType = 0; | 198 psEnc->sCmn.indices.quantOffsetType = 0; |
179 psEncCtrl->sparseness = 0.0f; | |
180 } else { | 199 } else { |
181 /* Sparseness measure, based on relative fluctuations of energy per 2 mi
lliseconds */ | 200 /* Sparseness measure, based on relative fluctuations of energy per 2 mi
lliseconds */ |
182 nSamples = 2 * psEnc->sCmn.fs_kHz; | 201 nSamples = 2 * psEnc->sCmn.fs_kHz; |
183 energy_variation = 0.0f; | 202 energy_variation = 0.0f; |
184 log_energy_prev = 0.0f; | 203 log_energy_prev = 0.0f; |
185 pitch_res_ptr = pitch_res; | 204 pitch_res_ptr = pitch_res; |
186 for( k = 0; k < silk_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr )
/ 2; k++ ) { | 205 nSegs = silk_SMULBB( SUB_FRAME_LENGTH_MS, psEnc->sCmn.nb_subfr ) / 2; |
| 206 for( k = 0; k < nSegs; k++ ) { |
187 nrg = ( silk_float )nSamples + ( silk_float )silk_energy_FLP( pitch_
res_ptr, nSamples ); | 207 nrg = ( silk_float )nSamples + ( silk_float )silk_energy_FLP( pitch_
res_ptr, nSamples ); |
188 log_energy = silk_log2( nrg ); | 208 log_energy = silk_log2( nrg ); |
189 if( k > 0 ) { | 209 if( k > 0 ) { |
190 energy_variation += silk_abs_float( log_energy - log_energy_prev
); | 210 energy_variation += silk_abs_float( log_energy - log_energy_prev
); |
191 } | 211 } |
192 log_energy_prev = log_energy; | 212 log_energy_prev = log_energy; |
193 pitch_res_ptr += nSamples; | 213 pitch_res_ptr += nSamples; |
194 } | 214 } |
195 psEncCtrl->sparseness = silk_sigmoid( 0.4f * ( energy_variation - 5.0f )
); | |
196 | 215 |
197 /* Set quantization offset depending on sparseness measure */ | 216 /* Set quantization offset depending on sparseness measure */ |
198 if( psEncCtrl->sparseness > SPARSENESS_THRESHOLD_QNT_OFFSET ) { | 217 if( energy_variation > ENERGY_VARIATION_THRESHOLD_QNT_OFFSET * (nSegs-1)
) { |
199 psEnc->sCmn.indices.quantOffsetType = 0; | 218 psEnc->sCmn.indices.quantOffsetType = 0; |
200 } else { | 219 } else { |
201 psEnc->sCmn.indices.quantOffsetType = 1; | 220 psEnc->sCmn.indices.quantOffsetType = 1; |
202 } | 221 } |
203 | |
204 /* Increase coding SNR for sparse signals */ | |
205 SNR_adj_dB += SPARSE_SNR_INCR_dB * ( psEncCtrl->sparseness - 0.5f ); | |
206 } | 222 } |
207 | 223 |
208 /*******************************/ | 224 /*******************************/ |
209 /* Control bandwidth expansion */ | 225 /* Control bandwidth expansion */ |
210 /*******************************/ | 226 /*******************************/ |
211 /* More BWE for signals with high prediction gain */ | 227 /* More BWE for signals with high prediction gain */ |
212 strength = FIND_PITCH_WHITE_NOISE_FRACTION * psEncCtrl->predGain;
/* between 0.0 and 1.0 */ | 228 strength = FIND_PITCH_WHITE_NOISE_FRACTION * psEncCtrl->predGain;
/* between 0.0 and 1.0 */ |
213 BWExp1 = BWExp2 = BANDWIDTH_EXPANSION / ( 1.0f + strength * strength ); | 229 BWExp = BANDWIDTH_EXPANSION / ( 1.0f + strength * strength ); |
214 delta = LOW_RATE_BANDWIDTH_EXPANSION_DELTA * ( 1.0f - 0.75f * psEncCtrl->co
ding_quality ); | |
215 BWExp1 -= delta; | |
216 BWExp2 += delta; | |
217 /* BWExp1 will be applied after BWExp2, so make it relative */ | |
218 BWExp1 /= BWExp2; | |
219 | 230 |
220 if( psEnc->sCmn.warping_Q16 > 0 ) { | 231 /* Slightly more warping in analysis will move quantization noise up in freq
uency, where it's better masked */ |
221 /* Slightly more warping in analysis will move quantization noise up in
frequency, where it's better masked */ | 232 warping = (silk_float)psEnc->sCmn.warping_Q16 / 65536.0f + 0.01f * psEncCtrl
->coding_quality; |
222 warping = (silk_float)psEnc->sCmn.warping_Q16 / 65536.0f + 0.01f * psEnc
Ctrl->coding_quality; | |
223 } else { | |
224 warping = 0.0f; | |
225 } | |
226 | 233 |
227 /********************************************/ | 234 /********************************************/ |
228 /* Compute noise shaping AR coefs and gains */ | 235 /* Compute noise shaping AR coefs and gains */ |
229 /********************************************/ | 236 /********************************************/ |
230 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | 237 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { |
231 /* Apply window: sine slope followed by flat part followed by cosine slo
pe */ | 238 /* Apply window: sine slope followed by flat part followed by cosine slo
pe */ |
232 opus_int shift, slope_part, flat_part; | 239 opus_int shift, slope_part, flat_part; |
233 flat_part = psEnc->sCmn.fs_kHz * 3; | 240 flat_part = psEnc->sCmn.fs_kHz * 3; |
234 slope_part = ( psEnc->sCmn.shapeWinLength - flat_part ) / 2; | 241 slope_part = ( psEnc->sCmn.shapeWinLength - flat_part ) / 2; |
235 | 242 |
236 silk_apply_sine_window_FLP( x_windowed, x_ptr, 1, slope_part ); | 243 silk_apply_sine_window_FLP( x_windowed, x_ptr, 1, slope_part ); |
237 shift = slope_part; | 244 shift = slope_part; |
238 silk_memcpy( x_windowed + shift, x_ptr + shift, flat_part * sizeof(silk_
float) ); | 245 silk_memcpy( x_windowed + shift, x_ptr + shift, flat_part * sizeof(silk_
float) ); |
239 shift += flat_part; | 246 shift += flat_part; |
240 silk_apply_sine_window_FLP( x_windowed + shift, x_ptr + shift, 2, slope_
part ); | 247 silk_apply_sine_window_FLP( x_windowed + shift, x_ptr + shift, 2, slope_
part ); |
241 | 248 |
242 /* Update pointer: next LPC analysis block */ | 249 /* Update pointer: next LPC analysis block */ |
243 x_ptr += psEnc->sCmn.subfr_length; | 250 x_ptr += psEnc->sCmn.subfr_length; |
244 | 251 |
245 if( psEnc->sCmn.warping_Q16 > 0 ) { | 252 if( psEnc->sCmn.warping_Q16 > 0 ) { |
246 /* Calculate warped auto correlation */ | 253 /* Calculate warped auto correlation */ |
247 silk_warped_autocorrelation_FLP( auto_corr, x_windowed, warping, | 254 silk_warped_autocorrelation_FLP( auto_corr, x_windowed, warping, |
248 psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder ); | 255 psEnc->sCmn.shapeWinLength, psEnc->sCmn.shapingLPCOrder ); |
249 } else { | 256 } else { |
250 /* Calculate regular auto correlation */ | 257 /* Calculate regular auto correlation */ |
251 silk_autocorrelation_FLP( auto_corr, x_windowed, psEnc->sCmn.shapeWi
nLength, psEnc->sCmn.shapingLPCOrder + 1 ); | 258 silk_autocorrelation_FLP( auto_corr, x_windowed, psEnc->sCmn.shapeWi
nLength, psEnc->sCmn.shapingLPCOrder + 1 ); |
252 } | 259 } |
253 | 260 |
254 /* Add white noise, as a fraction of energy */ | 261 /* Add white noise, as a fraction of energy */ |
255 auto_corr[ 0 ] += auto_corr[ 0 ] * SHAPE_WHITE_NOISE_FRACTION; | 262 auto_corr[ 0 ] += auto_corr[ 0 ] * SHAPE_WHITE_NOISE_FRACTION + 1.0f; |
256 | 263 |
257 /* Convert correlations to prediction coefficients, and compute residual
energy */ | 264 /* Convert correlations to prediction coefficients, and compute residual
energy */ |
258 nrg = silk_levinsondurbin_FLP( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER
], auto_corr, psEnc->sCmn.shapingLPCOrder ); | 265 nrg = silk_schur_FLP( rc, auto_corr, psEnc->sCmn.shapingLPCOrder ); |
| 266 silk_k2a_FLP( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], rc, psEnc->sCmn
.shapingLPCOrder ); |
259 psEncCtrl->Gains[ k ] = ( silk_float )sqrt( nrg ); | 267 psEncCtrl->Gains[ k ] = ( silk_float )sqrt( nrg ); |
260 | 268 |
261 if( psEnc->sCmn.warping_Q16 > 0 ) { | 269 if( psEnc->sCmn.warping_Q16 > 0 ) { |
262 /* Adjust gain for warping */ | 270 /* Adjust gain for warping */ |
263 psEncCtrl->Gains[ k ] *= warped_gain( &psEncCtrl->AR2[ k * MAX_SHAPE
_LPC_ORDER ], warping, psEnc->sCmn.shapingLPCOrder ); | 271 psEncCtrl->Gains[ k ] *= warped_gain( &psEncCtrl->AR[ k * MAX_SHAPE_
LPC_ORDER ], warping, psEnc->sCmn.shapingLPCOrder ); |
264 } | 272 } |
265 | 273 |
266 /* Bandwidth expansion for synthesis filter shaping */ | 274 /* Bandwidth expansion for synthesis filter shaping */ |
267 silk_bwexpander_FLP( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], psEnc->
sCmn.shapingLPCOrder, BWExp2 ); | 275 silk_bwexpander_FLP( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], psEnc->s
Cmn.shapingLPCOrder, BWExp ); |
268 | 276 |
269 /* Compute noise shaping filter coefficients */ | 277 if( psEnc->sCmn.warping_Q16 > 0 ) { |
270 silk_memcpy( | 278 /* Convert to monic warped prediction coefficients and limit absolut
e values */ |
271 &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], | 279 warped_true2monic_coefs( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ],
warping, 3.999f, psEnc->sCmn.shapingLPCOrder ); |
272 &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], | 280 } else { |
273 psEnc->sCmn.shapingLPCOrder * sizeof( silk_float ) ); | 281 /* Limit absolute values */ |
274 | 282 limit_coefs( &psEncCtrl->AR[ k * MAX_SHAPE_LPC_ORDER ], 3.999f, psEn
c->sCmn.shapingLPCOrder ); |
275 /* Bandwidth expansion for analysis filter shaping */ | 283 } |
276 silk_bwexpander_FLP( &psEncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], psEnc->
sCmn.shapingLPCOrder, BWExp1 ); | |
277 | |
278 /* Ratio of prediction gains, in energy domain */ | |
279 pre_nrg = silk_LPC_inverse_pred_gain_FLP( &psEncCtrl->AR2[ k * MAX_SHAPE
_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder ); | |
280 nrg = silk_LPC_inverse_pred_gain_FLP( &psEncCtrl->AR1[ k * MAX_SHAPE
_LPC_ORDER ], psEnc->sCmn.shapingLPCOrder ); | |
281 psEncCtrl->GainsPre[ k ] = 1.0f - 0.7f * ( 1.0f - pre_nrg / nrg ); | |
282 | |
283 /* Convert to monic warped prediction coefficients and limit absolute va
lues */ | |
284 warped_true2monic_coefs( &psEncCtrl->AR2[ k * MAX_SHAPE_LPC_ORDER ], &ps
EncCtrl->AR1[ k * MAX_SHAPE_LPC_ORDER ], | |
285 warping, 3.999f, psEnc->sCmn.shapingLPCOrder ); | |
286 } | 284 } |
287 | 285 |
288 /*****************/ | 286 /*****************/ |
289 /* Gain tweaking */ | 287 /* Gain tweaking */ |
290 /*****************/ | 288 /*****************/ |
291 /* Increase gains during low speech activity */ | 289 /* Increase gains during low speech activity */ |
292 gain_mult = (silk_float)pow( 2.0f, -0.16f * SNR_adj_dB ); | 290 gain_mult = (silk_float)pow( 2.0f, -0.16f * SNR_adj_dB ); |
293 gain_add = (silk_float)pow( 2.0f, 0.16f * MIN_QGAIN_DB ); | 291 gain_add = (silk_float)pow( 2.0f, 0.16f * MIN_QGAIN_DB ); |
294 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | 292 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { |
295 psEncCtrl->Gains[ k ] *= gain_mult; | 293 psEncCtrl->Gains[ k ] *= gain_mult; |
296 psEncCtrl->Gains[ k ] += gain_add; | 294 psEncCtrl->Gains[ k ] += gain_add; |
297 } | 295 } |
298 | 296 |
299 gain_mult = 1.0f + INPUT_TILT + psEncCtrl->coding_quality * HIGH_RATE_INPUT_
TILT; | |
300 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | |
301 psEncCtrl->GainsPre[ k ] *= gain_mult; | |
302 } | |
303 | |
304 /************************************************/ | 297 /************************************************/ |
305 /* Control low-frequency shaping and noise tilt */ | 298 /* Control low-frequency shaping and noise tilt */ |
306 /************************************************/ | 299 /************************************************/ |
307 /* Less low frequency shaping for noisy inputs */ | 300 /* Less low frequency shaping for noisy inputs */ |
308 strength = LOW_FREQ_SHAPING * ( 1.0f + LOW_QUALITY_LOW_FREQ_SHAPING_DECR * (
psEnc->sCmn.input_quality_bands_Q15[ 0 ] * ( 1.0f / 32768.0f ) - 1.0f ) ); | 301 strength = LOW_FREQ_SHAPING * ( 1.0f + LOW_QUALITY_LOW_FREQ_SHAPING_DECR * (
psEnc->sCmn.input_quality_bands_Q15[ 0 ] * ( 1.0f / 32768.0f ) - 1.0f ) ); |
309 strength *= psEnc->sCmn.speech_activity_Q8 * ( 1.0f / 256.0f ); | 302 strength *= psEnc->sCmn.speech_activity_Q8 * ( 1.0f / 256.0f ); |
310 if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | 303 if( psEnc->sCmn.indices.signalType == TYPE_VOICED ) { |
311 /* Reduce low frequencies quantization noise for periodic signals, depen
ding on pitch lag */ | 304 /* Reduce low frequencies quantization noise for periodic signals, depen
ding on pitch lag */ |
312 /*f = 400; freqz([1, -0.98 + 2e-4 * f], [1, -0.97 + 7e-4 * f], 2^12, Fs)
; axis([0, 1000, -10, 1])*/ | 305 /*f = 400; freqz([1, -0.98 + 2e-4 * f], [1, -0.97 + 7e-4 * f], 2^12, Fs)
; axis([0, 1000, -10, 1])*/ |
313 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | 306 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { |
(...skipping 10 matching lines...) Expand all Loading... |
324 for( k = 1; k < psEnc->sCmn.nb_subfr; k++ ) { | 317 for( k = 1; k < psEnc->sCmn.nb_subfr; k++ ) { |
325 psEncCtrl->LF_MA_shp[ k ] = psEncCtrl->LF_MA_shp[ 0 ]; | 318 psEncCtrl->LF_MA_shp[ k ] = psEncCtrl->LF_MA_shp[ 0 ]; |
326 psEncCtrl->LF_AR_shp[ k ] = psEncCtrl->LF_AR_shp[ 0 ]; | 319 psEncCtrl->LF_AR_shp[ k ] = psEncCtrl->LF_AR_shp[ 0 ]; |
327 } | 320 } |
328 Tilt = -HP_NOISE_COEF; | 321 Tilt = -HP_NOISE_COEF; |
329 } | 322 } |
330 | 323 |
331 /****************************/ | 324 /****************************/ |
332 /* HARMONIC SHAPING CONTROL */ | 325 /* HARMONIC SHAPING CONTROL */ |
333 /****************************/ | 326 /****************************/ |
334 /* Control boosting of harmonic frequencies */ | |
335 HarmBoost = LOW_RATE_HARMONIC_BOOST * ( 1.0f - psEncCtrl->coding_quality ) *
psEnc->LTPCorr; | |
336 | |
337 /* More harmonic boost for noisy input signals */ | |
338 HarmBoost += LOW_INPUT_QUALITY_HARMONIC_BOOST * ( 1.0f - psEncCtrl->input_qu
ality ); | |
339 | |
340 if( USE_HARM_SHAPING && psEnc->sCmn.indices.signalType == TYPE_VOICED ) { | 327 if( USE_HARM_SHAPING && psEnc->sCmn.indices.signalType == TYPE_VOICED ) { |
341 /* Harmonic noise shaping */ | 328 /* Harmonic noise shaping */ |
342 HarmShapeGain = HARMONIC_SHAPING; | 329 HarmShapeGain = HARMONIC_SHAPING; |
343 | 330 |
344 /* More harmonic noise shaping for high bitrates or noisy input */ | 331 /* More harmonic noise shaping for high bitrates or noisy input */ |
345 HarmShapeGain += HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING * | 332 HarmShapeGain += HIGH_RATE_OR_LOW_QUALITY_HARMONIC_SHAPING * |
346 ( 1.0f - ( 1.0f - psEncCtrl->coding_quality ) * psEncCtrl->input_qua
lity ); | 333 ( 1.0f - ( 1.0f - psEncCtrl->coding_quality ) * psEncCtrl->input_qua
lity ); |
347 | 334 |
348 /* Less harmonic noise shaping for less periodic signals */ | 335 /* Less harmonic noise shaping for less periodic signals */ |
349 HarmShapeGain *= ( silk_float )sqrt( psEnc->LTPCorr ); | 336 HarmShapeGain *= ( silk_float )sqrt( psEnc->LTPCorr ); |
350 } else { | 337 } else { |
351 HarmShapeGain = 0.0f; | 338 HarmShapeGain = 0.0f; |
352 } | 339 } |
353 | 340 |
354 /*************************/ | 341 /*************************/ |
355 /* Smooth over subframes */ | 342 /* Smooth over subframes */ |
356 /*************************/ | 343 /*************************/ |
357 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | 344 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { |
358 psShapeSt->HarmBoost_smth += SUBFR_SMTH_COEF * ( HarmBoost - psShape
St->HarmBoost_smth ); | |
359 psEncCtrl->HarmBoost[ k ] = psShapeSt->HarmBoost_smth; | |
360 psShapeSt->HarmShapeGain_smth += SUBFR_SMTH_COEF * ( HarmShapeGain - psS
hapeSt->HarmShapeGain_smth ); | 345 psShapeSt->HarmShapeGain_smth += SUBFR_SMTH_COEF * ( HarmShapeGain - psS
hapeSt->HarmShapeGain_smth ); |
361 psEncCtrl->HarmShapeGain[ k ] = psShapeSt->HarmShapeGain_smth; | 346 psEncCtrl->HarmShapeGain[ k ] = psShapeSt->HarmShapeGain_smth; |
362 psShapeSt->Tilt_smth += SUBFR_SMTH_COEF * ( Tilt - psShapeSt->T
ilt_smth ); | 347 psShapeSt->Tilt_smth += SUBFR_SMTH_COEF * ( Tilt - psShapeSt->T
ilt_smth ); |
363 psEncCtrl->Tilt[ k ] = psShapeSt->Tilt_smth; | 348 psEncCtrl->Tilt[ k ] = psShapeSt->Tilt_smth; |
364 } | 349 } |
365 } | 350 } |
OLD | NEW |