| 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 | |
| 29 #include "config.h" | |
| 30 #endif | |
| 31 | |
| 32 #include "main_FIX.h" | |
| 33 #include "stack_alloc.h" | |
| 34 #include "tuning_parameters.h" | |
| 35 | |
| 36 /* Compute gain to make warped filter coefficients have a zero mean log frequenc
y response on a */ | |
| 37 /* non-warped frequency scale. (So that it can be implemented with a minimum-pha
se monic filter.) */ | |
| 38 /* Note: A monic filter is one with the first coefficient equal to 1.0. In Silk
we omit the first */ | |
| 39 /* coefficient in an array of coefficients, for monic filters.
*/ | |
| 40 static OPUS_INLINE opus_int32 warped_gain( /* gain in Q16*/ | |
| 41 const opus_int32 *coefs_Q24, | |
| 42 opus_int lambda_Q16, | |
| 43 opus_int order | |
| 44 ) { | |
| 45 opus_int i; | |
| 46 opus_int32 gain_Q24; | |
| 47 | |
| 48 lambda_Q16 = -lambda_Q16; | |
| 49 gain_Q24 = coefs_Q24[ order - 1 ]; | |
| 50 for( i = order - 2; i >= 0; i-- ) { | |
| 51 gain_Q24 = silk_SMLAWB( coefs_Q24[ i ], gain_Q24, lambda_Q16 ); | |
| 52 } | |
| 53 gain_Q24 = silk_SMLAWB( SILK_FIX_CONST( 1.0, 24 ), gain_Q24, -lambda_Q16 ); | |
| 54 return silk_INVERSE32_varQ( gain_Q24, 40 ); | |
| 55 } | |
| 56 | |
| 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 */ | |
| 59 static OPUS_INLINE void limit_warped_coefs( | |
| 60 opus_int32 *coefs_syn_Q24, | |
| 61 opus_int32 *coefs_ana_Q24, | |
| 62 opus_int lambda_Q16, | |
| 63 opus_int32 limit_Q24, | |
| 64 opus_int order | |
| 65 ) { | |
| 66 opus_int i, iter, ind = 0; | |
| 67 opus_int32 tmp, maxabs_Q24, chirp_Q16, gain_syn_Q16, gain_ana_Q16; | |
| 68 opus_int32 nom_Q16, den_Q24; | |
| 69 | |
| 70 /* Convert to monic coefficients */ | |
| 71 lambda_Q16 = -lambda_Q16; | |
| 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 ); | |
| 74 coefs_ana_Q24[ i - 1 ] = silk_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_ana_
Q24[ i ], lambda_Q16 ); | |
| 75 } | |
| 76 lambda_Q16 = -lambda_Q16; | |
| 77 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 ); | |
| 79 gain_syn_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++ ) { | |
| 83 coefs_syn_Q24[ i ] = silk_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] ); | |
| 84 coefs_ana_Q24[ i ] = silk_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] ); | |
| 85 } | |
| 86 | |
| 87 for( iter = 0; iter < 10; iter++ ) { | |
| 88 /* Find maximum absolute value */ | |
| 89 maxabs_Q24 = -1; | |
| 90 for( i = 0; i < order; i++ ) { | |
| 91 tmp = silk_max( silk_abs_int32( coefs_syn_Q24[ i ] ), silk_abs_int32
( coefs_ana_Q24[ i ] ) ); | |
| 92 if( tmp > maxabs_Q24 ) { | |
| 93 maxabs_Q24 = tmp; | |
| 94 ind = i; | |
| 95 } | |
| 96 } | |
| 97 if( maxabs_Q24 <= limit_Q24 ) { | |
| 98 /* Coefficients are within range - done */ | |
| 99 return; | |
| 100 } | |
| 101 | |
| 102 /* Convert back to true warped coefficients */ | |
| 103 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 ); | |
| 105 coefs_ana_Q24[ i - 1 ] = silk_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_
ana_Q24[ i ], lambda_Q16 ); | |
| 106 } | |
| 107 gain_syn_Q16 = silk_INVERSE32_varQ( gain_syn_Q16, 32 ); | |
| 108 gain_ana_Q16 = silk_INVERSE32_varQ( gain_ana_Q16, 32 ); | |
| 109 for( i = 0; i < order; i++ ) { | |
| 110 coefs_syn_Q24[ i ] = silk_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] )
; | |
| 111 coefs_ana_Q24[ i ] = silk_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] )
; | |
| 112 } | |
| 113 | |
| 114 /* Apply bandwidth expansion */ | |
| 115 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 ) ), | |
| 117 silk_MUL( maxabs_Q24, ind + 1 ), 22 ); | |
| 118 silk_bwexpander_32( coefs_syn_Q24, order, chirp_Q16 ); | |
| 119 silk_bwexpander_32( coefs_ana_Q24, order, chirp_Q16 ); | |
| 120 | |
| 121 /* Convert to monic warped coefficients */ | |
| 122 lambda_Q16 = -lambda_Q16; | |
| 123 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 ); | |
| 125 coefs_ana_Q24[ i - 1 ] = silk_SMLAWB( coefs_ana_Q24[ i - 1 ], coefs_
ana_Q24[ i ], lambda_Q16 ); | |
| 126 } | |
| 127 lambda_Q16 = -lambda_Q16; | |
| 128 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 ); | |
| 130 gain_syn_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++ ) { | |
| 134 coefs_syn_Q24[ i ] = silk_SMULWW( gain_syn_Q16, coefs_syn_Q24[ i ] )
; | |
| 135 coefs_ana_Q24[ i ] = silk_SMULWW( gain_ana_Q16, coefs_ana_Q24[ i ] )
; | |
| 136 } | |
| 137 } | |
| 138 silk_assert( 0 ); | |
| 139 } | |
| 140 | 28 |
| 141 /**************************************************************/ | 29 /**************************************************************/ |
| 142 /* Compute noise shaping coefficients and initial gain values */ | 30 /* Compute noise shaping coefficients and initial gain values */ |
| 143 /**************************************************************/ | 31 /**************************************************************/ |
| 32 #define OVERRIDE_silk_noise_shape_analysis_FIX |
| 33 |
| 144 void silk_noise_shape_analysis_FIX( | 34 void silk_noise_shape_analysis_FIX( |
| 145 silk_encoder_state_FIX *psEnc, /* I
/O Encoder state FIX
*/ | 35 silk_encoder_state_FIX *psEnc, /* I
/O Encoder state FIX
*/ |
| 146 silk_encoder_control_FIX *psEncCtrl, /* I
/O Encoder control FIX
*/ | 36 silk_encoder_control_FIX *psEncCtrl, /* I
/O Encoder control FIX
*/ |
| 147 const opus_int16 *pitch_res, /* I
LPC residual from pitch analysis
*/ | 37 const opus_int16 *pitch_res, /* I
LPC residual from pitch analysis
*/ |
| 148 const opus_int16 *x, /* I
Input signal [ frame_length + la_shape ]
*/ | 38 const opus_int16 *x, /* I
Input signal [ frame_length + la_shape ]
*/ |
| 149 int arch /* I
Run-time architecture
*/ | 39 int arch /* I
Run-time architecture
*/ |
| 150 ) | 40 ) |
| 151 { | 41 { |
| 152 silk_shape_state_FIX *psShapeSt = &psEnc->sShape; | 42 silk_shape_state_FIX *psShapeSt = &psEnc->sShape; |
| 153 opus_int k, i, nSamples, Qnrg, b_Q14, warping_Q16, scale = 0; | 43 opus_int k, i, nSamples, Qnrg, b_Q14, warping_Q16, scale = 0; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 | 192 |
| 303 /* Make sure that Qnrg is an even number */ | 193 /* Make sure that Qnrg is an even number */ |
| 304 if( Qnrg & 1 ) { | 194 if( Qnrg & 1 ) { |
| 305 Qnrg -= 1; | 195 Qnrg -= 1; |
| 306 nrg >>= 1; | 196 nrg >>= 1; |
| 307 } | 197 } |
| 308 | 198 |
| 309 tmp32 = silk_SQRT_APPROX( nrg ); | 199 tmp32 = silk_SQRT_APPROX( nrg ); |
| 310 Qnrg >>= 1; /* range: -6...15*/ | 200 Qnrg >>= 1; /* range: -6...15*/ |
| 311 | 201 |
| 312 psEncCtrl->Gains_Q16[ k ] = silk_LSHIFT_SAT32( tmp32, 16 - Qnrg ); | 202 psEncCtrl->Gains_Q16[ k ] = (silk_LSHIFT32( silk_LIMIT( (tmp32), silk_RS
HIFT32( silk_int32_MIN, (16 - Qnrg) ), \ |
| 203 silk_RSHIFT32( silk_int32_MAX, (16 - Qnrg) ) ), (16
- Qnrg) )); |
| 313 | 204 |
| 314 if( psEnc->sCmn.warping_Q16 > 0 ) { | 205 if( psEnc->sCmn.warping_Q16 > 0 ) { |
| 315 /* Adjust gain for warping */ | 206 /* Adjust gain for warping */ |
| 316 gain_mult_Q16 = warped_gain( AR2_Q24, warping_Q16, psEnc->sCmn.shapi
ngLPCOrder ); | 207 gain_mult_Q16 = warped_gain( AR2_Q24, warping_Q16, psEnc->sCmn.shapi
ngLPCOrder ); |
| 317 silk_assert( psEncCtrl->Gains_Q16[ k ] >= 0 ); | 208 silk_assert( psEncCtrl->Gains_Q16[ k ] >= 0 ); |
| 318 if ( silk_SMULWW( silk_RSHIFT_ROUND( psEncCtrl->Gains_Q16[ k ], 1 ),
gain_mult_Q16 ) >= ( silk_int32_MAX >> 1 ) ) { | 209 if ( silk_SMULWW( silk_RSHIFT_ROUND( psEncCtrl->Gains_Q16[ k ], 1 ),
gain_mult_Q16 ) >= ( silk_int32_MAX >> 1 ) ) { |
| 319 psEncCtrl->Gains_Q16[ k ] = silk_int32_MAX; | 210 psEncCtrl->Gains_Q16[ k ] = silk_int32_MAX; |
| 320 } else { | 211 } else { |
| 321 psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k
], gain_mult_Q16 ); | 212 psEncCtrl->Gains_Q16[ k ] = silk_SMULWW( psEncCtrl->Gains_Q16[ k
], gain_mult_Q16 ); |
| 322 } | 213 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 silk_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 -
psShapeSt->HarmShapeGain_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); | 327 silk_SMLAWB( psShapeSt->HarmShapeGain_smth_Q16, HarmShapeGain_Q16 -
psShapeSt->HarmShapeGain_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); |
| 437 psShapeSt->Tilt_smth_Q16 = | 328 psShapeSt->Tilt_smth_Q16 = |
| 438 silk_SMLAWB( psShapeSt->Tilt_smth_Q16, Tilt_Q16 -
psShapeSt->Tilt_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); | 329 silk_SMLAWB( psShapeSt->Tilt_smth_Q16, Tilt_Q16 -
psShapeSt->Tilt_smth_Q16, SILK_FIX_CONST( SUBFR_SMTH_COEF, 16 ) ); |
| 439 | 330 |
| 440 psEncCtrl->HarmBoost_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->HarmBoost_smth_Q16, 2 ); | 331 psEncCtrl->HarmBoost_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->HarmBoost_smth_Q16, 2 ); |
| 441 psEncCtrl->HarmShapeGain_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->HarmShapeGain_smth_Q16, 2 ); | 332 psEncCtrl->HarmShapeGain_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->HarmShapeGain_smth_Q16, 2 ); |
| 442 psEncCtrl->Tilt_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->Tilt_smth_Q16, 2 ); | 333 psEncCtrl->Tilt_Q14[ k ] = ( opus_int )silk_RSHIFT_ROUND( psSha
peSt->Tilt_smth_Q16, 2 ); |
| 443 } | 334 } |
| 444 RESTORE_STACK; | 335 RESTORE_STACK; |
| 445 } | 336 } |
| OLD | NEW |