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_FLP.h" | 33 #include "main_FLP.h" |
33 #include "tuning_parameters.h" | 34 #include "tuning_parameters.h" |
34 | 35 |
35 /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with
lower bitrate */ | 36 /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with
lower bitrate */ |
36 static OPUS_INLINE void silk_LBRR_encode_FLP( | 37 static OPUS_INLINE void silk_LBRR_encode_FLP( |
37 silk_encoder_state_FLP *psEnc, /* I/O
Encoder state FLP */ | 38 silk_encoder_state_FLP *psEnc, /* I/O
Encoder state FLP */ |
38 silk_encoder_control_FLP *psEncCtrl, /* I/O
Encoder control FLP */ | 39 silk_encoder_control_FLP *psEncCtrl, /* I/O
Encoder control FLP */ |
39 const silk_float xfw[], /* I
Input signal */ | 40 const silk_float xfw[], /* I
Input signal */ |
40 opus_int condCoding /* I
The type of conditional coding used so far for this frame */ | 41 opus_int condCoding /* I
The type of conditional coding used so far for this frame */ |
41 ); | 42 ); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 opus_int32 *pnBytesOut, /* O
Number of payload bytes; */ | 79 opus_int32 *pnBytesOut, /* O
Number of payload bytes; */ |
79 ec_enc *psRangeEnc, /* I/O
compressor data structure */ | 80 ec_enc *psRangeEnc, /* I/O
compressor data structure */ |
80 opus_int condCoding, /* I
The type of conditional coding to use */ | 81 opus_int condCoding, /* I
The type of conditional coding to use */ |
81 opus_int maxBits, /* I
If > 0: maximum number of output bits */ | 82 opus_int maxBits, /* I
If > 0: maximum number of output bits */ |
82 opus_int useCBR /* I
Flag to force constant-bitrate operation */ | 83 opus_int useCBR /* I
Flag to force constant-bitrate operation */ |
83 ) | 84 ) |
84 { | 85 { |
85 silk_encoder_control_FLP sEncCtrl; | 86 silk_encoder_control_FLP sEncCtrl; |
86 opus_int i, iter, maxIter, found_upper, found_lower, ret = 0; | 87 opus_int i, iter, maxIter, found_upper, found_lower, ret = 0; |
87 silk_float *x_frame, *res_pitch_frame; | 88 silk_float *x_frame, *res_pitch_frame; |
88 silk_float xfw[ MAX_FRAME_LENGTH ]; | |
89 silk_float res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ]; | 89 silk_float res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ]; |
90 ec_enc sRangeEnc_copy, sRangeEnc_copy2; | 90 ec_enc sRangeEnc_copy, sRangeEnc_copy2; |
91 silk_nsq_state sNSQ_copy, sNSQ_copy2; | 91 silk_nsq_state sNSQ_copy, sNSQ_copy2; |
92 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; |
93 opus_int32 gainsID, gainsID_lower, gainsID_upper; | 93 opus_int32 gainsID, gainsID_lower, gainsID_upper; |
94 opus_int16 gainMult_Q8; | 94 opus_int16 gainMult_Q8; |
95 opus_int16 ec_prevLagIndex_copy; | 95 opus_int16 ec_prevLagIndex_copy; |
96 opus_int ec_prevSignalType_copy; | 96 opus_int ec_prevSignalType_copy; |
97 opus_int8 LastGainIndex_copy2; | 97 opus_int8 LastGainIndex_copy2; |
98 opus_int32 pGains_Q16[ MAX_NB_SUBFR ]; | 98 opus_int32 pGains_Q16[ MAX_NB_SUBFR ]; |
99 opus_uint8 ec_buf_copy[ 1275 ]; | 99 opus_uint8 ec_buf_copy[ 1275 ]; |
| 100 opus_int gain_lock[ MAX_NB_SUBFR ] = {0}; |
| 101 opus_int16 best_gain_mult[ MAX_NB_SUBFR ]; |
| 102 opus_int best_sum[ MAX_NB_SUBFR ]; |
100 | 103 |
101 /* This is totally unnecessary but many compilers (including gcc) are too du
mb to realise it */ | 104 /* This is totally unnecessary but many compilers (including gcc) are too du
mb to realise it */ |
102 LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_
upper = 0; | 105 LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_
upper = 0; |
103 | 106 |
104 psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3; | 107 psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3; |
105 | 108 |
106 /**************************************************************/ | 109 /**************************************************************/ |
107 /* Set up Input Pointers, and insert frame in input buffer */ | 110 /* Set up Input Pointers, and insert frame in input buffer */ |
108 /**************************************************************/ | 111 /**************************************************************/ |
109 /* pointers aligned with start of frame to encode */ | 112 /* pointers aligned with start of frame to encode */ |
(...skipping 22 matching lines...) Expand all Loading... |
132 silk_find_pitch_lags_FLP( psEnc, &sEncCtrl, res_pitch, x_frame, psEnc->s
Cmn.arch ); | 135 silk_find_pitch_lags_FLP( psEnc, &sEncCtrl, res_pitch, x_frame, psEnc->s
Cmn.arch ); |
133 | 136 |
134 /************************/ | 137 /************************/ |
135 /* Noise shape analysis */ | 138 /* Noise shape analysis */ |
136 /************************/ | 139 /************************/ |
137 silk_noise_shape_analysis_FLP( psEnc, &sEncCtrl, res_pitch_frame, x_fram
e ); | 140 silk_noise_shape_analysis_FLP( psEnc, &sEncCtrl, res_pitch_frame, x_fram
e ); |
138 | 141 |
139 /***************************************************/ | 142 /***************************************************/ |
140 /* Find linear prediction coefficients (LPC + LTP) */ | 143 /* Find linear prediction coefficients (LPC + LTP) */ |
141 /***************************************************/ | 144 /***************************************************/ |
142 silk_find_pred_coefs_FLP( psEnc, &sEncCtrl, res_pitch, x_frame, condCodi
ng ); | 145 silk_find_pred_coefs_FLP( psEnc, &sEncCtrl, res_pitch_frame, x_frame, co
ndCoding ); |
143 | 146 |
144 /****************************************/ | 147 /****************************************/ |
145 /* Process gains */ | 148 /* Process gains */ |
146 /****************************************/ | 149 /****************************************/ |
147 silk_process_gains_FLP( psEnc, &sEncCtrl, condCoding ); | 150 silk_process_gains_FLP( psEnc, &sEncCtrl, condCoding ); |
148 | 151 |
149 /*****************************************/ | |
150 /* Prefiltering for noise shaper */ | |
151 /*****************************************/ | |
152 silk_prefilter_FLP( psEnc, &sEncCtrl, xfw, x_frame ); | |
153 | |
154 /****************************************/ | 152 /****************************************/ |
155 /* Low Bitrate Redundant Encoding */ | 153 /* Low Bitrate Redundant Encoding */ |
156 /****************************************/ | 154 /****************************************/ |
157 silk_LBRR_encode_FLP( psEnc, &sEncCtrl, xfw, condCoding ); | 155 silk_LBRR_encode_FLP( psEnc, &sEncCtrl, x_frame, condCoding ); |
158 | 156 |
159 /* Loop over quantizer and entroy coding to control bitrate */ | 157 /* Loop over quantizer and entroy coding to control bitrate */ |
160 maxIter = 6; | 158 maxIter = 6; |
161 gainMult_Q8 = SILK_FIX_CONST( 1, 8 ); | 159 gainMult_Q8 = SILK_FIX_CONST( 1, 8 ); |
162 found_lower = 0; | 160 found_lower = 0; |
163 found_upper = 0; | 161 found_upper = 0; |
164 gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.n
b_subfr ); | 162 gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.n
b_subfr ); |
165 gainsID_lower = -1; | 163 gainsID_lower = -1; |
166 gainsID_upper = -1; | 164 gainsID_upper = -1; |
167 /* Copy part of the input state */ | 165 /* Copy part of the input state */ |
(...skipping 13 matching lines...) Expand all Loading... |
181 silk_memcpy( psRangeEnc, &sRangeEnc_copy, sizeof( ec_enc ) )
; | 179 silk_memcpy( psRangeEnc, &sRangeEnc_copy, sizeof( ec_enc ) )
; |
182 silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy, sizeof( silk_nsq
_state ) ); | 180 silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy, sizeof( silk_nsq
_state ) ); |
183 psEnc->sCmn.indices.Seed = seed_copy; | 181 psEnc->sCmn.indices.Seed = seed_copy; |
184 psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; | 182 psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; |
185 psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; | 183 psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; |
186 } | 184 } |
187 | 185 |
188 /*****************************************/ | 186 /*****************************************/ |
189 /* Noise shaping quantization */ | 187 /* Noise shaping quantization */ |
190 /*****************************************/ | 188 /*****************************************/ |
191 silk_NSQ_wrapper_FLP( psEnc, &sEncCtrl, &psEnc->sCmn.indices, &p
sEnc->sCmn.sNSQ, psEnc->sCmn.pulses, xfw ); | 189 silk_NSQ_wrapper_FLP( psEnc, &sEncCtrl, &psEnc->sCmn.indices, &p
sEnc->sCmn.sNSQ, psEnc->sCmn.pulses, x_frame ); |
| 190 |
| 191 if ( iter == maxIter && !found_lower ) { |
| 192 silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc )
); |
| 193 } |
192 | 194 |
193 /****************************************/ | 195 /****************************************/ |
194 /* Encode Parameters */ | 196 /* Encode Parameters */ |
195 /****************************************/ | 197 /****************************************/ |
196 silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFram
esEncoded, 0, condCoding ); | 198 silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFram
esEncoded, 0, condCoding ); |
197 | 199 |
198 /****************************************/ | 200 /****************************************/ |
199 /* Encode Excitation Signal */ | 201 /* Encode Excitation Signal */ |
200 /****************************************/ | 202 /****************************************/ |
201 silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType,
psEnc->sCmn.indices.quantOffsetType, | 203 silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType,
psEnc->sCmn.indices.quantOffsetType, |
202 psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); | 204 psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); |
203 | 205 |
204 nBits = ec_tell( psRangeEnc ); | 206 nBits = ec_tell( psRangeEnc ); |
205 | 207 |
| 208 /* If we still bust after the last iteration, do some damage con
trol. */ |
| 209 if ( iter == maxIter && !found_lower && nBits > maxBits ) { |
| 210 silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc )
); |
| 211 |
| 212 /* Keep gains the same as the last frame. */ |
| 213 psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; |
| 214 for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { |
| 215 psEnc->sCmn.indices.GainsIndices[ i ] = 4; |
| 216 } |
| 217 if (condCoding != CODE_CONDITIONALLY) { |
| 218 psEnc->sCmn.indices.GainsIndices[ 0 ] = sEncCtrl.lastGain
IndexPrev; |
| 219 } |
| 220 psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy; |
| 221 psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy; |
| 222 /* Clear all pulses. */ |
| 223 for ( i = 0; i < psEnc->sCmn.frame_length; i++ ) { |
| 224 psEnc->sCmn.pulses[ i ] = 0; |
| 225 } |
| 226 |
| 227 silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.n
FramesEncoded, 0, condCoding ); |
| 228 |
| 229 silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalTy
pe, psEnc->sCmn.indices.quantOffsetType, |
| 230 psEnc->sCmn.pulses, psEnc->sCmn.frame_length ); |
| 231 |
| 232 nBits = ec_tell( psRangeEnc ); |
| 233 } |
| 234 |
206 if( useCBR == 0 && iter == 0 && nBits <= maxBits ) { | 235 if( useCBR == 0 && iter == 0 && nBits <= maxBits ) { |
207 break; | 236 break; |
208 } | 237 } |
209 } | 238 } |
210 | 239 |
211 if( iter == maxIter ) { | 240 if( iter == maxIter ) { |
212 if( found_lower && ( gainsID == gainsID_lower || nBits > maxBits
) ) { | 241 if( found_lower && ( gainsID == gainsID_lower || nBits > maxBits
) ) { |
213 /* Restore output state from earlier iteration that did meet
the bitrate budget */ | 242 /* Restore output state from earlier iteration that did meet
the bitrate budget */ |
214 silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc )
); | 243 silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc )
); |
215 silk_assert( sRangeEnc_copy2.offs <= 1275 ); | 244 silk_assert( sRangeEnc_copy2.offs <= 1275 ); |
216 silk_memcpy( psRangeEnc->buf, ec_buf_copy, sRangeEnc_copy2.o
ffs ); | 245 silk_memcpy( psRangeEnc->buf, ec_buf_copy, sRangeEnc_copy2.o
ffs ); |
217 silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy2, sizeof( silk_ns
q_state ) ); | 246 silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy2, sizeof( silk_ns
q_state ) ); |
218 psEnc->sShape.LastGainIndex = LastGainIndex_copy2; | 247 psEnc->sShape.LastGainIndex = LastGainIndex_copy2; |
219 } | 248 } |
220 break; | 249 break; |
221 } | 250 } |
222 | 251 |
223 if( nBits > maxBits ) { | 252 if( nBits > maxBits ) { |
224 if( found_lower == 0 && iter >= 2 ) { | 253 if( found_lower == 0 && iter >= 2 ) { |
225 /* Adjust the quantizer's rate/distortion tradeoff and disca
rd previous "upper" results */ | 254 /* Adjust the quantizer's rate/distortion tradeoff and disca
rd previous "upper" results */ |
226 sEncCtrl.Lambda *= 1.5f; | 255 sEncCtrl.Lambda = silk_max_float(sEncCtrl.Lambda*1.5f, 1.5f)
; |
| 256 /* Reducing dithering can help us hit the target. */ |
| 257 psEnc->sCmn.indices.quantOffsetType = 0; |
227 found_upper = 0; | 258 found_upper = 0; |
228 gainsID_upper = -1; | 259 gainsID_upper = -1; |
229 } else { | 260 } else { |
230 found_upper = 1; | 261 found_upper = 1; |
231 nBits_upper = nBits; | 262 nBits_upper = nBits; |
232 gainMult_upper = gainMult_Q8; | 263 gainMult_upper = gainMult_Q8; |
233 gainsID_upper = gainsID; | 264 gainsID_upper = gainsID; |
234 } | 265 } |
235 } else if( nBits < maxBits - 5 ) { | 266 } else if( nBits < maxBits - 5 ) { |
236 found_lower = 1; | 267 found_lower = 1; |
237 nBits_lower = nBits; | 268 nBits_lower = nBits; |
238 gainMult_lower = gainMult_Q8; | 269 gainMult_lower = gainMult_Q8; |
239 if( gainsID != gainsID_lower ) { | 270 if( gainsID != gainsID_lower ) { |
240 gainsID_lower = gainsID; | 271 gainsID_lower = gainsID; |
241 /* Copy part of the output state */ | 272 /* Copy part of the output state */ |
242 silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc )
); | 273 silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc )
); |
243 silk_assert( psRangeEnc->offs <= 1275 ); | 274 silk_assert( psRangeEnc->offs <= 1275 ); |
244 silk_memcpy( ec_buf_copy, psRangeEnc->buf, psRangeEnc->offs
); | 275 silk_memcpy( ec_buf_copy, psRangeEnc->buf, psRangeEnc->offs
); |
245 silk_memcpy( &sNSQ_copy2, &psEnc->sCmn.sNSQ, sizeof( silk_ns
q_state ) ); | 276 silk_memcpy( &sNSQ_copy2, &psEnc->sCmn.sNSQ, sizeof( silk_ns
q_state ) ); |
246 LastGainIndex_copy2 = psEnc->sShape.LastGainIndex; | 277 LastGainIndex_copy2 = psEnc->sShape.LastGainIndex; |
247 } | 278 } |
248 } else { | 279 } else { |
249 /* Within 5 bits of budget: close enough */ | 280 /* Within 5 bits of budget: close enough */ |
250 break; | 281 break; |
251 } | 282 } |
252 | 283 |
| 284 if ( !found_lower && nBits > maxBits ) { |
| 285 int j; |
| 286 for ( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { |
| 287 int sum=0; |
| 288 for ( j = i*psEnc->sCmn.subfr_length; j < (i+1)*psEnc->sCmn.
subfr_length; j++ ) { |
| 289 sum += abs( psEnc->sCmn.pulses[j] ); |
| 290 } |
| 291 if ( iter == 0 || (sum < best_sum[i] && !gain_lock[i]) ) { |
| 292 best_sum[i] = sum; |
| 293 best_gain_mult[i] = gainMult_Q8; |
| 294 } else { |
| 295 gain_lock[i] = 1; |
| 296 } |
| 297 } |
| 298 } |
253 if( ( found_lower & found_upper ) == 0 ) { | 299 if( ( found_lower & found_upper ) == 0 ) { |
254 /* Adjust gain according to high-rate rate/distortion curve */ | 300 /* Adjust gain according to high-rate rate/distortion curve */ |
255 opus_int32 gain_factor_Q16; | |
256 gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits, 7
) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) ); | |
257 gain_factor_Q16 = silk_min_32( gain_factor_Q16, SILK_FIX_CONST(
2, 16 ) ); | |
258 if( nBits > maxBits ) { | 301 if( nBits > maxBits ) { |
259 gain_factor_Q16 = silk_max_32( gain_factor_Q16, SILK_FIX_CON
ST( 1.3, 16 ) ); | 302 if (gainMult_Q8 < 16384) { |
| 303 gainMult_Q8 *= 2; |
| 304 } else { |
| 305 gainMult_Q8 = 32767; |
| 306 } |
| 307 } else { |
| 308 opus_int32 gain_factor_Q16; |
| 309 gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits
, 7 ) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) ); |
| 310 gainMult_Q8 = silk_SMULWB( gain_factor_Q16, gainMult_Q8 ); |
260 } | 311 } |
261 gainMult_Q8 = silk_SMULWB( gain_factor_Q16, gainMult_Q8 ); | |
262 } else { | 312 } else { |
263 /* Adjust gain by interpolating */ | 313 /* Adjust gain by interpolating */ |
264 gainMult_Q8 = gainMult_lower + ( ( gainMult_upper - gainMult_low
er ) * ( maxBits - nBits_lower ) ) / ( nBits_upper - nBits_lower ); | 314 gainMult_Q8 = gainMult_lower + ( ( gainMult_upper - gainMult_low
er ) * ( maxBits - nBits_lower ) ) / ( nBits_upper - nBits_lower ); |
265 /* New gain multplier must be between 25% and 75% of old range (
note that gainMult_upper < gainMult_lower) */ | 315 /* New gain multplier must be between 25% and 75% of old range (
note that gainMult_upper < gainMult_lower) */ |
266 if( gainMult_Q8 > silk_ADD_RSHIFT32( gainMult_lower, gainMult_up
per - gainMult_lower, 2 ) ) { | 316 if( gainMult_Q8 > silk_ADD_RSHIFT32( gainMult_lower, gainMult_up
per - gainMult_lower, 2 ) ) { |
267 gainMult_Q8 = silk_ADD_RSHIFT32( gainMult_lower, gainMult_up
per - gainMult_lower, 2 ); | 317 gainMult_Q8 = silk_ADD_RSHIFT32( gainMult_lower, gainMult_up
per - gainMult_lower, 2 ); |
268 } else | 318 } else |
269 if( gainMult_Q8 < silk_SUB_RSHIFT32( gainMult_upper, gainMult_up
per - gainMult_lower, 2 ) ) { | 319 if( gainMult_Q8 < silk_SUB_RSHIFT32( gainMult_upper, gainMult_up
per - gainMult_lower, 2 ) ) { |
270 gainMult_Q8 = silk_SUB_RSHIFT32( gainMult_upper, gainMult_up
per - gainMult_lower, 2 ); | 320 gainMult_Q8 = silk_SUB_RSHIFT32( gainMult_upper, gainMult_up
per - gainMult_lower, 2 ); |
271 } | 321 } |
272 } | 322 } |
273 | 323 |
274 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { | 324 for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) { |
275 pGains_Q16[ i ] = silk_LSHIFT_SAT32( silk_SMULWB( sEncCtrl.Gains
Unq_Q16[ i ], gainMult_Q8 ), 8 ); | 325 opus_int16 tmp; |
| 326 if ( gain_lock[i] ) { |
| 327 tmp = best_gain_mult[i]; |
| 328 } else { |
| 329 tmp = gainMult_Q8; |
| 330 } |
| 331 pGains_Q16[ i ] = silk_LSHIFT_SAT32( silk_SMULWB( sEncCtrl.Gains
Unq_Q16[ i ], tmp ), 8 ); |
276 } | 332 } |
277 | 333 |
278 /* Quantize gains */ | 334 /* Quantize gains */ |
279 psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; | 335 psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev; |
280 silk_gains_quant( psEnc->sCmn.indices.GainsIndices, pGains_Q16, | 336 silk_gains_quant( psEnc->sCmn.indices.GainsIndices, pGains_Q16, |
281 &psEnc->sShape.LastGainIndex, condCoding == CODE_CONDITIONALLY
, psEnc->sCmn.nb_subfr ); | 337 &psEnc->sShape.LastGainIndex, condCoding == CODE_CONDITIONALLY
, psEnc->sCmn.nb_subfr ); |
282 | 338 |
283 /* Unique identifier of gains vector */ | 339 /* Unique identifier of gains vector */ |
284 gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sC
mn.nb_subfr ); | 340 gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sC
mn.nb_subfr ); |
285 | 341 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 /*****************************************/ | 419 /*****************************************/ |
364 /* Noise shaping quantization */ | 420 /* Noise shaping quantization */ |
365 /*****************************************/ | 421 /*****************************************/ |
366 silk_NSQ_wrapper_FLP( psEnc, psEncCtrl, psIndices_LBRR, &sNSQ_LBRR, | 422 silk_NSQ_wrapper_FLP( psEnc, psEncCtrl, psIndices_LBRR, &sNSQ_LBRR, |
367 psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], xfw ); | 423 psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], xfw ); |
368 | 424 |
369 /* Restore original gains */ | 425 /* Restore original gains */ |
370 silk_memcpy( psEncCtrl->Gains, TempGains, psEnc->sCmn.nb_subfr * sizeof(
silk_float ) ); | 426 silk_memcpy( psEncCtrl->Gains, TempGains, psEnc->sCmn.nb_subfr * sizeof(
silk_float ) ); |
371 } | 427 } |
372 } | 428 } |
OLD | NEW |