LCOV - code coverage report
Current view: top level - lib_enc - tcx_ltp_enc.c (source / functions) Hit Total Coverage
Test: Coverage on main -- merged total coverage @ a21f94bc6bac334fe001a5bad2f7b32b79038097 Lines: 208 209 99.5 %
Date: 2025-11-01 08:50:45 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : /*====================================================================================
      34             :     EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
      35             :   ====================================================================================*/
      36             : 
      37             : #include <stdint.h>
      38             : #include "options.h"
      39             : #ifdef DEBUGGING
      40             : #include "debug.h"
      41             : #endif
      42             : #include <math.h>
      43             : #include "prot.h"
      44             : #include "rom_enc.h"
      45             : #include "rom_com.h"
      46             : #include "wmc_auto.h"
      47             : #ifdef DEBUG_PLOT
      48             : #include "deb_out.h"
      49             : #endif
      50             : 
      51             : 
      52             : /*---------------------------------------------------------------------*
      53             :  * interpolate_corr()
      54             :  *
      55             :  *
      56             :  *---------------------------------------------------------------------*/
      57             : 
      58             : /*! r: interpolated value */
      59    99557706 : static float interpolate_corr(
      60             :     const float *x,        /* i  : input vector         */
      61             :     const int16_t frac,    /* i  : fraction of lag      */
      62             :     const int16_t frac_max /* i  : max fraction         */
      63             : )
      64             : {
      65             :     int16_t i;
      66             :     float s;
      67             :     const float *c1, *c2, *x1, *x2, *win;
      68             : 
      69             : 
      70    99557706 :     if ( frac_max == 6 )
      71             :     {
      72     5392152 :         win = E_ROM_inter6_1;
      73             :     }
      74             :     else
      75             :     {
      76    94165554 :         win = E_ROM_inter4_1;
      77             :     }
      78             : 
      79    99557706 :     x1 = &x[0];
      80    99557706 :     x2 = &x[1];
      81    99557706 :     c1 = &win[frac];
      82    99557706 :     c2 = &win[frac_max - frac];
      83    99557706 :     s = 0.0f;
      84   497788530 :     for ( i = 0; i < 4; i++, c1 += frac_max, c2 += frac_max )
      85             :     {
      86   398230824 :         s += ( *x1-- ) * ( *c1 ) + ( *x2++ ) * ( *c2 );
      87             :     }
      88             : 
      89    99557706 :     return s;
      90             : }
      91             : 
      92             : 
      93             : /*---------------------------------------------------------------------*
      94             :  * tcx_ltp_pitch_search()
      95             :  *
      96             :  *
      97             :  *---------------------------------------------------------------------*/
      98             : 
      99    19348703 : static void tcx_ltp_pitch_search(
     100             :     const int16_t pitch_ol,
     101             :     int16_t *pitch_int,
     102             :     int16_t *pitch_fr,
     103             :     int16_t *index,
     104             :     float *norm_corr,
     105             :     const int16_t len,
     106             :     const float *wsp,
     107             :     const int16_t pitmin,
     108             :     const int16_t pitfr1,
     109             :     const int16_t pitfr2,
     110             :     const int16_t pitmax,
     111             :     const int16_t pitres,
     112             :     const int16_t check_border_case,
     113             :     int16_t *border_case )
     114             : {
     115             :     int16_t i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta;
     116             :     float temp, cor_max, cor[256], *pt_cor;
     117             : 
     118    19348703 :     if ( pitres == 6 )
     119             :     {
     120     2192858 :         delta = 8;
     121             :     }
     122             :     else
     123             :     {
     124    17155845 :         delta = 16;
     125             :     }
     126             : 
     127    19348703 :     t0_min = (int16_t) pitch_ol - ( delta >> 1 );
     128    19348703 :     t0_max = (int16_t) pitch_ol + ( delta >> 1 ) - 1;
     129             : 
     130    19348703 :     if ( t0_min < pitmin )
     131             :     {
     132     1699825 :         t0_min = pitmin;
     133     1699825 :         t0_max = t0_min + delta - 1;
     134             :     }
     135    19348703 :     if ( t0_max > pitmax )
     136             :     {
     137      439288 :         t0_max = pitmax;
     138      439288 :         t0_min = t0_max - delta + 1;
     139             :     }
     140             : 
     141             : 
     142    19348703 :     t_min = t0_min - L_INTERPOL1;
     143    19348703 :     t_max = t0_max + L_INTERPOL1;
     144             : 
     145    19348703 :     pt_cor = cor;
     146   466174711 :     for ( t = t_min; t <= t_max; t++ )
     147             :     {
     148   446826008 :         *pt_cor++ = dotp( wsp, wsp - t, len );
     149             :     }
     150             : 
     151    19348703 :     pt_cor = cor + L_INTERPOL1;
     152    19348703 :     cor_max = *pt_cor++;
     153    19348703 :     t1 = t0_min;
     154   292036384 :     for ( t = t0_min + 1; t <= t0_max; t++ )
     155             :     {
     156   272687681 :         if ( *pt_cor > cor_max )
     157             :         {
     158    91052659 :             cor_max = *pt_cor;
     159    91052659 :             t1 = t;
     160             :         }
     161   272687681 :         pt_cor++;
     162             :     }
     163    19348703 :     temp = dotp( wsp, wsp, len ) * dotp( wsp - t1, wsp - t1, len );
     164    19348703 :     *norm_corr = cor_max / (float) sqrt( temp + 0.1f );
     165             : 
     166             :     /* check for border cases at the low lag border */
     167             :     /*pt_cor=cor;*/
     168    19348703 :     if ( check_border_case && t1 == t0_min )
     169             :     {
     170             :         float tmpCor;
     171     6497598 :         for ( t = t1 - L_INTERPOL1; t < t1; t++ )
     172             :         {
     173     5615956 :             tmpCor = dotp( wsp, wsp - t, len );
     174     5615956 :             if ( tmpCor > cor_max )
     175             :             {
     176             :                 /* no real maximum but still on a rising slope */
     177             :                 /* keep t1 but set norm_corr to zero to avoid activating the LTP here */
     178     1386053 :                 *border_case = 1;
     179     1386053 :                 break;
     180             :             }
     181             :         }
     182             :     }
     183             : 
     184    19348703 :     if ( t1 >= pitfr1 )
     185             :     {
     186     3291560 :         *pitch_int = t1;
     187     3291560 :         *pitch_fr = 0;
     188     3291560 :         *index = t1 - pitfr1 + ( ( pitfr2 - pitmin ) * pitres ) + ( ( pitfr1 - pitfr2 ) * ( pitres >> 1 ) );
     189     3291560 :         return;
     190             :     }
     191             : 
     192             :     /*------------------------------------------------------------------*
     193             :      * Search fractional pitch with 1/4 subsample resolution.
     194             :      * search the fractions around t0 and choose the one which maximizes
     195             :      * the interpolated normalized correlation.
     196             :      *-----------------------------------------------------------------*/
     197             : 
     198    16057143 :     pt_cor = cor + L_INTERPOL1 - t0_min;
     199    16057143 :     t0 = t1;
     200    16057143 :     if ( t0 >= pitfr2 )
     201             :     {
     202     2895964 :         step = 2;
     203     2895964 :         fraction = 2;
     204             :     }
     205             :     else
     206             :     {
     207    13161179 :         step = 1;
     208    13161179 :         fraction = 1;
     209             :     }
     210             : 
     211    16057143 :     if ( t0 == t0_min ) /* Limit case */
     212             :     {
     213     2009437 :         fraction = 0;
     214     2009437 :         cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres );
     215             :     }
     216             :     else /* Process negative fractions */
     217             :     {
     218    14047706 :         t0--;
     219    14047706 :         cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres );
     220    37976954 :         for ( i = ( fraction + step ); i <= pitres - 1; i = i + step )
     221             :         {
     222    23929248 :             temp = interpolate_corr( &pt_cor[t0], i, pitres );
     223    23929248 :             if ( temp > cor_max )
     224             :             {
     225    22477217 :                 cor_max = temp;
     226    22477217 :                 fraction = i;
     227             :             }
     228             :         }
     229             :     }
     230             : 
     231    75628458 :     for ( i = 0; i <= pitres - 1; i = i + step ) /* Process positive fractions */
     232             :     {
     233    59571315 :         temp = interpolate_corr( &pt_cor[t1], i, pitres );
     234    59571315 :         if ( temp > cor_max )
     235             :         {
     236    17023511 :             cor_max = temp;
     237    17023511 :             fraction = i;
     238    17023511 :             t0 = t1;
     239             :         }
     240             :     }
     241    16057143 :     *pitch_int = t0;
     242    16057143 :     *pitch_fr = fraction;
     243    16057143 :     if ( t0 >= pitfr2 )
     244             :     {
     245     2879347 :         *index = t0 * ( pitres >> 1 ) + ( fraction >> 1 ) - ( pitfr2 * ( pitres >> 1 ) ) + ( ( pitfr2 - pitmin ) * pitres );
     246             :     }
     247             :     else
     248             :     {
     249    13177796 :         *index = t0 * pitres + fraction - ( pitmin * pitres );
     250             :     }
     251             : 
     252    16057143 :     return;
     253             : }
     254             : 
     255             : 
     256             : /*---------------------------------------------------------------------*
     257             :  * tcx_ltp_find_gain()
     258             :  *
     259             :  *
     260             :  *---------------------------------------------------------------------*/
     261             : 
     262    14594142 : static void tcx_ltp_find_gain(
     263             :     const float *speech,
     264             :     float *pred_speech,
     265             :     const int16_t L_frame,
     266             :     float *gain,
     267             :     int16_t *gain_index )
     268             : {
     269    14594142 :     int16_t gainbits = 2;
     270             : 
     271             :     /* Find gain */
     272    14594142 :     *gain = get_gain( speech, pred_speech, L_frame, NULL );
     273             : 
     274             :     /* Quantize gain */
     275    14594142 :     if ( *gain >= 0.875f )
     276             :     {
     277     2732637 :         *gain_index = 3; /* 1.00/2 */
     278             :     }
     279    11861505 :     else if ( *gain >= 0.625f )
     280             :     {
     281     3400339 :         *gain_index = 2; /* 0.75/2 */
     282             :     }
     283     8461166 :     else if ( *gain >= 0.375f )
     284             :     {
     285     3776538 :         *gain_index = 1; /* 0.50/2 */
     286             :     }
     287     4684628 :     else if ( *gain >= 0.125f )
     288             :     {
     289     3746089 :         *gain_index = 0; /* 0.25/2 */
     290             :     }
     291             :     else
     292             :     {
     293      938539 :         *gain_index = -1; /* escape */
     294             :     }
     295             :     /* Dequantize gain */
     296    14594142 :     *gain = (float) ( *gain_index + 1 ) * 0.625f / (float) ( 1 << gainbits );
     297             : 
     298    14594142 :     return;
     299             : }
     300             : 
     301             : /*---------------------------------------------------------------------*
     302             :  * tcx_ltp_encode()
     303             :  *
     304             :  *
     305             :  *---------------------------------------------------------------------*/
     306             : 
     307    14594142 : void tcx_ltp_encode(
     308             :     Encoder_State *st,
     309             :     const int16_t tcxMode,
     310             :     const int16_t L_frame,
     311             :     const float *speech,
     312             :     float *speech_ltp,
     313             :     const float *wsp,
     314             :     const int16_t Top[],
     315             :     int16_t *ltp_param,
     316             :     int16_t *ltp_bits,
     317             :     float *A,
     318             :     const int16_t disable_ltp,
     319             :     const int16_t element_mode )
     320             : {
     321             :     int16_t i, j, n;
     322             :     int16_t ltp_on, tcxOnly, L_subfr, SideInfoOnly, delta;
     323             :     float s;
     324             :     float norm_corr;
     325             :     float pred_speech[L_FRAME_PLUS];
     326             :     float tempFlatness;
     327             :     float maxEnergyChange;
     328             :     float buf_zir[M + L_FRAME_PLUS / 4], *zir;
     329             :     float r[M + 1], Aest[M + 1];
     330             :     float alpha, step;
     331             :     float si_gain;
     332             :     int16_t border_case;
     333             : 
     334    14594142 :     TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
     335             : 
     336    14594142 :     tcxOnly = st->tcxonly;
     337    14594142 :     L_subfr = L_SUBFR;
     338    14594142 :     SideInfoOnly = st->sr_core > 25600;
     339             : 
     340             :     /* Reset memory if past frame is acelp */
     341    14594142 :     if ( st->last_core == ACELP_CORE )
     342             :     {
     343      135801 :         hTcxEnc->tcxltp_pitch_int_past = L_frame;
     344      135801 :         hTcxEnc->tcxltp_pitch_fr_past = 0;
     345      135801 :         hTcxEnc->tcxltp_gain_past = 0.f;
     346             :     }
     347             : 
     348             :     /* By default, LTP is off */
     349    14594142 :     ltp_param[0] = 0;
     350    14594142 :     norm_corr = 0.0f;
     351    14594142 :     border_case = 0;
     352             : 
     353    14594142 :     if ( hTcxEnc->tcxltp || SideInfoOnly )
     354             :     {
     355             :         /* Find pitch lag */
     356    14594142 :         if ( st->pit_res_max == 6 )
     357             :         {
     358     2192858 :             delta = 8;
     359             :         }
     360             :         else
     361             :         {
     362    12401284 :             delta = 16;
     363             :         }
     364             : 
     365    14594142 :         if ( st->element_mode == IVAS_CPE_MDCT )
     366             :         {
     367    11584740 :             if ( abs( Top[0] - Top[1] ) < ( delta / 2 ) )
     368             :             {
     369             :                 /* estimates are close enough and stable, take the artihmetic mean as estimate */
     370     6830179 :                 tcx_ltp_pitch_search( ( Top[0] + Top[1] ) / 2, &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &ltp_param[1], &norm_corr, L_frame, wsp, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, 1, &border_case );
     371             :             }
     372             :             else
     373             :             {
     374             :                 /* pitch jumps between half frames, calc ltp for both estimates, choose the better one */
     375             :                 int16_t pitch_int_2[2];
     376             :                 int16_t pitch_fr_2[2];
     377             :                 float norm_corr_2[2];
     378             :                 int16_t pit_param_2[2];
     379             : 
     380    14263683 :                 for ( i = 0; i < 2; i++ )
     381             :                 {
     382     9509122 :                     tcx_ltp_pitch_search( Top[i], &pitch_int_2[i], &pitch_fr_2[i], &pit_param_2[i], &norm_corr_2[i], L_frame, wsp, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, 1, &border_case );
     383             :                 }
     384             : 
     385     4754561 :                 i = ( norm_corr_2[1] > norm_corr_2[0] ) ? 1 : 0;
     386     4754561 :                 hTcxEnc->tcxltp_pitch_int = pitch_int_2[i];
     387     4754561 :                 hTcxEnc->tcxltp_pitch_fr = pitch_fr_2[i];
     388     4754561 :                 ltp_param[1] = pit_param_2[i];
     389     4754561 :                 norm_corr = norm_corr_2[i];
     390             :             }
     391             :         }
     392             :         else
     393             :         {
     394     3009402 :             tcx_ltp_pitch_search( Top[1], &hTcxEnc->tcxltp_pitch_int, &hTcxEnc->tcxltp_pitch_fr, &ltp_param[1], &norm_corr, L_frame, wsp, st->pit_min, st->pit_fr1, st->pit_fr2, st->pit_max, st->pit_res_max, ( element_mode > EVS_MONO ) ? 1 : 0, &border_case );
     395             :         }
     396             : 
     397    14594142 :         if ( border_case )
     398             :         {
     399     1282767 :             norm_corr = 0.0f;
     400             :         }
     401    14594142 :         if ( st->element_mode == IVAS_CPE_DFT )
     402             :         {
     403      358672 :             tempFlatness = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS - NSUBBLOCKS_SHIFT, ( NSUBBLOCKS_SHIFT + 1 ) + min( NSUBBLOCKS, (int16_t) ceil( 0.5f + NSUBBLOCKS * ( 1.0f * ( hTcxEnc->tcxltp_pitch_int ) / L_frame ) ) ) );
     404             : 
     405      358672 :             maxEnergyChange = GetTCXMaxenergyChange( st->hTranDet, tcxMode == TCX_10, NSUBBLOCKS - NSUBBLOCKS_SHIFT, ( NSUBBLOCKS_SHIFT + 1 ) + min( NSUBBLOCKS, (int16_t) ceil( 0.5f + NSUBBLOCKS * (float) ( hTcxEnc->tcxltp_pitch_int ) / (float) L_frame ) ) );
     406             :         }
     407             :         else
     408             :         {
     409    14235470 :             tempFlatness = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 1 + min( NSUBBLOCKS, (int16_t) ceil( 0.5f + NSUBBLOCKS * ( 1.0f * ( hTcxEnc->tcxltp_pitch_int ) / L_frame ) ) ) );
     410             : 
     411    14235470 :             maxEnergyChange = GetTCXMaxenergyChange( st->hTranDet, tcxMode == TCX_10, NSUBBLOCKS, 1 + min( NSUBBLOCKS, (int16_t) ceil( 0.5f + NSUBBLOCKS * (float) ( hTcxEnc->tcxltp_pitch_int ) / (float) L_frame ) ) );
     412             :         }
     413             : 
     414             :         /* Switch LTP on */
     415    14594142 :         if ( ( tcxOnly == 0 && tcxMode == TCX_20 && norm_corr * hTcxEnc->tcxltp_norm_corr_past > 0.25f && tempFlatness < 3.5f ) ||
     416    13752402 :              ( tcxOnly == 1 && tcxMode == TCX_10 && max( norm_corr, hTcxEnc->tcxltp_norm_corr_past ) > 0.5f && maxEnergyChange < 3.5f ) ||
     417             :              /* Use LTP for lower correlation when pitch lag is big, L_frame*(1.2f-norm_corr) < hTcxEnc->tcxltp_pitch_int <=> norm_corr > 1.2f-hTcxEnc->/L_frame */
     418    13731756 :              ( tcxOnly == 1 && norm_corr > 0.44f && L_frame * ( 1.2f - norm_corr ) < hTcxEnc->tcxltp_pitch_int ) ||
     419    11434589 :              ( tcxOnly == 1 && tcxMode == TCX_20 && norm_corr > 0.44f && ( tempFlatness < 6.0f || ( tempFlatness < 7.0f && maxEnergyChange < 22.0f ) ) ) )
     420             :         {
     421     6968630 :             if ( disable_ltp == 0 )
     422             :             {
     423     6967657 :                 ltp_param[0] = 1;
     424             :             }
     425             :         }
     426             : 
     427             :         /* hysteresis for stable ltp prediction */
     428    14594142 :         ltp_on = 0;
     429    14594142 :         if ( tcxOnly == 1 && st->element_mode == IVAS_CPE_MDCT && ( ( sqrt( (float) ( hTcxEnc->tcxltp_on_mem ) ) * (norm_corr) *0.9f ) > 0.44f && ( tempFlatness < 6.0f || ( tempFlatness < 7.0f && maxEnergyChange < 22.0f ) ) ) )
     430             :         {
     431     5535003 :             ltp_on = 1;
     432             :         }
     433             : 
     434    14594142 :         if ( tcxOnly == 1 && ltp_param[0] == 1 )
     435             :         {
     436             :             /* increase ltp counter */
     437     6126890 :             hTcxEnc->tcxltp_on_mem = min( 5, hTcxEnc->tcxltp_on_mem + 1 );
     438             :         }
     439     8467252 :         else if ( ltp_on == 1 )
     440             :         {
     441             :             /* hysteresis takes effect, decrease counter */
     442      637555 :             hTcxEnc->tcxltp_on_mem = max( 0, hTcxEnc->tcxltp_on_mem - 1 );
     443      637555 :             ltp_param[0] = ltp_on;
     444             :         }
     445             :         else
     446             :         {
     447             :             /* no ltp in this frame, reset counter */
     448     7829697 :             hTcxEnc->tcxltp_on_mem = 0;
     449             :         }
     450             :     }
     451             : 
     452             :     /* Find predicted signal */
     453    14594142 :     predict_signal( speech, pred_speech, hTcxEnc->tcxltp_pitch_int, hTcxEnc->tcxltp_pitch_fr, st->pit_res_max, L_frame );
     454             : 
     455             :     /* Find gain */
     456    14594142 :     tcx_ltp_find_gain( speech, pred_speech, L_frame, &hTcxEnc->tcxltp_gain, &ltp_param[2] );
     457             : 
     458    14594142 :     if ( ltp_param[0] )
     459             :     {
     460             :         /* Total number of bits for LTP */
     461     7605212 :         if ( ltp_param[2] + 1 ) /* hTcxEnc->tcxltp_gain > 0 */
     462             :         {
     463     7602866 :             *ltp_bits = 12;
     464             :         }
     465             :         else /* hTcxEnc->tcxltp_gain <= 0 -> turn off LTP */
     466             :         {
     467        2346 :             ltp_param[0] = 0;
     468             :         }
     469             :     }
     470             : 
     471    14594142 :     if ( !ltp_param[0] )
     472             :     {
     473             :         /* No LTP -> set everything to zero */
     474     6991276 :         hTcxEnc->tcxltp_pitch_int = L_frame;
     475     6991276 :         hTcxEnc->tcxltp_pitch_fr = 0;
     476     6991276 :         ltp_param[1] = 0;
     477     6991276 :         set_zero( pred_speech, L_frame );
     478     6991276 :         hTcxEnc->tcxltp_gain = 0.f;
     479     6991276 :         ltp_param[2] = 0;
     480     6991276 :         if ( hTcxEnc->tcxltp || SideInfoOnly )
     481             :         {
     482     6991276 :             *ltp_bits = 1;
     483             :         }
     484             :         else
     485             :         {
     486           0 :             *ltp_bits = 0;
     487             :         }
     488             :     }
     489             : 
     490    14594142 :     si_gain = 0;
     491    14594142 :     if ( SideInfoOnly )
     492             :     {
     493     5821950 :         si_gain = hTcxEnc->tcxltp_gain;
     494     5821950 :         hTcxEnc->tcxltp_gain = 0.f;
     495             :     }
     496             : 
     497    14594142 :     if ( speech_ltp != NULL )
     498             :     {
     499     2650730 :         if ( hTcxEnc->tcxltp_gain_past == 0.f && hTcxEnc->tcxltp_gain == 0.f )
     500             :         {
     501     1785710 :             mvr2r( speech, speech_ltp, L_subfr );
     502             :         }
     503      865020 :         else if ( hTcxEnc->tcxltp_gain_past == 0.f )
     504             :         {
     505      134691 :             alpha = 0.f;
     506      134691 :             step = 1.f / (float) ( L_subfr );
     507     8754915 :             for ( n = 0; n < L_subfr; n++ )
     508             :             {
     509     8620224 :                 speech_ltp[n] = speech[n] - alpha * hTcxEnc->tcxltp_gain * pred_speech[n];
     510     8620224 :                 alpha += step;
     511             :             }
     512             :         }
     513             :         else
     514             :         {
     515      730329 :             if ( A == NULL )
     516             :             {
     517    12936888 :                 for ( i = 0; i <= M; i++ )
     518             :                 {
     519    12218172 :                     s = 0.0;
     520  3700683420 :                     for ( j = 0; j < L_frame - i; j++ )
     521             :                     {
     522  3688465248 :                         s += speech[j - L_frame] * speech[j + i - L_frame];
     523             :                     }
     524    12218172 :                     r[i] = s;
     525             :                 }
     526      718716 :                 if ( r[0] < 100.0f )
     527             :                 {
     528        5656 :                     r[0] = 100.0f;
     529             :                 }
     530      718716 :                 r[0] *= 1.0001f;
     531      718716 :                 lev_dur( Aest, r, M, NULL );
     532      718716 :                 A = Aest;
     533             :             }
     534             : 
     535      730329 :             if ( hTcxEnc->tcxltp_gain > 0.f )
     536             :             {
     537      635979 :                 predict_signal( speech - M, buf_zir, hTcxEnc->tcxltp_pitch_int, hTcxEnc->tcxltp_pitch_fr, st->pit_res_max, M );
     538             :             }
     539             :             else
     540             :             {
     541       94350 :                 set_f( buf_zir, 0.0f, M );
     542             :             }
     543             : 
     544    12415593 :             for ( n = 0; n < M; n++ )
     545             :             {
     546    11685264 :                 buf_zir[n] = speech_ltp[n - M] - speech[n - M] + hTcxEnc->tcxltp_gain * buf_zir[n];
     547             :             }
     548             : 
     549      730329 :             zir = buf_zir + M;
     550      730329 :             set_f( zir, 0.0f, L_subfr );
     551      730329 :             syn_filt( A, M, zir, zir, L_subfr, buf_zir, 0 );
     552      730329 :             alpha = 1.f;
     553      730329 :             step = 1.f / (float) ( L_subfr / 2 );
     554             : 
     555    24100857 :             for ( n = L_subfr / 2; n < L_subfr; n++ )
     556             :             {
     557    23370528 :                 zir[n] *= alpha;
     558    23370528 :                 alpha -= step;
     559             :             }
     560             : 
     561    47471385 :             for ( n = 0; n < L_subfr; n++ )
     562             :             {
     563    46741056 :                 speech_ltp[n] = ( speech[n] - hTcxEnc->tcxltp_gain * pred_speech[n] ) + zir[n];
     564             :             }
     565             :         }
     566             : 
     567     2650730 :         if ( SideInfoOnly || hTcxEnc->tcxltp_gain == 0.0f )
     568             :         {
     569   747757564 :             for ( n = L_subfr; n < L_frame; n++ )
     570             :             {
     571   745877504 :                 speech_ltp[n] = speech[n];
     572             :             }
     573             :         }
     574             :         else
     575             :         {
     576   189728366 :             for ( n = L_subfr; n < L_frame; n++ )
     577             :             {
     578   188957696 :                 speech_ltp[n] = speech[n] - hTcxEnc->tcxltp_gain * pred_speech[n];
     579             :             }
     580             :         }
     581             :     }
     582             : 
     583             :     /* Update */
     584    14594142 :     hTcxEnc->tcxltp_pitch_int_past = hTcxEnc->tcxltp_pitch_int;
     585    14594142 :     hTcxEnc->tcxltp_pitch_fr_past = hTcxEnc->tcxltp_pitch_fr;
     586    14594142 :     hTcxEnc->tcxltp_gain_past = hTcxEnc->tcxltp_gain;
     587             : 
     588    14594142 :     if ( SideInfoOnly )
     589             :     {
     590     5821950 :         hTcxEnc->tcxltp_gain = si_gain;
     591             :     }
     592             : 
     593    14594142 :     hTcxEnc->tcxltp_norm_corr_past = norm_corr;
     594             : 
     595    14594142 :     return;
     596             : }

Generated by: LCOV version 1.14