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. |
11 - Neither the name of Internet Society, IETF or IETF Trust, nor the | 11 - Neither the name of Internet Society, IETF or IETF Trust, nor the |
12 names of specific contributors, may be used to endorse or promote | 12 names of specific contributors, may be used to endorse or promote |
13 products derived from this software without specific prior written | 13 products derived from this software without specific prior written |
14 permission. | 14 permission. |
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” | 15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 18 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 19 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 20 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 21 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 22 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 23 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 24 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 POSSIBILITY OF SUCH DAMAGE. | 25 POSSIBILITY OF SUCH DAMAGE. |
26 ***********************************************************************/ | 26 ***********************************************************************/ |
27 | 27 |
28 #ifdef HAVE_CONFIG_H | 28 #ifdef HAVE_CONFIG_H |
29 #include "config.h" | 29 #include "config.h" |
30 #endif | 30 #endif |
31 | 31 |
32 #include "main_FIX.h" | 32 #include "main_FIX.h" |
| 33 #include "stack_alloc.h" |
33 #include "tuning_parameters.h" | 34 #include "tuning_parameters.h" |
34 | 35 |
35 /* Compute gain to make warped filter coefficients have a zero mean log frequenc
y response on a */ | 36 /* Compute gain to make warped filter coefficients have a zero mean log frequenc
y response on a */ |
36 /* non-warped frequency scale. (So that it can be implemented with a minimum-pha
se monic filter.) */ | 37 /* non-warped frequency scale. (So that it can be implemented with a minimum-pha
se monic filter.) */ |
37 /* Note: A monic filter is one with the first coefficient equal to 1.0. In Silk
we omit the first */ | 38 /* Note: A monic filter is one with the first coefficient equal to 1.0. In Silk
we omit the first */ |
38 /* coefficient in an array of coefficients, for monic filters.
*/ | 39 /* coefficient in an array of coefficients, for monic filters.
*/ |
39 static inline opus_int32 warped_gain( /* gain in Q16*/ | 40 static inline opus_int32 warped_gain( /* gain in Q16*/ |
40 const opus_int32 *coefs_Q24, | 41 const opus_int32 *coefs_Q24, |
41 opus_int lambda_Q16, | 42 opus_int lambda_Q16, |
42 opus_int order | 43 opus_int order |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 { | 150 { |
150 silk_shape_state_FIX *psShapeSt = &psEnc->sShape; | 151 silk_shape_state_FIX *psShapeSt = &psEnc->sShape; |
151 opus_int k, i, nSamples, Qnrg, b_Q14, warping_Q16, scale = 0; | 152 opus_int k, i, nSamples, Qnrg, b_Q14, warping_Q16, scale = 0; |
152 opus_int32 SNR_adj_dB_Q7, HarmBoost_Q16, HarmShapeGain_Q16, Tilt_Q16, tmp3
2; | 153 opus_int32 SNR_adj_dB_Q7, HarmBoost_Q16, HarmShapeGain_Q16, Tilt_Q16, tmp3
2; |
153 opus_int32 nrg, pre_nrg_Q30, log_energy_Q7, log_energy_prev_Q7, energy_var
iation_Q7; | 154 opus_int32 nrg, pre_nrg_Q30, log_energy_Q7, log_energy_prev_Q7, energy_var
iation_Q7; |
154 opus_int32 delta_Q16, BWExp1_Q16, BWExp2_Q16, gain_mult_Q16, gain_add_Q16,
strength_Q16, b_Q8; | 155 opus_int32 delta_Q16, BWExp1_Q16, BWExp2_Q16, gain_mult_Q16, gain_add_Q16,
strength_Q16, b_Q8; |
155 opus_int32 auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; | 156 opus_int32 auto_corr[ MAX_SHAPE_LPC_ORDER + 1 ]; |
156 opus_int32 refl_coef_Q16[ MAX_SHAPE_LPC_ORDER ]; | 157 opus_int32 refl_coef_Q16[ MAX_SHAPE_LPC_ORDER ]; |
157 opus_int32 AR1_Q24[ MAX_SHAPE_LPC_ORDER ]; | 158 opus_int32 AR1_Q24[ MAX_SHAPE_LPC_ORDER ]; |
158 opus_int32 AR2_Q24[ MAX_SHAPE_LPC_ORDER ]; | 159 opus_int32 AR2_Q24[ MAX_SHAPE_LPC_ORDER ]; |
159 opus_int16 x_windowed[ SHAPE_LPC_WIN_MAX ]; | 160 VARDECL( opus_int16, x_windowed ); |
160 const opus_int16 *x_ptr, *pitch_res_ptr; | 161 const opus_int16 *x_ptr, *pitch_res_ptr; |
| 162 SAVE_STACK; |
161 | 163 |
162 /* Point to start of first LPC analysis block */ | 164 /* Point to start of first LPC analysis block */ |
163 x_ptr = x - psEnc->sCmn.la_shape; | 165 x_ptr = x - psEnc->sCmn.la_shape; |
164 | 166 |
165 /****************/ | 167 /****************/ |
166 /* GAIN CONTROL */ | 168 /* GAIN CONTROL */ |
167 /****************/ | 169 /****************/ |
168 SNR_adj_dB_Q7 = psEnc->sCmn.SNR_dB_Q7; | 170 SNR_adj_dB_Q7 = psEnc->sCmn.SNR_dB_Q7; |
169 | 171 |
170 /* Input quality is the average of the quality in the lowest two VAD bands *
/ | 172 /* Input quality is the average of the quality in the lowest two VAD bands *
/ |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 if( psEnc->sCmn.warping_Q16 > 0 ) { | 253 if( psEnc->sCmn.warping_Q16 > 0 ) { |
252 /* Slightly more warping in analysis will move quantization noise up in
frequency, where it's better masked */ | 254 /* Slightly more warping in analysis will move quantization noise up in
frequency, where it's better masked */ |
253 warping_Q16 = silk_SMLAWB( psEnc->sCmn.warping_Q16, (opus_int32)psEncCtr
l->coding_quality_Q14, SILK_FIX_CONST( 0.01, 18 ) ); | 255 warping_Q16 = silk_SMLAWB( psEnc->sCmn.warping_Q16, (opus_int32)psEncCtr
l->coding_quality_Q14, SILK_FIX_CONST( 0.01, 18 ) ); |
254 } else { | 256 } else { |
255 warping_Q16 = 0; | 257 warping_Q16 = 0; |
256 } | 258 } |
257 | 259 |
258 /********************************************/ | 260 /********************************************/ |
259 /* Compute noise shaping AR coefs and gains */ | 261 /* Compute noise shaping AR coefs and gains */ |
260 /********************************************/ | 262 /********************************************/ |
| 263 ALLOC( x_windowed, psEnc->sCmn.shapeWinLength, opus_int16 ); |
261 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { | 264 for( k = 0; k < psEnc->sCmn.nb_subfr; k++ ) { |
262 /* Apply window: sine slope followed by flat part followed by cosine slo
pe */ | 265 /* Apply window: sine slope followed by flat part followed by cosine slo
pe */ |
263 opus_int shift, slope_part, flat_part; | 266 opus_int shift, slope_part, flat_part; |
264 flat_part = psEnc->sCmn.fs_kHz * 3; | 267 flat_part = psEnc->sCmn.fs_kHz * 3; |
265 slope_part = silk_RSHIFT( psEnc->sCmn.shapeWinLength - flat_part, 1 ); | 268 slope_part = silk_RSHIFT( psEnc->sCmn.shapeWinLength - flat_part, 1 ); |
266 | 269 |
267 silk_apply_sine_window( x_windowed, x_ptr, 1, slope_part ); | 270 silk_apply_sine_window( x_windowed, x_ptr, 1, slope_part ); |
268 shift = slope_part; | 271 shift = slope_part; |
269 silk_memcpy( x_windowed + shift, x_ptr + shift, flat_part * sizeof(opus_
int16) ); | 272 silk_memcpy( x_windowed + shift, x_ptr + shift, flat_part * sizeof(opus_
int16) ); |
270 shift += flat_part; | 273 shift += flat_part; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 silk_SMLAWB( psShapeSt->HarmBoost_smth_Q16, HarmBoost_Q16 -
psShapeSt->HarmBoost_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); | 433 silk_SMLAWB( psShapeSt->HarmBoost_smth_Q16, HarmBoost_Q16 -
psShapeSt->HarmBoost_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); |
431 psShapeSt->HarmShapeGain_smth_Q16 = | 434 psShapeSt->HarmShapeGain_smth_Q16 = |
432 silk_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 -
psShapeSt->HarmShapeGain_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); | 435 silk_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 -
psShapeSt->HarmShapeGain_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); |
433 psShapeSt->Tilt_smth_Q16 = | 436 psShapeSt->Tilt_smth_Q16 = |
434 silk_SMLAWB( psShapeSt->Tilt_smth_Q16, Tilt_Q16 -
psShapeSt->Tilt_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); | 437 silk_SMLAWB( psShapeSt->Tilt_smth_Q16, Tilt_Q16 -
psShapeSt->Tilt_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); |
435 | 438 |
436 psEncCtrl->HarmBoost_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->HarmBoost_smth_Q16, 2 ); | 439 psEncCtrl->HarmBoost_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->HarmBoost_smth_Q16, 2 ); |
437 psEncCtrl->HarmShapeGain_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->HarmShapeGain_smth_Q16, 2 ); | 440 psEncCtrl->HarmShapeGain_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->HarmShapeGain_smth_Q16, 2 ); |
438 psEncCtrl->Tilt_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->Tilt_smth_Q16, 2 ); | 441 psEncCtrl->Tilt_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->Tilt_smth_Q16, 2 ); |
439 } | 442 } |
| 443 RESTORE_STACK; |
440 } | 444 } |
OLD | NEW |