LCOV - code coverage report
Current view: top level - lib_enc - tcx_ltp_enc.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 208 209 99.5 %
Date: 2025-05-23 08:37:30 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     5352230 : 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     5352230 :     if ( frac_max == 6 )
      71             :     {
      72      286488 :         win = E_ROM_inter6_1;
      73             :     }
      74             :     else
      75             :     {
      76     5065742 :         win = E_ROM_inter4_1;
      77             :     }
      78             : 
      79     5352230 :     x1 = &x[0];
      80     5352230 :     x2 = &x[1];
      81     5352230 :     c1 = &win[frac];
      82     5352230 :     c2 = &win[frac_max - frac];
      83     5352230 :     s = 0.0f;
      84    26761150 :     for ( i = 0; i < 4; i++, c1 += frac_max, c2 += frac_max )
      85             :     {
      86    21408920 :         s += ( *x1-- ) * ( *c1 ) + ( *x2++ ) * ( *c2 );
      87             :     }
      88             : 
      89     5352230 :     return s;
      90             : }
      91             : 
      92             : 
      93             : /*---------------------------------------------------------------------*
      94             :  * tcx_ltp_pitch_search()
      95             :  *
      96             :  *
      97             :  *---------------------------------------------------------------------*/
      98             : 
      99     1077126 : 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     1077126 :     if ( pitres == 6 )
     119             :     {
     120      174667 :         delta = 8;
     121             :     }
     122             :     else
     123             :     {
     124      902459 :         delta = 16;
     125             :     }
     126             : 
     127     1077126 :     t0_min = (int16_t) pitch_ol - ( delta >> 1 );
     128     1077126 :     t0_max = (int16_t) pitch_ol + ( delta >> 1 ) - 1;
     129             : 
     130     1077126 :     if ( t0_min < pitmin )
     131             :     {
     132       86766 :         t0_min = pitmin;
     133       86766 :         t0_max = t0_min + delta - 1;
     134             :     }
     135     1077126 :     if ( t0_max > pitmax )
     136             :     {
     137       21962 :         t0_max = pitmax;
     138       21962 :         t0_min = t0_max - delta + 1;
     139             :     }
     140             : 
     141             : 
     142     1077126 :     t_min = t0_min - L_INTERPOL1;
     143     1077126 :     t_max = t0_max + L_INTERPOL1;
     144             : 
     145     1077126 :     pt_cor = cor;
     146    25530814 :     for ( t = t_min; t <= t_max; t++ )
     147             :     {
     148    24453688 :         *pt_cor++ = dotp( wsp, wsp - t, len );
     149             :     }
     150             : 
     151     1077126 :     pt_cor = cor + L_INTERPOL1;
     152     1077126 :     cor_max = *pt_cor++;
     153     1077126 :     t1 = t0_min;
     154    15836680 :     for ( t = t0_min + 1; t <= t0_max; t++ )
     155             :     {
     156    14759554 :         if ( *pt_cor > cor_max )
     157             :         {
     158     5759443 :             cor_max = *pt_cor;
     159     5759443 :             t1 = t;
     160             :         }
     161    14759554 :         pt_cor++;
     162             :     }
     163     1077126 :     temp = dotp( wsp, wsp, len ) * dotp( wsp - t1, wsp - t1, len );
     164     1077126 :     *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     1077126 :     if ( check_border_case && t1 == t0_min )
     169             :     {
     170             :         float tmpCor;
     171      288352 :         for ( t = t1 - L_INTERPOL1; t < t1; t++ )
     172             :         {
     173      255318 :             tmpCor = dotp( wsp, wsp - t, len );
     174      255318 :             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       87930 :                 *border_case = 1;
     179       87930 :                 break;
     180             :             }
     181             :         }
     182             :     }
     183             : 
     184     1077126 :     if ( t1 >= pitfr1 )
     185             :     {
     186      231549 :         *pitch_int = t1;
     187      231549 :         *pitch_fr = 0;
     188      231549 :         *index = t1 - pitfr1 + ( ( pitfr2 - pitmin ) * pitres ) + ( ( pitfr1 - pitfr2 ) * ( pitres >> 1 ) );
     189      231549 :         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      845577 :     pt_cor = cor + L_INTERPOL1 - t0_min;
     199      845577 :     t0 = t1;
     200      845577 :     if ( t0 >= pitfr2 )
     201             :     {
     202      129891 :         step = 2;
     203      129891 :         fraction = 2;
     204             :     }
     205             :     else
     206             :     {
     207      715686 :         step = 1;
     208      715686 :         fraction = 1;
     209             :     }
     210             : 
     211      845577 :     if ( t0 == t0_min ) /* Limit case */
     212             :     {
     213       96116 :         fraction = 0;
     214       96116 :         cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres );
     215             :     }
     216             :     else /* Process negative fractions */
     217             :     {
     218      749461 :         t0--;
     219      749461 :         cor_max = interpolate_corr( &pt_cor[t0], fraction, pitres );
     220     2073133 :         for ( i = ( fraction + step ); i <= pitres - 1; i = i + step )
     221             :         {
     222     1323672 :             temp = interpolate_corr( &pt_cor[t0], i, pitres );
     223     1323672 :             if ( temp > cor_max )
     224             :             {
     225     1236494 :                 cor_max = temp;
     226     1236494 :                 fraction = i;
     227             :             }
     228             :         }
     229             :     }
     230             : 
     231     4028558 :     for ( i = 0; i <= pitres - 1; i = i + step ) /* Process positive fractions */
     232             :     {
     233     3182981 :         temp = interpolate_corr( &pt_cor[t1], i, pitres );
     234     3182981 :         if ( temp > cor_max )
     235             :         {
     236      919276 :             cor_max = temp;
     237      919276 :             fraction = i;
     238      919276 :             t0 = t1;
     239             :         }
     240             :     }
     241      845577 :     *pitch_int = t0;
     242      845577 :     *pitch_fr = fraction;
     243      845577 :     if ( t0 >= pitfr2 )
     244             :     {
     245      128990 :         *index = t0 * ( pitres >> 1 ) + ( fraction >> 1 ) - ( pitfr2 * ( pitres >> 1 ) ) + ( ( pitfr2 - pitmin ) * pitres );
     246             :     }
     247             :     else
     248             :     {
     249      716587 :         *index = t0 * pitres + fraction - ( pitmin * pitres );
     250             :     }
     251             : 
     252      845577 :     return;
     253             : }
     254             : 
     255             : 
     256             : /*---------------------------------------------------------------------*
     257             :  * tcx_ltp_find_gain()
     258             :  *
     259             :  *
     260             :  *---------------------------------------------------------------------*/
     261             : 
     262      883606 : 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      883606 :     int16_t gainbits = 2;
     270             : 
     271             :     /* Find gain */
     272      883606 :     *gain = get_gain( speech, pred_speech, L_frame, NULL );
     273             : 
     274             :     /* Quantize gain */
     275      883606 :     if ( *gain >= 0.875f )
     276             :     {
     277      192151 :         *gain_index = 3; /* 1.00/2 */
     278             :     }
     279      691455 :     else if ( *gain >= 0.625f )
     280             :     {
     281      285147 :         *gain_index = 2; /* 0.75/2 */
     282             :     }
     283      406308 :     else if ( *gain >= 0.375f )
     284             :     {
     285      231309 :         *gain_index = 1; /* 0.50/2 */
     286             :     }
     287      174999 :     else if ( *gain >= 0.125f )
     288             :     {
     289      136991 :         *gain_index = 0; /* 0.25/2 */
     290             :     }
     291             :     else
     292             :     {
     293       38008 :         *gain_index = -1; /* escape */
     294             :     }
     295             :     /* Dequantize gain */
     296      883606 :     *gain = (float) ( *gain_index + 1 ) * 0.625f / (float) ( 1 << gainbits );
     297             : 
     298      883606 :     return;
     299             : }
     300             : 
     301             : /*---------------------------------------------------------------------*
     302             :  * tcx_ltp_encode()
     303             :  *
     304             :  *
     305             :  *---------------------------------------------------------------------*/
     306             : 
     307      883606 : 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      883606 :     TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
     335             : 
     336      883606 :     tcxOnly = st->tcxonly;
     337      883606 :     L_subfr = L_SUBFR;
     338      883606 :     SideInfoOnly = st->sr_core > 25600;
     339             : 
     340             :     /* Reset memory if past frame is acelp */
     341      883606 :     if ( st->last_core == ACELP_CORE )
     342             :     {
     343        9961 :         hTcxEnc->tcxltp_pitch_int_past = L_frame;
     344        9961 :         hTcxEnc->tcxltp_pitch_fr_past = 0;
     345        9961 :         hTcxEnc->tcxltp_gain_past = 0.f;
     346             :     }
     347             : 
     348             :     /* By default, LTP is off */
     349      883606 :     ltp_param[0] = 0;
     350      883606 :     norm_corr = 0.0f;
     351      883606 :     border_case = 0;
     352             : 
     353      883606 :     if ( hTcxEnc->tcxltp || SideInfoOnly )
     354             :     {
     355             :         /* Find pitch lag */
     356      883606 :         if ( st->pit_res_max == 6 )
     357             :         {
     358      174667 :             delta = 8;
     359             :         }
     360             :         else
     361             :         {
     362      708939 :             delta = 16;
     363             :         }
     364             : 
     365      883606 :         if ( st->element_mode == IVAS_CPE_MDCT )
     366             :         {
     367      647069 :             if ( abs( Top[0] - Top[1] ) < ( delta / 2 ) )
     368             :             {
     369             :                 /* estimates are close enough and stable, take the artihmetic mean as estimate */
     370      453549 :                 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      580560 :                 for ( i = 0; i < 2; i++ )
     381             :                 {
     382      387040 :                     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      193520 :                 i = ( norm_corr_2[1] > norm_corr_2[0] ) ? 1 : 0;
     386      193520 :                 hTcxEnc->tcxltp_pitch_int = pitch_int_2[i];
     387      193520 :                 hTcxEnc->tcxltp_pitch_fr = pitch_fr_2[i];
     388      193520 :                 ltp_param[1] = pit_param_2[i];
     389      193520 :                 norm_corr = norm_corr_2[i];
     390             :             }
     391             :         }
     392             :         else
     393             :         {
     394      236537 :             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      883606 :         if ( border_case )
     398             :         {
     399       83785 :             norm_corr = 0.0f;
     400             :         }
     401      883606 :         if ( st->element_mode == IVAS_CPE_DFT )
     402             :         {
     403       14309 :             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       14309 :             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      869297 :             tempFlatness = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 1 + min( NSUBBLOCKS, (int16_t) ceil( 0.5f + NSUBBLOCKS * ( 1.0f * ( hTcxEnc->tcxltp_pitch_int ) / L_frame ) ) ) );
     410             : 
     411      869297 :             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      883606 :         if ( ( tcxOnly == 0 && tcxMode == TCX_20 && norm_corr * hTcxEnc->tcxltp_norm_corr_past > 0.25f && tempFlatness < 3.5f ) ||
     416      821559 :              ( 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      820373 :              ( tcxOnly == 1 && norm_corr > 0.44f && L_frame * ( 1.2f - norm_corr ) < hTcxEnc->tcxltp_pitch_int ) ||
     419      659538 :              ( tcxOnly == 1 && tcxMode == TCX_20 && norm_corr > 0.44f && ( tempFlatness < 6.0f || ( tempFlatness < 7.0f && maxEnergyChange < 22.0f ) ) ) )
     420             :         {
     421      543397 :             if ( disable_ltp == 0 )
     422             :             {
     423      543339 :                 ltp_param[0] = 1;
     424             :             }
     425             :         }
     426             : 
     427             :         /* hysteresis for stable ltp prediction */
     428      883606 :         ltp_on = 0;
     429      883606 :         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      419455 :             ltp_on = 1;
     432             :         }
     433             : 
     434      883606 :         if ( tcxOnly == 1 && ltp_param[0] == 1 )
     435             :         {
     436             :             /* increase ltp counter */
     437      481350 :             hTcxEnc->tcxltp_on_mem = min( 5, hTcxEnc->tcxltp_on_mem + 1 );
     438             :         }
     439      402256 :         else if ( ltp_on == 1 )
     440             :         {
     441             :             /* hysteresis takes effect, decrease counter */
     442       44945 :             hTcxEnc->tcxltp_on_mem = max( 0, hTcxEnc->tcxltp_on_mem - 1 );
     443       44945 :             ltp_param[0] = ltp_on;
     444             :         }
     445             :         else
     446             :         {
     447             :             /* no ltp in this frame, reset counter */
     448      357311 :             hTcxEnc->tcxltp_on_mem = 0;
     449             :         }
     450             :     }
     451             : 
     452             :     /* Find predicted signal */
     453      883606 :     predict_signal( speech, pred_speech, hTcxEnc->tcxltp_pitch_int, hTcxEnc->tcxltp_pitch_fr, st->pit_res_max, L_frame );
     454             : 
     455             :     /* Find gain */
     456      883606 :     tcx_ltp_find_gain( speech, pred_speech, L_frame, &hTcxEnc->tcxltp_gain, &ltp_param[2] );
     457             : 
     458      883606 :     if ( ltp_param[0] )
     459             :     {
     460             :         /* Total number of bits for LTP */
     461      588284 :         if ( ltp_param[2] + 1 ) /* hTcxEnc->tcxltp_gain > 0 */
     462             :         {
     463      588226 :             *ltp_bits = 12;
     464             :         }
     465             :         else /* hTcxEnc->tcxltp_gain <= 0 -> turn off LTP */
     466             :         {
     467          58 :             ltp_param[0] = 0;
     468             :         }
     469             :     }
     470             : 
     471      883606 :     if ( !ltp_param[0] )
     472             :     {
     473             :         /* No LTP -> set everything to zero */
     474      295380 :         hTcxEnc->tcxltp_pitch_int = L_frame;
     475      295380 :         hTcxEnc->tcxltp_pitch_fr = 0;
     476      295380 :         ltp_param[1] = 0;
     477      295380 :         set_zero( pred_speech, L_frame );
     478      295380 :         hTcxEnc->tcxltp_gain = 0.f;
     479      295380 :         ltp_param[2] = 0;
     480      295380 :         if ( hTcxEnc->tcxltp || SideInfoOnly )
     481             :         {
     482      295380 :             *ltp_bits = 1;
     483             :         }
     484             :         else
     485             :         {
     486           0 :             *ltp_bits = 0;
     487             :         }
     488             :     }
     489             : 
     490      883606 :     si_gain = 0;
     491      883606 :     if ( SideInfoOnly )
     492             :     {
     493      426181 :         si_gain = hTcxEnc->tcxltp_gain;
     494      426181 :         hTcxEnc->tcxltp_gain = 0.f;
     495             :     }
     496             : 
     497      883606 :     if ( speech_ltp != NULL )
     498             :     {
     499      222228 :         if ( hTcxEnc->tcxltp_gain_past == 0.f && hTcxEnc->tcxltp_gain == 0.f )
     500             :         {
     501      150957 :             mvr2r( speech, speech_ltp, L_subfr );
     502             :         }
     503       71271 :         else if ( hTcxEnc->tcxltp_gain_past == 0.f )
     504             :         {
     505       12076 :             alpha = 0.f;
     506       12076 :             step = 1.f / (float) ( L_subfr );
     507      784940 :             for ( n = 0; n < L_subfr; n++ )
     508             :             {
     509      772864 :                 speech_ltp[n] = speech[n] - alpha * hTcxEnc->tcxltp_gain * pred_speech[n];
     510      772864 :                 alpha += step;
     511             :             }
     512             :         }
     513             :         else
     514             :         {
     515       59195 :             if ( A == NULL )
     516             :             {
     517     1056492 :                 for ( i = 0; i <= M; i++ )
     518             :                 {
     519      997798 :                     s = 0.0;
     520   297073334 :                     for ( j = 0; j < L_frame - i; j++ )
     521             :                     {
     522   296075536 :                         s += speech[j - L_frame] * speech[j + i - L_frame];
     523             :                     }
     524      997798 :                     r[i] = s;
     525             :                 }
     526       58694 :                 if ( r[0] < 100.0f )
     527             :                 {
     528          44 :                     r[0] = 100.0f;
     529             :                 }
     530       58694 :                 r[0] *= 1.0001f;
     531       58694 :                 lev_dur( Aest, r, M, NULL );
     532       58694 :                 A = Aest;
     533             :             }
     534             : 
     535       59195 :             if ( hTcxEnc->tcxltp_gain > 0.f )
     536             :             {
     537       50189 :                 predict_signal( speech - M, buf_zir, hTcxEnc->tcxltp_pitch_int, hTcxEnc->tcxltp_pitch_fr, st->pit_res_max, M );
     538             :             }
     539             :             else
     540             :             {
     541        9006 :                 set_f( buf_zir, 0.0f, M );
     542             :             }
     543             : 
     544     1006315 :             for ( n = 0; n < M; n++ )
     545             :             {
     546      947120 :                 buf_zir[n] = speech_ltp[n - M] - speech[n - M] + hTcxEnc->tcxltp_gain * buf_zir[n];
     547             :             }
     548             : 
     549       59195 :             zir = buf_zir + M;
     550       59195 :             set_f( zir, 0.0f, L_subfr );
     551       59195 :             syn_filt( A, M, zir, zir, L_subfr, buf_zir, 0 );
     552       59195 :             alpha = 1.f;
     553       59195 :             step = 1.f / (float) ( L_subfr / 2 );
     554             : 
     555     1953435 :             for ( n = L_subfr / 2; n < L_subfr; n++ )
     556             :             {
     557     1894240 :                 zir[n] *= alpha;
     558     1894240 :                 alpha -= step;
     559             :             }
     560             : 
     561     3847675 :             for ( n = 0; n < L_subfr; n++ )
     562             :             {
     563     3788480 :                 speech_ltp[n] = ( speech[n] - hTcxEnc->tcxltp_gain * pred_speech[n] ) + zir[n];
     564             :             }
     565             :         }
     566             : 
     567      222228 :         if ( SideInfoOnly || hTcxEnc->tcxltp_gain == 0.0f )
     568             :         {
     569    72016091 :             for ( n = L_subfr; n < L_frame; n++ )
     570             :             {
     571    71856128 :                 speech_ltp[n] = speech[n];
     572             :             }
     573             :         }
     574             :         else
     575             :         {
     576    15024057 :             for ( n = L_subfr; n < L_frame; n++ )
     577             :             {
     578    14961792 :                 speech_ltp[n] = speech[n] - hTcxEnc->tcxltp_gain * pred_speech[n];
     579             :             }
     580             :         }
     581             :     }
     582             : 
     583             :     /* Update */
     584      883606 :     hTcxEnc->tcxltp_pitch_int_past = hTcxEnc->tcxltp_pitch_int;
     585      883606 :     hTcxEnc->tcxltp_pitch_fr_past = hTcxEnc->tcxltp_pitch_fr;
     586      883606 :     hTcxEnc->tcxltp_gain_past = hTcxEnc->tcxltp_gain;
     587             : 
     588      883606 :     if ( SideInfoOnly )
     589             :     {
     590      426181 :         hTcxEnc->tcxltp_gain = si_gain;
     591             :     }
     592             : 
     593      883606 :     hTcxEnc->tcxltp_norm_corr_past = norm_corr;
     594             : 
     595      883606 :     return;
     596             : }

Generated by: LCOV version 1.14