| 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 11 matching lines...) Expand all Loading... |
| 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 <stdlib.h> |
| 32 #include "main_FIX.h" | 33 #include "main_FIX.h" |
| 33 #include "stack_alloc.h" | 34 #include "stack_alloc.h" |
| 34 #include "tuning_parameters.h" | 35 #include "tuning_parameters.h" |
| 35 | 36 |
| 36 /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with
lower bitrate */ | 37 /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with
lower bitrate */ |
| 37 static OPUS_INLINE void silk_LBRR_encode_FIX( | 38 static OPUS_INLINE void silk_LBRR_encode_FIX( |
| 38 silk_encoder_state_FIX *psEnc, /* I
/O Pointer to Silk FIX encoder state
*/ | 39 silk_encoder_state_FIX *psEnc, /* I
/O Pointer to Silk FIX encoder state
*/ |
| 39 silk_encoder_control_FIX *psEncCtrl, /* I
/O Pointer to Silk FIX encoder control struct
*/ | 40 silk_encoder_control_FIX *psEncCtrl, /* I
/O Pointer to Silk FIX encoder control struct
*/ |
| 40 const opus_int32 xfw_Q3[], /* I
Input signal
*/ | 41 const opus_int16 x16[], /* I
Input signal
*/ |
| 41 opus_int condCoding /* I
The type of conditional coding used so far for this frame
*/ | 42 opus_int condCoding /* I
The type of conditional coding used so far for this frame
*/ |
| 42 ); | 43 ); |
| 43 | 44 |
| 44 void silk_encode_do_VAD_FIX( | 45 void silk_encode_do_VAD_FIX( |
| 45 silk_encoder_state_FIX *psEnc /* I
/O Pointer to Silk FIX encoder state
*/ | 46 silk_encoder_state_FIX *psEnc /* I
/O Pointer to Silk FIX encoder state
*/ |
| 46 ) | 47 ) |
| 47 { | 48 { |
| 48 /****************************/ | 49 /****************************/ |
| 49 /* Voice Activity Detection */ | 50 /* Voice Activity Detection */ |
| 50 /****************************/ | 51 /****************************/ |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 opus_int i, iter, maxIter, found_upper, found_lower, ret = 0; | 88 opus_int i, iter, maxIter, found_upper, found_lower, ret = 0; |
| 88 opus_int16 *x_frame; | 89 opus_int16 *x_frame; |
| 89 ec_enc sRangeEnc_copy, sRangeEnc_copy2; | 90 ec_enc sRangeEnc_copy, sRangeEnc_copy2; |
| 90 silk_nsq_state sNSQ_copy, sNSQ_copy2; | 91 silk_nsq_state sNSQ_copy, sNSQ_copy2; |
| 91 opus_int32 seed_copy, nBits, nBits_lower, nBits_upper, gainMult_lower, gai
nMult_upper; | 92 opus_int32 seed_copy, nBits, nBits_lower, nBits_upper, gainMult_lower, gai
nMult_upper; |
| 92 opus_int32 gainsID, gainsID_lower, gainsID_upper; | 93 opus_int32 gainsID, gainsID_lower, gainsID_upper; |
| 93 opus_int16 gainMult_Q8; | 94 opus_int16 gainMult_Q8; |
| 94 opus_int16 ec_prevLagIndex_copy; | 95 opus_int16 ec_prevLagIndex_copy; |
| 95 opus_int ec_prevSignalType_copy; | 96 opus_int ec_prevSignalType_copy; |
| 96 opus_int8 LastGainIndex_copy2; | 97 opus_int8 LastGainIndex_copy2; |
| 98 opus_int gain_lock[ MAX_NB_SUBFR ] = {0}; |
| 99 opus_int16 best_gain_mult[ MAX_NB_SUBFR ]; |
| 100 opus_int best_sum[ MAX_NB_SUBFR ]; |
| 97 SAVE_STACK; | 101 SAVE_STACK; |
| 98 | 102 |
| 99 /* This is totally unnecessary but many compilers (including gcc) are too du
mb to realise it */ | 103 /* This is totally unnecessary but many compilers (including gcc) are too du
mb to realise it */ |
| 100 LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_
upper = 0; | 104 LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_
upper = 0; |
| 101 | 105 |
| 102 psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3; | 106 psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3; |
| 103 | 107 |
| 104 /**************************************************************/ | 108 /**************************************************************/ |
| 105 /* Set up Input Pointers, and insert frame in input buffer */ | 109 /* Set up Input Pointers, and insert frame in input buffer */ |
| 106 /*************************************************************/ | 110 /*************************************************************/ |
| 107 /* start of frame to encode */ | 111 /* start of frame to encode */ |
| 108 x_frame = psEnc->x_buf + psEnc->sCmn.ltp_mem_length; | 112 x_frame = psEnc->x_buf + psEnc->sCmn.ltp_mem_length; |
| 109 | 113 |
| 110 /***************************************/ | 114 /***************************************/ |
| 111 /* Ensure smooth bandwidth transitions */ | 115 /* Ensure smooth bandwidth transitions */ |
| 112 /***************************************/ | 116 /***************************************/ |
| 113 silk_LP_variable_cutoff( &psEnc->sCmn.sLP, psEnc->sCmn.inputBuf + 1, psEnc->
sCmn.frame_length ); | 117 silk_LP_variable_cutoff( &psEnc->sCmn.sLP, psEnc->sCmn.inputBuf + 1, psEnc->
sCmn.frame_length ); |
| 114 | 118 |
| 115 /*******************************************/ | 119 /*******************************************/ |
| 116 /* Copy new frame to front of input buffer */ | 120 /* Copy new frame to front of input buffer */ |
| 117 /*******************************************/ | 121 /*******************************************/ |
| 118 silk_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBu
f + 1, psEnc->sCmn.frame_length * sizeof( opus_int16 ) ); | 122 silk_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBu
f + 1, psEnc->sCmn.frame_length * sizeof( opus_int16 ) ); |
| 119 | 123 |
| 120 if( !psEnc->sCmn.prefillFlag ) { | 124 if( !psEnc->sCmn.prefillFlag ) { |
| 121 VARDECL( opus_int32, xfw_Q3 ); | |
| 122 VARDECL( opus_int16, res_pitch ); | 125 VARDECL( opus_int16, res_pitch ); |
| 123 VARDECL( opus_uint8, ec_buf_copy ); | 126 VARDECL( opus_uint8, ec_buf_copy ); |
| 124 opus_int16 *res_pitch_frame; | 127 opus_int16 *res_pitch_frame; |
| 125 | 128 |
| 126 ALLOC( res_pitch, | 129 ALLOC( res_pitch, |
| 127 psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length | 130 psEnc->sCmn.la_pitch + psEnc->sCmn.frame_length |
| 128 + psEnc->sCmn.ltp_mem_length, opus_int16 ); | 131 + psEnc->sCmn.ltp_mem_length, opus_int16 ); |
| 129 /* start of pitch LPC residual frame */ | 132 /* start of pitch LPC residual frame */ |
| 130 res_pitch_frame = res_pitch + psEnc->sCmn.ltp_mem_length; | 133 res_pitch_frame = res_pitch + psEnc->sCmn.ltp_mem_length; |
| 131 | 134 |
| 132 /*****************************************/ | 135 /*****************************************/ |
| 133 /* Find pitch lags, initial LPC analysis */ | 136 /* Find pitch lags, initial LPC analysis */ |
| 134 /*****************************************/ | 137 /*****************************************/ |
| 135 silk_find_pitch_lags_FIX( psEnc, &sEncCtrl, res_pitch, x_frame, psEnc->s
Cmn.arch ); | 138 silk_find_pitch_lags_FIX( psEnc, &sEncCtrl, res_pitch, x_frame - psEnc->
sCmn.ltp_mem_length, psEnc->sCmn.arch ); |
| 136 | 139 |
| 137 /************************/ | 140 /************************/ |
| 138 /* Noise shape analysis */ | 141 /* Noise shape analysis */ |
| 139 /************************/ | 142 /************************/ |
| 140 silk_noise_shape_analysis_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_fram
e, psEnc->sCmn.arch ); | 143 silk_noise_shape_analysis_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_fram
e, psEnc->sCmn.arch ); |
| 141 | 144 |
| 142 /***************************************************/ | 145 /***************************************************/ |
| 143 /* Find linear prediction coefficients (LPC + LTP) */ | 146 /* Find linear prediction coefficients (LPC + LTP) */ |
| 144 /***************************************************/ | 147 /***************************************************/ |
| 145 silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch, x_frame, condCodi
ng ); | 148 silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_frame, co
ndCoding ); |
| 146 | 149 |
| 147 /****************************************/ | 150 /****************************************/ |
| 148 /* Process gains */ | 151 /* Process gains */ |
| 149 /****************************************/ | 152 /****************************************/ |
| 150 silk_process_gains_FIX( psEnc, &sEncCtrl, condCoding ); | 153 silk_process_gains_FIX( psEnc, &sEncCtrl, condCoding ); |
| 151 | 154 |
| 152 /*****************************************/ | |
| 153 /* Prefiltering for noise shaper */ | |
| 154 /*****************************************/ | |
| 155 ALLOC( xfw_Q3, psEnc->sCmn.frame_length, opus_int32 ); | |
| 156 silk_prefilter_FIX( psEnc, &sEncCtrl, xfw_Q3, x_frame ); | |
| 157 | |
| 158 /****************************************/ | 155 /****************************************/ |
| 159 /* Low Bitrate Redundant Encoding */ | 156 /* Low Bitrate Redundant Encoding */ |
| 160 /****************************************/ | 157 /****************************************/ |
| 161 silk_LBRR_encode_FIX( psEnc, &sEncCtrl, xfw_Q3, condCoding ); | 158 silk_LBRR_encode_FIX( psEnc, &sEncCtrl, x_frame, condCoding ); |
| 162 | 159 |
| 163 /* Loop over quantizer and entropy coding to control bitrate */ | 160 /* Loop over quantizer and entropy coding to control bitrate */ |
| 164 maxIter = 6; | 161 maxIter = 6; |
| 165 gainMult_Q8 = SILK_FIX_CONST( 1, 8 ); | 162 gainMult_Q8 = SILK_FIX_CONST( 1, 8 ); |
| 166 found_lower = 0; | 163 found_lower = 0; |
| 167 found_upper = 0; | 164 found_upper = 0; |
| 168 gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.n
b_subfr ); | 165 gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.n
b_subfr ); |
| 169 gainsID_lower = -1; | 166 gainsID_lower = -1; |
| 170 gainsID_upper = -1; | 167 gainsID_upper = -1; |
| 171 /* Copy part of the input state */ | 168 /* Copy part of the input state */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 187 silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy, sizeof( silk_nsq
_state ) ); | 184 silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy, sizeof( silk_nsq
_state ) ); |
| 188 psEnc->sCmn.indices.Seed = seed_copy; | 185 psEnc->sCmn.indices.Seed = seed_copy; |
| 189 psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; | 186 psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; |
| 190 psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; | 187 psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; |
| 191 } | 188 } |
| 192 | 189 |
| 193 /*****************************************/ | 190 /*****************************************/ |
| 194 /* Noise shaping quantization */ | 191 /* Noise shaping quantization */ |
| 195 /*****************************************/ | 192 /*****************************************/ |
| 196 if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warpin
g_Q16 > 0 ) { | 193 if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warpin
g_Q16 > 0 ) { |
| 197 silk_NSQ_del_dec( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->s
Cmn.indices, xfw_Q3, psEnc->sCmn.pulses, | 194 silk_NSQ_del_dec( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->s
Cmn.indices, x_frame, psEnc->sCmn.pulses, |
| 198 sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEn
cCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14, | 195 sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEn
cCtrl.AR_Q13, sEncCtrl.HarmShapeGain_Q14, |
| 199 sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gain
s_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14, | 196 sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gain
s_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14, |
| 200 psEnc->sCmn.arch ); | 197 psEnc->sCmn.arch ); |
| 201 } else { | 198 } else { |
| 202 silk_NSQ( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indi
ces, xfw_Q3, psEnc->sCmn.pulses, | 199 silk_NSQ( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indi
ces, x_frame, psEnc->sCmn.pulses, |
| 203 sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sE
ncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14, | 200 sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sE
ncCtrl.AR_Q13, sEncCtrl.HarmShapeGain_Q14, |
| 204 sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gai
ns_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14, | 201 sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gai
ns_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14, |
| 205 psEnc->sCmn.arch); | 202 psEnc->sCmn.arch); |
| 206 } | 203 } |
| 207 | 204 |
| 205 if ( iter == maxIter && !found_lower ) { |
| 206 silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc )
); |
| 207 } |
| 208 |
| 208 /****************************************/ | 209 /****************************************/ |
| 209 /* Encode Parameters */ | 210 /* Encode Parameters */ |
| 210 /****************************************/ | 211 /****************************************/ |
| 211 silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFram
esEncoded, 0, condCoding ); | 212 silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFram
esEncoded, 0, condCoding ); |
| 212 | 213 |
| 213 /****************************************/ | 214 /****************************************/ |
| 214 /* Encode Excitation Signal */ | 215 /* Encode Excitation Signal */ |
| 215 /****************************************/ | 216 /****************************************/ |
| 216 silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType,
psEnc->sCmn.indices.quantOffsetType, | 217 silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType,
psEnc->sCmn.indices.quantOffsetType, |
| 217 psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); | 218 psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); |
| 218 | 219 |
| 219 nBits = ec_tell( psRangeEnc ); | 220 nBits = ec_tell( psRangeEnc ); |
| 220 | 221 |
| 222 /* If we still bust after the last iteration, do some damage con
trol. */ |
| 223 if ( iter == maxIter && !found_lower && nBits > maxBits ) { |
| 224 silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc )
); |
| 225 |
| 226 /* Keep gains the same as the last frame. */ |
| 227 psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; |
| 228 for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { |
| 229 psEnc->sCmn.indices.GainsIndices[ i ] = 4; |
| 230 } |
| 231 if (condCoding != CODE_CONDITIONALLY) { |
| 232 psEnc->sCmn.indices.GainsIndices[ 0 ] = sEncCtrl.lastGain
IndexPrev; |
| 233 } |
| 234 psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; |
| 235 psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; |
| 236 /* Clear all pulses. */ |
| 237 for ( i = 0; i < psEnc->sCmn.frame_length; i++ ) { |
| 238 psEnc->sCmn.pulses[ i ] = 0; |
| 239 } |
| 240 |
| 241 silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.n
FramesEncoded, 0, condCoding ); |
| 242 |
| 243 silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalTy
pe, psEnc->sCmn.indices.quantOffsetType, |
| 244 psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); |
| 245 |
| 246 nBits = ec_tell( psRangeEnc ); |
| 247 } |
| 248 |
| 221 if( useCBR == 0 && iter == 0 && nBits <= maxBits ) { | 249 if( useCBR == 0 && iter == 0 && nBits <= maxBits ) { |
| 222 break; | 250 break; |
| 223 } | 251 } |
| 224 } | 252 } |
| 225 | 253 |
| 226 if( iter == maxIter ) { | 254 if( iter == maxIter ) { |
| 227 if( found_lower && ( gainsID == gainsID_lower || nBits > maxBits
) ) { | 255 if( found_lower && ( gainsID == gainsID_lower || nBits > maxBits
) ) { |
| 228 /* Restore output state from earlier iteration that did meet
the bitrate budget */ | 256 /* Restore output state from earlier iteration that did meet
the bitrate budget */ |
| 229 silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc )
); | 257 silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc )
); |
| 230 silk_assert( sRangeEnc_copy2.offs <= 1275 ); | 258 silk_assert( sRangeEnc_copy2.offs <= 1275 ); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 258 silk_assert( psRangeEnc->offs <= 1275 ); | 286 silk_assert( psRangeEnc->offs <= 1275 ); |
| 259 silk_memcpy( ec_buf_copy, psRangeEnc->buf, psRangeEnc->offs
); | 287 silk_memcpy( ec_buf_copy, psRangeEnc->buf, psRangeEnc->offs
); |
| 260 silk_memcpy( &sNSQ_copy2, &psEnc->sCmn.sNSQ, sizeof( silk_ns
q_state ) ); | 288 silk_memcpy( &sNSQ_copy2, &psEnc->sCmn.sNSQ, sizeof( silk_ns
q_state ) ); |
| 261 LastGainIndex_copy2 = psEnc->sShape.LastGainIndex; | 289 LastGainIndex_copy2 = psEnc->sShape.LastGainIndex; |
| 262 } | 290 } |
| 263 } else { | 291 } else { |
| 264 /* Within 5 bits of budget: close enough */ | 292 /* Within 5 bits of budget: close enough */ |
| 265 break; | 293 break; |
| 266 } | 294 } |
| 267 | 295 |
| 296 if ( !found_lower && nBits > maxBits ) { |
| 297 int j; |
| 298 for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { |
| 299 int sum=0; |
| 300 for ( j = i*psEnc->sCmn.subfr_length; j < (i+1)*psEnc->sCmn.
subfr_length; j++ ) { |
| 301 sum += abs( psEnc->sCmn.pulses[j] ); |
| 302 } |
| 303 if ( iter == 0 || (sum < best_sum[i] && !gain_lock[i]) ) { |
| 304 best_sum[i] = sum; |
| 305 best_gain_mult[i] = gainMult_Q8; |
| 306 } else { |
| 307 gain_lock[i] = 1; |
| 308 } |
| 309 } |
| 310 } |
| 268 if( ( found_lower & found_upper ) == 0 ) { | 311 if( ( found_lower & found_upper ) == 0 ) { |
| 269 /* Adjust gain according to high-rate rate/distortion curve */ | 312 /* Adjust gain according to high-rate rate/distortion curve */ |
| 270 opus_int32 gain_factor_Q16; | |
| 271 gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits, 7
) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) ); | |
| 272 gain_factor_Q16 = silk_min_32( gain_factor_Q16, SILK_FIX_CONST(
2, 16 ) ); | |
| 273 if( nBits > maxBits ) { | 313 if( nBits > maxBits ) { |
| 274 gain_factor_Q16 = silk_max_32( gain_factor_Q16, SILK_FIX_CON
ST( 1.3, 16 ) ); | 314 if (gainMult_Q8 < 16384) { |
| 315 gainMult_Q8 *= 2; |
| 316 } else { |
| 317 gainMult_Q8 = 32767; |
| 318 } |
| 319 } else { |
| 320 opus_int32 gain_factor_Q16; |
| 321 gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits
, 7 ) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) ); |
| 322 gainMult_Q8 = silk_SMULWB( gain_factor_Q16, gainMult_Q8 ); |
| 275 } | 323 } |
| 276 gainMult_Q8 = silk_SMULWB( gain_factor_Q16, gainMult_Q8 ); | 324 |
| 277 } else { | 325 } else { |
| 278 /* Adjust gain by interpolating */ | 326 /* Adjust gain by interpolating */ |
| 279 gainMult_Q8 = gainMult_lower + silk_DIV32_16( silk_MUL( gainMult
_upper - gainMult_lower, maxBits - nBits_lower ), nBits_upper - nBits_lower ); | 327 gainMult_Q8 = gainMult_lower + silk_DIV32_16( silk_MUL( gainMult
_upper - gainMult_lower, maxBits - nBits_lower ), nBits_upper - nBits_lower ); |
| 280 /* New gain multplier must be between 25% and 75% of old range (
note that gainMult_upper < gainMult_lower) */ | 328 /* New gain multplier must be between 25% and 75% of old range (
note that gainMult_upper < gainMult_lower) */ |
| 281 if( gainMult_Q8 > silk_ADD_RSHIFT32( gainMult_lower, gainMult_up
per - gainMult_lower, 2 ) ) { | 329 if( gainMult_Q8 > silk_ADD_RSHIFT32( gainMult_lower, gainMult_up
per - gainMult_lower, 2 ) ) { |
| 282 gainMult_Q8 = silk_ADD_RSHIFT32( gainMult_lower, gainMult_up
per - gainMult_lower, 2 ); | 330 gainMult_Q8 = silk_ADD_RSHIFT32( gainMult_lower, gainMult_up
per - gainMult_lower, 2 ); |
| 283 } else | 331 } else |
| 284 if( gainMult_Q8 < silk_SUB_RSHIFT32( gainMult_upper, gainMult_up
per - gainMult_lower, 2 ) ) { | 332 if( gainMult_Q8 < silk_SUB_RSHIFT32( gainMult_upper, gainMult_up
per - gainMult_lower, 2 ) ) { |
| 285 gainMult_Q8 = silk_SUB_RSHIFT32( gainMult_upper, gainMult_up
per - gainMult_lower, 2 ); | 333 gainMult_Q8 = silk_SUB_RSHIFT32( gainMult_upper, gainMult_up
per - gainMult_lower, 2 ); |
| 286 } | 334 } |
| 287 } | 335 } |
| 288 | 336 |
| 289 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { | 337 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { |
| 290 sEncCtrl.Gains_Q16[ i ] = silk_LSHIFT_SAT32( silk_SMULWB( sEncCt
rl.GainsUnq_Q16[ i ], gainMult_Q8 ), 8 ); | 338 opus_int16 tmp; |
| 339 if ( gain_lock[i] ) { |
| 340 tmp = best_gain_mult[i]; |
| 341 } else { |
| 342 tmp = gainMult_Q8; |
| 343 } |
| 344 sEncCtrl.Gains_Q16[ i ] = silk_LSHIFT_SAT32( silk_SMULWB( sEncCt
rl.GainsUnq_Q16[ i ], tmp ), 8 ); |
| 291 } | 345 } |
| 292 | 346 |
| 293 /* Quantize gains */ | 347 /* Quantize gains */ |
| 294 psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; | 348 psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; |
| 295 silk_gains_quant( psEnc->sCmn.indices.GainsIndices, sEncCtrl.Gains_Q
16, | 349 silk_gains_quant( psEnc->sCmn.indices.GainsIndices, sEncCtrl.Gains_Q
16, |
| 296 &psEnc->sShape.LastGainIndex, condCoding == CODE_CONDITIONALLY
, psEnc->sCmn.nb_subfr ); | 350 &psEnc->sShape.LastGainIndex, condCoding == CODE_CONDITIONALLY
, psEnc->sCmn.nb_subfr ); |
| 297 | 351 |
| 298 /* Unique identifier of gains vector */ | 352 /* Unique identifier of gains vector */ |
| 299 gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sC
mn.nb_subfr ); | 353 gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sC
mn.nb_subfr ); |
| 300 } | 354 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 324 *pnBytesOut = silk_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); | 378 *pnBytesOut = silk_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 ); |
| 325 | 379 |
| 326 RESTORE_STACK; | 380 RESTORE_STACK; |
| 327 return ret; | 381 return ret; |
| 328 } | 382 } |
| 329 | 383 |
| 330 /* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excit
ation at lower bitrate */ | 384 /* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excit
ation at lower bitrate */ |
| 331 static OPUS_INLINE void silk_LBRR_encode_FIX( | 385 static OPUS_INLINE void silk_LBRR_encode_FIX( |
| 332 silk_encoder_state_FIX *psEnc, /* I
/O Pointer to Silk FIX encoder state
*/ | 386 silk_encoder_state_FIX *psEnc, /* I
/O Pointer to Silk FIX encoder state
*/ |
| 333 silk_encoder_control_FIX *psEncCtrl, /* I
/O Pointer to Silk FIX encoder control struct
*/ | 387 silk_encoder_control_FIX *psEncCtrl, /* I
/O Pointer to Silk FIX encoder control struct
*/ |
| 334 const opus_int32 xfw_Q3[], /* I
Input signal
*/ | 388 const opus_int16 x16[], /* I
Input signal
*/ |
| 335 opus_int condCoding /* I
The type of conditional coding used so far for this frame
*/ | 389 opus_int condCoding /* I
The type of conditional coding used so far for this frame
*/ |
| 336 ) | 390 ) |
| 337 { | 391 { |
| 338 opus_int32 TempGains_Q16[ MAX_NB_SUBFR ]; | 392 opus_int32 TempGains_Q16[ MAX_NB_SUBFR ]; |
| 339 SideInfoIndices *psIndices_LBRR = &psEnc->sCmn.indices_LBRR[ psEnc->sCmn.nFr
amesEncoded ]; | 393 SideInfoIndices *psIndices_LBRR = &psEnc->sCmn.indices_LBRR[ psEnc->sCmn.nFr
amesEncoded ]; |
| 340 silk_nsq_state sNSQ_LBRR; | 394 silk_nsq_state sNSQ_LBRR; |
| 341 | 395 |
| 342 /*******************************************/ | 396 /*******************************************/ |
| 343 /* Control use of inband LBRR */ | 397 /* Control use of inband LBRR */ |
| 344 /*******************************************/ | 398 /*******************************************/ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 363 | 417 |
| 364 /* Decode to get gains in sync with decoder */ | 418 /* Decode to get gains in sync with decoder */ |
| 365 /* Overwrite unquantized gains with quantized gains */ | 419 /* Overwrite unquantized gains with quantized gains */ |
| 366 silk_gains_dequant( psEncCtrl->Gains_Q16, psIndices_LBRR->GainsIndices, | 420 silk_gains_dequant( psEncCtrl->Gains_Q16, psIndices_LBRR->GainsIndices, |
| 367 &psEnc->sCmn.LBRRprevLastGainIndex, condCoding == CODE_CONDITIONALLY
, psEnc->sCmn.nb_subfr ); | 421 &psEnc->sCmn.LBRRprevLastGainIndex, condCoding == CODE_CONDITIONALLY
, psEnc->sCmn.nb_subfr ); |
| 368 | 422 |
| 369 /*****************************************/ | 423 /*****************************************/ |
| 370 /* Noise shaping quantization */ | 424 /* Noise shaping quantization */ |
| 371 /*****************************************/ | 425 /*****************************************/ |
| 372 if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 >
0 ) { | 426 if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 >
0 ) { |
| 373 silk_NSQ_del_dec( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, xfw_Q3, | 427 silk_NSQ_del_dec( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, x16, |
| 374 psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl
->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, | 428 psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl
->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, |
| 375 psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Til
t_Q14, psEncCtrl->LF_shp_Q14, | 429 psEncCtrl->AR_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt
_Q14, psEncCtrl->LF_shp_Q14, |
| 376 psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10,
psEncCtrl->LTP_scale_Q14, psEnc->sCmn.arch ); | 430 psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10,
psEncCtrl->LTP_scale_Q14, psEnc->sCmn.arch ); |
| 377 } else { | 431 } else { |
| 378 silk_NSQ( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, xfw_Q3, | 432 silk_NSQ( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, x16, |
| 379 psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl
->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, | 433 psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl
->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14, |
| 380 psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Til
t_Q14, psEncCtrl->LF_shp_Q14, | 434 psEncCtrl->AR_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt
_Q14, psEncCtrl->LF_shp_Q14, |
| 381 psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10,
psEncCtrl->LTP_scale_Q14, psEnc->sCmn.arch ); | 435 psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10,
psEncCtrl->LTP_scale_Q14, psEnc->sCmn.arch ); |
| 382 } | 436 } |
| 383 | 437 |
| 384 /* Restore original gains */ | 438 /* Restore original gains */ |
| 385 silk_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, psEnc->sCmn.nb_subfr *
sizeof( opus_int32 ) ); | 439 silk_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, psEnc->sCmn.nb_subfr *
sizeof( opus_int32 ) ); |
| 386 } | 440 } |
| 387 } | 441 } |
| OLD | NEW |