Reformatting changes with an update to the MSVC project files
[opus.git] / silk / fixed / encode_frame_FIX.c
1 /***********************************************************************
2 Copyright (c) 2006-2011, Skype Limited. All rights reserved.
3 Redistribution and use in source and binary forms, with or without
4 modification, (subject to the limitations in the disclaimer below)
5 are permitted provided that the following conditions are met:
6 - Redistributions of source code must retain the above copyright notice,
7 this list of conditions and the following disclaimer.
8 - Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution.
11 - Neither the name of Skype Limited, nor the names of specific
12 contributors, may be used to endorse or promote products derived from
13 this software without specific prior written permission.
14 NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
15 BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
16 CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
17 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***********************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include "main_FIX.h"
33 #include "tuning_parameters.h"
34
35 /* Low Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode with lower bitrate           */
36 static inline void silk_LBRR_encode_FIX(
37     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Pointer to Silk FIX encoder state                                           */
38     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  Pointer to Silk FIX encoder control struct                                  */
39     const opus_int16                xfw[],                                  /* I    Input signal                                                                */
40     opus_int                        condCoding                              /* I    The type of conditional coding used so far for this frame                   */
41 );
42
43 void silk_encode_do_VAD_FIX(
44     silk_encoder_state_FIX          *psEnc                                  /* I/O  Pointer to Silk FIX encoder state                                           */
45 )
46 {
47     /****************************/
48     /* Voice Activity Detection */
49     /****************************/
50     silk_VAD_GetSA_Q8( &psEnc->sCmn, psEnc->sCmn.inputBuf + 1 );
51
52     /**************************************************/
53     /* Convert speech activity into VAD and DTX flags */
54     /**************************************************/
55     if( psEnc->sCmn.speech_activity_Q8 < SILK_FIX_CONST( SPEECH_ACTIVITY_DTX_THRES, 8 ) ) {
56         psEnc->sCmn.indices.signalType = TYPE_NO_VOICE_ACTIVITY;
57         psEnc->sCmn.noSpeechCounter++;
58         if( psEnc->sCmn.noSpeechCounter < NB_SPEECH_FRAMES_BEFORE_DTX ) {
59             psEnc->sCmn.inDTX = 0;
60         } else if( psEnc->sCmn.noSpeechCounter > MAX_CONSECUTIVE_DTX + NB_SPEECH_FRAMES_BEFORE_DTX ) {
61             psEnc->sCmn.noSpeechCounter = NB_SPEECH_FRAMES_BEFORE_DTX;
62             psEnc->sCmn.inDTX           = 0;
63         }
64         psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesEncoded ] = 0;
65     } else {
66         psEnc->sCmn.noSpeechCounter    = 0;
67         psEnc->sCmn.inDTX              = 0;
68         psEnc->sCmn.indices.signalType = TYPE_UNVOICED;
69         psEnc->sCmn.VAD_flags[ psEnc->sCmn.nFramesEncoded ] = 1;
70     }
71 }
72
73 /****************/
74 /* Encode frame */
75 /****************/
76 opus_int silk_encode_frame_FIX(
77     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Pointer to Silk FIX encoder state                                           */
78     opus_int32                      *pnBytesOut,                            /* O    Pointer to number of payload bytes;                                         */
79     ec_enc                          *psRangeEnc,                            /* I/O  compressor data structure                                                   */
80     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                        useCBR                                  /* I    Flag to force constant-bitrate operation                                    */
83 )
84 {
85     silk_encoder_control_FIX sEncCtrl;
86     opus_int     i, iter, maxIter, found_upper, found_lower, ret = 0;
87     opus_int16   *x_frame, *res_pitch_frame;
88     opus_int16   xfw[ MAX_FRAME_LENGTH ];
89     opus_int16   res_pitch[ 2 * MAX_FRAME_LENGTH + LA_PITCH_MAX ];
90     ec_enc       sRangeEnc_copy, sRangeEnc_copy2;
91     silk_nsq_state sNSQ_copy, sNSQ_copy2;
92     opus_int32   seed_copy, nBits, nBits_lower, nBits_upper, gainMult_lower, gainMult_upper;
93     opus_int32   gainsID, gainsID_lower, gainsID_upper;
94     opus_int16   gainMult_Q8;
95     opus_int16   ec_prevLagIndex_copy;
96     opus_int     ec_prevSignalType_copy;
97     opus_int8    LastGainIndex_copy2;
98     opus_uint8   ec_buf_copy[ 1275 ];
99
100     /* This is totally unnecessary but many compilers (including gcc) are too dumb to realise it */
101     LastGainIndex_copy2 = nBits_lower = nBits_upper = gainMult_lower = gainMult_upper = 0;
102
103     psEnc->sCmn.indices.Seed = psEnc->sCmn.frameCounter++ & 3;
104
105     /**************************************************************/
106     /* Setup Input Pointers, and insert frame in input buffer    */
107     /*************************************************************/
108     /* pointers aligned with start of frame to encode */
109     x_frame         = psEnc->x_buf + psEnc->sCmn.ltp_mem_length;    /* start of frame to encode */
110     res_pitch_frame = res_pitch    + psEnc->sCmn.ltp_mem_length;    /* start of pitch LPC residual frame */
111
112     /***************************************/
113     /* Ensure smooth bandwidth transitions */
114     /***************************************/
115     silk_LP_variable_cutoff( &psEnc->sCmn.sLP, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.frame_length );
116
117     /*******************************************/
118     /* Copy new frame to front of input buffer */
119     /*******************************************/
120     silk_memcpy( x_frame + LA_SHAPE_MS * psEnc->sCmn.fs_kHz, psEnc->sCmn.inputBuf + 1, psEnc->sCmn.frame_length * sizeof( opus_int16 ) );
121
122     /*****************************************/
123     /* Find pitch lags, initial LPC analysis */
124     /*****************************************/
125     silk_find_pitch_lags_FIX( psEnc, &sEncCtrl, res_pitch, x_frame );
126
127     /************************/
128     /* Noise shape analysis */
129     /************************/
130     silk_noise_shape_analysis_FIX( psEnc, &sEncCtrl, res_pitch_frame, x_frame );
131
132     /***************************************************/
133     /* Find linear prediction coefficients (LPC + LTP) */
134     /***************************************************/
135     silk_find_pred_coefs_FIX( psEnc, &sEncCtrl, res_pitch, x_frame, condCoding );
136
137     /****************************************/
138     /* Process gains                        */
139     /****************************************/
140     silk_process_gains_FIX( psEnc, &sEncCtrl, condCoding );
141
142     /*****************************************/
143     /* Prefiltering for noise shaper         */
144     /*****************************************/
145     silk_prefilter_FIX( psEnc, &sEncCtrl, xfw, x_frame );
146
147     /****************************************/
148     /* Low Bitrate Redundant Encoding       */
149     /****************************************/
150     silk_LBRR_encode_FIX( psEnc, &sEncCtrl, xfw, condCoding );
151
152     if( psEnc->sCmn.prefillFlag ) {
153         if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {
154             silk_NSQ_del_dec( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, xfw, psEnc->sCmn.pulses,
155                    sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14,
156                    sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14 );
157         } else {
158             silk_NSQ( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, xfw, psEnc->sCmn.pulses,
159                    sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14,
160                    sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14 );
161         }
162     } else {
163         /* Loop over quantizer and entropy coding to control bitrate */
164         maxIter = 5;
165         gainMult_Q8 = SILK_FIX_CONST( 1, 8 );
166         found_lower = 0;
167         found_upper = 0;
168         gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.nb_subfr );
169         gainsID_lower = -1;
170         gainsID_upper = -1;
171         /* Copy part of the input state */
172         silk_memcpy( &sRangeEnc_copy, psRangeEnc, sizeof( ec_enc ) );
173         silk_memcpy( &sNSQ_copy, &psEnc->sCmn.sNSQ, sizeof( silk_nsq_state ) );
174         seed_copy = psEnc->sCmn.indices.Seed;
175         ec_prevLagIndex_copy = psEnc->sCmn.ec_prevLagIndex;
176         ec_prevSignalType_copy = psEnc->sCmn.ec_prevSignalType;
177         for( iter = 0; ; iter++ ) {
178             if( gainsID == gainsID_lower ) {
179                 nBits = nBits_lower;
180             } else if( gainsID == gainsID_upper ) {
181                 nBits = nBits_upper;
182             } else {
183                 /* Restore part of the input state */
184                 if( iter > 0 ) {
185                     silk_memcpy( psRangeEnc, &sRangeEnc_copy, sizeof( ec_enc ) );
186                     silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy, sizeof( silk_nsq_state ) );
187                     psEnc->sCmn.indices.Seed = seed_copy;
188                     psEnc->sCmn.ec_prevLagIndex = ec_prevLagIndex_copy;
189                     psEnc->sCmn.ec_prevSignalType = ec_prevSignalType_copy;
190                 }
191
192                 /*****************************************/
193                 /* Noise shaping quantization            */
194                 /*****************************************/
195                 if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {
196                     silk_NSQ_del_dec( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, xfw, psEnc->sCmn.pulses,
197                            sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14,
198                            sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14 );
199                 } else {
200                     silk_NSQ( &psEnc->sCmn, &psEnc->sCmn.sNSQ, &psEnc->sCmn.indices, xfw, psEnc->sCmn.pulses,
201                             sEncCtrl.PredCoef_Q12[ 0 ], sEncCtrl.LTPCoef_Q14, sEncCtrl.AR2_Q13, sEncCtrl.HarmShapeGain_Q14,
202                             sEncCtrl.Tilt_Q14, sEncCtrl.LF_shp_Q14, sEncCtrl.Gains_Q16, sEncCtrl.pitchL, sEncCtrl.Lambda_Q10, sEncCtrl.LTP_scale_Q14 );
203                 }
204
205                 /****************************************/
206                 /* Encode Parameters                    */
207                 /****************************************/
208                 silk_encode_indices( &psEnc->sCmn, psRangeEnc, psEnc->sCmn.nFramesEncoded, 0, condCoding );
209
210                 /****************************************/
211                 /* Encode Excitation Signal             */
212                 /****************************************/
213                 silk_encode_pulses( psRangeEnc, psEnc->sCmn.indices.signalType, psEnc->sCmn.indices.quantOffsetType,
214                     psEnc->sCmn.pulses, psEnc->sCmn.frame_length );
215
216                 nBits = ec_tell( psRangeEnc );
217
218                 if( useCBR == 0 && iter == 0 && nBits <= maxBits ) {
219                     break;
220                 }
221             }
222
223             if( iter == maxIter ) {
224                 if( found_lower && ( gainsID == gainsID_lower || nBits > maxBits ) ) {
225                     /* Restore output state from earlier iteration that did meet the bitrate budget */
226                     silk_memcpy( psRangeEnc, &sRangeEnc_copy2, sizeof( ec_enc ) );
227                     silk_assert( sRangeEnc_copy2.offs <= 1275 );
228                     silk_memcpy( psRangeEnc->buf, ec_buf_copy, sRangeEnc_copy2.offs );
229                     silk_memcpy( &psEnc->sCmn.sNSQ, &sNSQ_copy2, sizeof( silk_nsq_state ) );
230                     psEnc->sShape.LastGainIndex = LastGainIndex_copy2;
231                 }
232                 break;
233             }
234
235             if( nBits > maxBits ) {
236                 if( found_lower == 0 && iter >= 2 ) {
237                     /* Adjust the quantizer's rate/distortion tradeoff and discard previous "upper" results */
238                     sEncCtrl.Lambda_Q10 = silk_ADD_RSHIFT32( sEncCtrl.Lambda_Q10, sEncCtrl.Lambda_Q10, 1 );
239                     found_upper = 0;
240                     gainsID_upper = -1;
241                 } else {
242                     found_upper = 1;
243                     nBits_upper = nBits;
244                     gainMult_upper = gainMult_Q8;
245                     gainsID_upper = gainsID;
246                 }
247             } else if( nBits < maxBits - 5 ) {
248                 found_lower = 1;
249                 nBits_lower = nBits;
250                 gainMult_lower = gainMult_Q8;
251                 if( gainsID != gainsID_lower ) {
252                     gainsID_lower = gainsID;
253                     /* Copy part of the output state */
254                     silk_memcpy( &sRangeEnc_copy2, psRangeEnc, sizeof( ec_enc ) );
255                     silk_assert( psRangeEnc->offs <= 1275 );
256                     silk_memcpy( ec_buf_copy, psRangeEnc->buf, psRangeEnc->offs );
257                     silk_memcpy( &sNSQ_copy2, &psEnc->sCmn.sNSQ, sizeof( silk_nsq_state ) );
258                     LastGainIndex_copy2 = psEnc->sShape.LastGainIndex;
259                 }
260             } else {
261                 /* Within 5 bits of budget: close enough */
262                 break;
263             }
264
265             if( ( found_lower & found_upper ) == 0 ) {
266                 /* Adjust gain according to high-rate rate/distortion curve */
267                 opus_int32 gain_factor_Q16;
268                 gain_factor_Q16 = silk_log2lin( silk_LSHIFT( nBits - maxBits, 7 ) / psEnc->sCmn.frame_length + SILK_FIX_CONST( 16, 7 ) );
269                 gain_factor_Q16 = silk_min_32( gain_factor_Q16, SILK_FIX_CONST( 2, 16 ) );
270                 if( nBits > maxBits ) {
271                     gain_factor_Q16 = silk_max_32( gain_factor_Q16, SILK_FIX_CONST( 1.3, 16 ) );
272                 }
273                 gainMult_Q8 = silk_SMULWB( gain_factor_Q16, gainMult_Q8 );
274             } else {
275                 /* Adjust gain by interpolating */
276                 gainMult_Q8 = gainMult_lower + silk_DIV32_16( silk_MUL( gainMult_upper - gainMult_lower, maxBits - nBits_lower ), nBits_upper - nBits_lower );
277                 /* New gain multplier must be between 25% and 75% of old range (note that gainMult_upper < gainMult_lower) */
278                 if( gainMult_Q8 > silk_ADD_RSHIFT32( gainMult_lower, gainMult_upper - gainMult_lower, 2 ) ) {
279                     gainMult_Q8 = silk_ADD_RSHIFT32( gainMult_lower, gainMult_upper - gainMult_lower, 2 );
280                 } else
281                 if( gainMult_Q8 < silk_SUB_RSHIFT32( gainMult_upper, gainMult_upper - gainMult_lower, 2 ) ) {
282                     gainMult_Q8 = silk_SUB_RSHIFT32( gainMult_upper, gainMult_upper - gainMult_lower, 2 );
283                 }
284             }
285
286             for( i = 0; i < psEnc->sCmn.nb_subfr; i++ ) {
287                 sEncCtrl.Gains_Q16[ i ] = silk_LSHIFT_SAT32( silk_SMULWB( sEncCtrl.GainsUnq_Q16[ i ], gainMult_Q8 ), 8 );
288             }
289  
290             /* Quantize gains */
291             psEnc->sShape.LastGainIndex = sEncCtrl.lastGainIndexPrev;
292             silk_gains_quant( psEnc->sCmn.indices.GainsIndices, sEncCtrl.Gains_Q16,
293                   &psEnc->sShape.LastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr );
294
295             /* Unique identifier of gains vector */
296             gainsID = silk_gains_ID( psEnc->sCmn.indices.GainsIndices, psEnc->sCmn.nb_subfr );
297         }
298     }
299
300     /* Update input buffer */
301     silk_memmove( psEnc->x_buf, &psEnc->x_buf[ psEnc->sCmn.frame_length ],
302         ( psEnc->sCmn.ltp_mem_length + LA_SHAPE_MS * psEnc->sCmn.fs_kHz ) * sizeof( opus_int16 ) );
303
304     /* Parameters needed for next frame */
305     psEnc->sCmn.prevLag        = sEncCtrl.pitchL[ psEnc->sCmn.nb_subfr - 1 ];
306     psEnc->sCmn.prevSignalType = psEnc->sCmn.indices.signalType;
307
308     /* Exit without entropy coding */
309     if( psEnc->sCmn.prefillFlag ) {
310         /* No payload */
311         *pnBytesOut = 0;
312         return ret;
313     }
314
315     /****************************************/
316     /* Finalize payload                     */
317     /****************************************/
318     psEnc->sCmn.first_frame_after_reset = 0;
319     /* Payload size */
320     *pnBytesOut = silk_RSHIFT( ec_tell( psRangeEnc ) + 7, 3 );
321
322     return ret;
323 }
324
325 /* Low-Bitrate Redundancy (LBRR) encoding. Reuse all parameters but encode excitation at lower bitrate  */
326 static inline void silk_LBRR_encode_FIX(
327     silk_encoder_state_FIX          *psEnc,                                 /* I/O  Pointer to Silk FIX encoder state                                           */
328     silk_encoder_control_FIX        *psEncCtrl,                             /* I/O  Pointer to Silk FIX encoder control struct                                  */
329     const opus_int16                xfw[],                                  /* I    Input signal                                                                */
330     opus_int                        condCoding                              /* I    The type of conditional coding used so far for this frame                   */
331 )
332 {
333     opus_int32   TempGains_Q16[ MAX_NB_SUBFR ];
334     SideInfoIndices *psIndices_LBRR = &psEnc->sCmn.indices_LBRR[ psEnc->sCmn.nFramesEncoded ];
335     silk_nsq_state sNSQ_LBRR;
336
337     /*******************************************/
338     /* Control use of inband LBRR              */
339     /*******************************************/
340     if( psEnc->sCmn.LBRR_enabled && psEnc->sCmn.speech_activity_Q8 > SILK_FIX_CONST( LBRR_SPEECH_ACTIVITY_THRES, 8 ) ) {
341         psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesEncoded ] = 1;
342
343         /* Copy noise shaping quantizer state and quantization indices from regular encoding */
344         silk_memcpy( &sNSQ_LBRR, &psEnc->sCmn.sNSQ, sizeof( silk_nsq_state ) );
345         silk_memcpy( psIndices_LBRR, &psEnc->sCmn.indices, sizeof( SideInfoIndices ) );
346
347         /* Save original gains */
348         silk_memcpy( TempGains_Q16, psEncCtrl->Gains_Q16, psEnc->sCmn.nb_subfr * sizeof( opus_int32 ) );
349
350         if( psEnc->sCmn.nFramesEncoded == 0 || psEnc->sCmn.LBRR_flags[ psEnc->sCmn.nFramesEncoded - 1 ] == 0 ) {
351             /* First frame in packet or previous frame not LBRR coded */
352             psEnc->sCmn.LBRRprevLastGainIndex = psEnc->sShape.LastGainIndex;
353
354             /* Increase Gains to get target LBRR rate */
355             psIndices_LBRR->GainsIndices[ 0 ] = psIndices_LBRR->GainsIndices[ 0 ] + psEnc->sCmn.LBRR_GainIncreases;
356             psIndices_LBRR->GainsIndices[ 0 ] = silk_min_int( psIndices_LBRR->GainsIndices[ 0 ], N_LEVELS_QGAIN - 1 );
357         }
358
359         /* Decode to get gains in sync with decoder         */
360         /* Overwrite unquantized gains with quantized gains */
361         silk_gains_dequant( psEncCtrl->Gains_Q16, psIndices_LBRR->GainsIndices,
362             &psEnc->sCmn.LBRRprevLastGainIndex, condCoding == CODE_CONDITIONALLY, psEnc->sCmn.nb_subfr );
363
364         /*****************************************/
365         /* Noise shaping quantization            */
366         /*****************************************/
367         if( psEnc->sCmn.nStatesDelayedDecision > 1 || psEnc->sCmn.warping_Q16 > 0 ) {
368             silk_NSQ_del_dec( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, xfw,
369                 psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14,
370                 psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14,
371                 psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 );
372         } else {
373             silk_NSQ( &psEnc->sCmn, &sNSQ_LBRR, psIndices_LBRR, xfw,
374                 psEnc->sCmn.pulses_LBRR[ psEnc->sCmn.nFramesEncoded ], psEncCtrl->PredCoef_Q12[ 0 ], psEncCtrl->LTPCoef_Q14,
375                 psEncCtrl->AR2_Q13, psEncCtrl->HarmShapeGain_Q14, psEncCtrl->Tilt_Q14, psEncCtrl->LF_shp_Q14,
376                 psEncCtrl->Gains_Q16, psEncCtrl->pitchL, psEncCtrl->Lambda_Q10, psEncCtrl->LTP_scale_Q14 );
377         }
378
379         /* Restore original gains */
380         silk_memcpy( psEncCtrl->Gains_Q16, TempGains_Q16, psEnc->sCmn.nb_subfr * sizeof( opus_int32 ) );
381     }
382 }