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 @ efe53129c9ed87a5067dd0a8fb9dca41db9c4add Lines: 211 212 99.5 %
Date: 2026-02-12 08:06:51 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2026 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 "cnst.h"
      38             : #include <stdint.h>
      39             : #include "options.h"
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include <math.h>
      44             : #include "prot.h"
      45             : #include "rom_enc.h"
      46             : #include "rom_com.h"
      47             : #include "wmc_auto.h"
      48             : #ifdef DEBUG_PLOT
      49             : #include "deb_out.h"
      50             : #endif
      51             : 
      52             : 
      53             : /*---------------------------------------------------------------------*
      54             :  * interpolate_corr()
      55             :  *
      56             :  *
      57             :  *---------------------------------------------------------------------*/
      58             : 
      59             : /*! r: interpolated value */
      60   100860919 : static float interpolate_corr(
      61             :     const float *x,        /* i  : input vector         */
      62             :     const int16_t frac,    /* i  : fraction of lag      */
      63             :     const int16_t frac_max /* i  : max fraction         */
      64             : )
      65             : {
      66             :     int16_t i;
      67             :     float s;
      68             :     const float *c1, *c2, *x1, *x2, *win;
      69             : 
      70             : 
      71   100860919 :     if ( frac_max == 6 )
      72             :     {
      73     5553259 :         win = E_ROM_inter6_1;
      74             :     }
      75             :     else
      76             :     {
      77    95307660 :         win = E_ROM_inter4_1;
      78             :     }
      79             : 
      80   100860919 :     x1 = &x[0];
      81   100860919 :     x2 = &x[1];
      82   100860919 :     c1 = &win[frac];
      83   100860919 :     c2 = &win[frac_max - frac];
      84   100860919 :     s = 0.0f;
      85   504304595 :     for ( i = 0; i < 4; i++, c1 += frac_max, c2 += frac_max )
      86             :     {
      87   403443676 :         s += ( *x1-- ) * ( *c1 ) + ( *x2++ ) * ( *c2 );
      88             :     }
      89             : 
      90   100860919 :     return s;
      91             : }
      92             : 
      93             : 
      94             : /*---------------------------------------------------------------------*
      95             :  * tcx_ltp_pitch_search()
      96             :  *
      97             :  *
      98             :  *---------------------------------------------------------------------*/
      99             : 
     100    19650616 : static void tcx_ltp_pitch_search(
     101             :     const int16_t pitch_ol,
     102             :     int16_t *pitch_int,
     103             :     int16_t *pitch_fr,
     104             :     int16_t *index,
     105             :     float *norm_corr,
     106             :     const int16_t len,
     107             :     const float *wsp,
     108             :     const int16_t pitmin,
     109             :     const int16_t pitfr1,
     110             :     const int16_t pitfr2,
     111             :     const int16_t pitmax,
     112             :     const int16_t pitres,
     113             :     const int16_t check_border_case,
     114             :     int16_t *border_case )
     115             : {
     116             :     int16_t i, t, t0, t1, step, fraction, t0_min, t0_max, t_min, t_max, delta;
     117             :     int16_t cor_idx_ini, cor_idx;
     118             :     float temp, cor_max, cor[256], *pt_cor;
     119             : 
     120    19650616 :     if ( pitres == 6 )
     121             :     {
     122     2259379 :         delta = 8;
     123             :     }
     124             :     else
     125             :     {
     126    17391237 :         delta = 16;
     127             :     }
     128             : 
     129    19650616 :     t0_min = (int16_t) pitch_ol - ( delta >> 1 );
     130    19650616 :     t0_max = (int16_t) pitch_ol + ( delta >> 1 ) - 1;
     131             : 
     132    19650616 :     if ( t0_min < pitmin )
     133             :     {
     134     1725722 :         t0_min = pitmin;
     135     1725722 :         t0_max = t0_min + delta - 1;
     136             :     }
     137    19650616 :     if ( t0_max > pitmax )
     138             :     {
     139      447578 :         t0_max = pitmax;
     140      447578 :         t0_min = t0_max - delta + 1;
     141             :     }
     142             : 
     143             : 
     144    19650616 :     t_min = t0_min - L_INTERPOL1;
     145    19650616 :     t_max = t0_max + L_INTERPOL1;
     146             : 
     147    19650616 :     pt_cor = cor;
     148   473190368 :     for ( t = t_min; t <= t_max; t++ )
     149             :     {
     150   453539752 :         *pt_cor++ = dotp( wsp, wsp - t, len );
     151             :     }
     152             : 
     153    19650616 :     pt_cor = cor + L_INTERPOL1;
     154    19650616 :     cor_max = *pt_cor++;
     155    19650616 :     t1 = t0_min;
     156   296334824 :     for ( t = t0_min + 1; t <= t0_max; t++ )
     157             :     {
     158   276684208 :         if ( *pt_cor > cor_max )
     159             :         {
     160    92405818 :             cor_max = *pt_cor;
     161    92405818 :             t1 = t;
     162             :         }
     163   276684208 :         pt_cor++;
     164             :     }
     165    19650616 :     temp = dotp( wsp, wsp, len ) * dotp( wsp - t1, wsp - t1, len );
     166    19650616 :     *norm_corr = cor_max / (float) sqrt( temp + 0.1f );
     167             : 
     168             :     /* check for border cases at the low lag border */
     169             :     /*pt_cor=cor;*/
     170    19650616 :     if ( check_border_case && t1 == t0_min )
     171             :     {
     172             :         float tmpCor;
     173     6644411 :         for ( t = t1 - L_INTERPOL1; t < t1; t++ )
     174             :         {
     175     5741567 :             tmpCor = dotp( wsp, wsp - t, len );
     176     5741567 :             if ( tmpCor > cor_max )
     177             :             {
     178             :                 /* no real maximum but still on a rising slope */
     179             :                 /* keep t1 but set norm_corr to zero to avoid activating the LTP here */
     180     1415012 :                 *border_case = 1;
     181     1415012 :                 break;
     182             :             }
     183             :         }
     184             :     }
     185             : 
     186    19650616 :     if ( t1 >= pitfr1 )
     187             :     {
     188     3369910 :         *pitch_int = t1;
     189     3369910 :         *pitch_fr = 0;
     190     3369910 :         *index = t1 - pitfr1 + ( ( pitfr2 - pitmin ) * pitres ) + ( ( pitfr1 - pitfr2 ) * ( pitres >> 1 ) );
     191     3369910 :         return;
     192             :     }
     193             : 
     194             :     /*------------------------------------------------------------------*
     195             :      * Search fractional pitch with 1/4 subsample resolution.
     196             :      * search the fractions around t0 and choose the one which maximizes
     197             :      * the interpolated normalized correlation.
     198             :      *-----------------------------------------------------------------*/
     199             : 
     200    16280706 :     cor_idx_ini = L_INTERPOL1 - t0_min;
     201    16280706 :     t0 = t1;
     202    16280706 :     if ( t0 >= pitfr2 )
     203             :     {
     204     2963313 :         step = 2;
     205     2963313 :         fraction = 2;
     206             :     }
     207             :     else
     208             :     {
     209    13317393 :         step = 1;
     210    13317393 :         fraction = 1;
     211             :     }
     212             : 
     213    16280706 :     if ( t0 == t0_min ) /* Limit case */
     214             :     {
     215     2049624 :         fraction = 0;
     216     2049624 :         cor_idx = cor_idx_ini + t0;
     217     2049624 :         cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres );
     218             :     }
     219             :     else /* Process negative fractions */
     220             :     {
     221    14231082 :         t0--;
     222    14231082 :         cor_idx = cor_idx_ini + t0;
     223    14231082 :         cor_max = interpolate_corr( &cor[cor_idx], fraction, pitres );
     224    38445801 :         for ( i = ( fraction + step ); i <= pitres - 1; i = i + step )
     225             :         {
     226    24214719 :             temp = interpolate_corr( &cor[cor_idx], i, pitres );
     227    24214719 :             if ( temp > cor_max )
     228             :             {
     229    22745773 :                 cor_max = temp;
     230    22745773 :                 fraction = i;
     231             :             }
     232             :         }
     233             :     }
     234             : 
     235    16280706 :     cor_idx = cor_idx_ini + t1;
     236    76646200 :     for ( i = 0; i <= pitres - 1; i = i + step ) /* Process positive fractions */
     237             :     {
     238    60365494 :         temp = interpolate_corr( &cor[cor_idx], i, pitres );
     239    60365494 :         if ( temp > cor_max )
     240             :         {
     241    17250360 :             cor_max = temp;
     242    17250360 :             fraction = i;
     243    17250360 :             t0 = t1;
     244             :         }
     245             :     }
     246    16280706 :     *pitch_int = t0;
     247    16280706 :     *pitch_fr = fraction;
     248    16280706 :     if ( t0 >= pitfr2 )
     249             :     {
     250     2946901 :         *index = t0 * ( pitres >> 1 ) + ( fraction >> 1 ) - ( pitfr2 * ( pitres >> 1 ) ) + ( ( pitfr2 - pitmin ) * pitres );
     251             :     }
     252             :     else
     253             :     {
     254    13333805 :         *index = t0 * pitres + fraction - ( pitmin * pitres );
     255             :     }
     256             : 
     257    16280706 :     return;
     258             : }
     259             : 
     260             : 
     261             : /*---------------------------------------------------------------------*
     262             :  * tcx_ltp_find_gain()
     263             :  *
     264             :  *
     265             :  *---------------------------------------------------------------------*/
     266             : 
     267    14830182 : static void tcx_ltp_find_gain(
     268             :     const float *speech,
     269             :     float *pred_speech,
     270             :     const int16_t L_frame,
     271             :     float *gain,
     272             :     int16_t *gain_index )
     273             : {
     274    14830182 :     int16_t gainbits = 2;
     275             : 
     276             :     /* Find gain */
     277    14830182 :     *gain = get_gain( speech, pred_speech, L_frame, NULL );
     278             : 
     279             :     /* Quantize gain */
     280    14830182 :     if ( *gain >= 0.875f )
     281             :     {
     282     2767477 :         *gain_index = 3; /* 1.00/2 */
     283             :     }
     284    12062705 :     else if ( *gain >= 0.625f )
     285             :     {
     286     3441068 :         *gain_index = 2; /* 0.75/2 */
     287             :     }
     288     8621637 :     else if ( *gain >= 0.375f )
     289             :     {
     290     3838274 :         *gain_index = 1; /* 0.50/2 */
     291             :     }
     292     4783363 :     else if ( *gain >= 0.125f )
     293             :     {
     294     3808676 :         *gain_index = 0; /* 0.25/2 */
     295             :     }
     296             :     else
     297             :     {
     298      974687 :         *gain_index = -1; /* escape */
     299             :     }
     300             :     /* Dequantize gain */
     301    14830182 :     *gain = (float) ( *gain_index + 1 ) * 0.625f / (float) ( 1 << gainbits );
     302             : 
     303    14830182 :     return;
     304             : }
     305             : 
     306             : /*---------------------------------------------------------------------*
     307             :  * tcx_ltp_encode()
     308             :  *
     309             :  *
     310             :  *---------------------------------------------------------------------*/
     311             : 
     312    14830182 : void tcx_ltp_encode(
     313             :     Encoder_State *st,
     314             :     const int16_t tcxMode,
     315             :     const int16_t L_frame,
     316             :     const float *speech,
     317             :     float *speech_ltp,
     318             :     const float *wsp,
     319             :     const int16_t Top[],
     320             :     int16_t *ltp_param,
     321             :     int16_t *ltp_bits,
     322             :     float *A,
     323             :     const int16_t disable_ltp,
     324             :     const int16_t element_mode )
     325             : {
     326             :     int16_t i, j, n;
     327             :     int16_t ltp_on, tcxOnly, L_subfr, SideInfoOnly, delta;
     328             :     float s;
     329             :     float norm_corr;
     330             :     float pred_speech[L_FRAME_PLUS];
     331             :     float tempFlatness;
     332             :     float maxEnergyChange;
     333             :     float buf_zir[M + L_FRAME_PLUS / 4], *zir;
     334             :     float r[M + 1], Aest[M + 1];
     335             :     float alpha, step;
     336             :     float si_gain;
     337             :     int16_t border_case;
     338             : 
     339    14830182 :     TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;
     340             : 
     341    14830182 :     tcxOnly = st->tcxonly;
     342    14830182 :     L_subfr = L_SUBFR;
     343    14830182 :     SideInfoOnly = st->sr_core > 25600;
     344             : 
     345             :     /* Reset memory if past frame is acelp */
     346    14830182 :     if ( st->last_core == ACELP_CORE )
     347             :     {
     348      145196 :         hTcxEnc->tcxltp_pitch_int_past = L_frame;
     349      145196 :         hTcxEnc->tcxltp_pitch_fr_past = 0;
     350      145196 :         hTcxEnc->tcxltp_gain_past = 0.f;
     351             :     }
     352             : 
     353             :     /* By default, LTP is off */
     354    14830182 :     ltp_param[0] = 0;
     355    14830182 :     norm_corr = 0.0f;
     356    14830182 :     border_case = 0;
     357             : 
     358    14830182 :     if ( hTcxEnc->tcxltp || SideInfoOnly )
     359             :     {
     360             :         /* Find pitch lag */
     361    14830182 :         if ( st->pit_res_max == 6 )
     362             :         {
     363     2259379 :             delta = 8;
     364             :         }
     365             :         else
     366             :         {
     367    12570803 :             delta = 16;
     368             :         }
     369             : 
     370    14830182 :         if ( st->element_mode == IVAS_CPE_MDCT )
     371             :         {
     372    11723026 :             if ( abs( Top[0] - Top[1] ) < ( delta / 2 ) )
     373             :             {
     374             :                 /* estimates are close enough and stable, take the artihmetic mean as estimate */
     375     6902592 :                 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 );
     376             :             }
     377             :             else
     378             :             {
     379             :                 /* pitch jumps between half frames, calc ltp for both estimates, choose the better one */
     380             :                 int16_t pitch_int_2[2];
     381             :                 int16_t pitch_fr_2[2];
     382             :                 float norm_corr_2[2];
     383             :                 int16_t pit_param_2[2];
     384             : 
     385    14461302 :                 for ( i = 0; i < 2; i++ )
     386             :                 {
     387     9640868 :                     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 );
     388             :                 }
     389             : 
     390     4820434 :                 i = ( norm_corr_2[1] > norm_corr_2[0] ) ? 1 : 0;
     391     4820434 :                 hTcxEnc->tcxltp_pitch_int = pitch_int_2[i];
     392     4820434 :                 hTcxEnc->tcxltp_pitch_fr = pitch_fr_2[i];
     393     4820434 :                 ltp_param[1] = pit_param_2[i];
     394     4820434 :                 norm_corr = norm_corr_2[i];
     395             :             }
     396             :         }
     397             :         else
     398             :         {
     399     3107156 :             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 );
     400             :         }
     401             : 
     402    14830182 :         if ( border_case )
     403             :         {
     404     1309963 :             norm_corr = 0.0f;
     405             :         }
     406    14830182 :         if ( st->element_mode == IVAS_CPE_DFT )
     407             :         {
     408      379768 :             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 ) ) ) );
     409             : 
     410      379768 :             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 ) ) );
     411             :         }
     412             :         else
     413             :         {
     414    14450414 :             tempFlatness = GetTCXAvgTemporalFlatnessMeasure( st->hTranDet, NSUBBLOCKS, 1 + min( NSUBBLOCKS, (int16_t) ceil( 0.5f + NSUBBLOCKS * ( 1.0f * ( hTcxEnc->tcxltp_pitch_int ) / L_frame ) ) ) );
     415             : 
     416    14450414 :             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 ) ) );
     417             :         }
     418             : 
     419             :         /* Switch LTP on */
     420    14830182 :         if ( ( tcxOnly == 0 && tcxMode == TCX_20 && norm_corr * hTcxEnc->tcxltp_norm_corr_past > 0.25f && tempFlatness < 3.5f ) ||
     421    13971967 :              ( tcxOnly == 1 && tcxMode == TCX_10 && max( norm_corr, hTcxEnc->tcxltp_norm_corr_past ) > 0.5f && maxEnergyChange < 3.5f ) ||
     422             :              /* 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 */
     423    13950650 :              ( tcxOnly == 1 && norm_corr > 0.44f && L_frame * ( 1.2f - norm_corr ) < hTcxEnc->tcxltp_pitch_int ) ||
     424    11579677 :              ( tcxOnly == 1 && tcxMode == TCX_20 && norm_corr > 0.44f && ( tempFlatness < 6.0f || ( tempFlatness < 7.0f && maxEnergyChange < 22.0f ) ) ) )
     425             :         {
     426     7054840 :             if ( disable_ltp == 0 )
     427             :             {
     428     7053785 :                 ltp_param[0] = 1;
     429             :             }
     430             :         }
     431             : 
     432             :         /* hysteresis for stable ltp prediction */
     433    14830182 :         ltp_on = 0;
     434    14830182 :         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 ) ) ) )
     435             :         {
     436     5582972 :             ltp_on = 1;
     437             :         }
     438             : 
     439    14830182 :         if ( tcxOnly == 1 && ltp_param[0] == 1 )
     440             :         {
     441             :             /* increase ltp counter */
     442     6196625 :             hTcxEnc->tcxltp_on_mem = min( 5, hTcxEnc->tcxltp_on_mem + 1 );
     443             :         }
     444     8633557 :         else if ( ltp_on == 1 )
     445             :         {
     446             :             /* hysteresis takes effect, decrease counter */
     447      643845 :             hTcxEnc->tcxltp_on_mem = max( 0, hTcxEnc->tcxltp_on_mem - 1 );
     448      643845 :             ltp_param[0] = ltp_on;
     449             :         }
     450             :         else
     451             :         {
     452             :             /* no ltp in this frame, reset counter */
     453     7989712 :             hTcxEnc->tcxltp_on_mem = 0;
     454             :         }
     455             :     }
     456             : 
     457             :     /* Find predicted signal */
     458    14830182 :     predict_signal( speech, pred_speech, hTcxEnc->tcxltp_pitch_int, hTcxEnc->tcxltp_pitch_fr, st->pit_res_max, L_frame );
     459             : 
     460             :     /* Find gain */
     461    14830182 :     tcx_ltp_find_gain( speech, pred_speech, L_frame, &hTcxEnc->tcxltp_gain, &ltp_param[2] );
     462             : 
     463    14830182 :     if ( ltp_param[0] )
     464             :     {
     465             :         /* Total number of bits for LTP */
     466     7697630 :         if ( ltp_param[2] + 1 ) /* hTcxEnc->tcxltp_gain > 0 */
     467             :         {
     468     7695170 :             *ltp_bits = 12;
     469             :         }
     470             :         else /* hTcxEnc->tcxltp_gain <= 0 -> turn off LTP */
     471             :         {
     472        2460 :             ltp_param[0] = 0;
     473             :         }
     474             :     }
     475             : 
     476    14830182 :     if ( !ltp_param[0] )
     477             :     {
     478             :         /* No LTP -> set everything to zero */
     479     7135012 :         hTcxEnc->tcxltp_pitch_int = L_frame;
     480     7135012 :         hTcxEnc->tcxltp_pitch_fr = 0;
     481     7135012 :         ltp_param[1] = 0;
     482     7135012 :         set_zero( pred_speech, L_frame );
     483     7135012 :         hTcxEnc->tcxltp_gain = 0.f;
     484     7135012 :         ltp_param[2] = 0;
     485     7135012 :         if ( hTcxEnc->tcxltp || SideInfoOnly )
     486             :         {
     487     7135012 :             *ltp_bits = 1;
     488             :         }
     489             :         else
     490             :         {
     491           0 :             *ltp_bits = 0;
     492             :         }
     493             :     }
     494             : 
     495    14830182 :     si_gain = 0;
     496    14830182 :     if ( SideInfoOnly )
     497             :     {
     498     5896236 :         si_gain = hTcxEnc->tcxltp_gain;
     499     5896236 :         hTcxEnc->tcxltp_gain = 0.f;
     500             :     }
     501             : 
     502    14830182 :     if ( speech_ltp != NULL )
     503             :     {
     504     2727388 :         if ( hTcxEnc->tcxltp_gain_past == 0.f && hTcxEnc->tcxltp_gain == 0.f )
     505             :         {
     506     1845360 :             mvr2r( speech, speech_ltp, L_subfr );
     507             :         }
     508      882028 :         else if ( hTcxEnc->tcxltp_gain_past == 0.f )
     509             :         {
     510      138288 :             alpha = 0.f;
     511      138288 :             step = 1.f / (float) ( L_subfr );
     512     8988720 :             for ( n = 0; n < L_subfr; n++ )
     513             :             {
     514     8850432 :                 speech_ltp[n] = speech[n] - alpha * hTcxEnc->tcxltp_gain * pred_speech[n];
     515     8850432 :                 alpha += step;
     516             :             }
     517             :         }
     518             :         else
     519             :         {
     520      743740 :             if ( A == NULL )
     521             :             {
     522    13167216 :                 for ( i = 0; i <= M; i++ )
     523             :                 {
     524    12435704 :                     s = 0.0;
     525  3773125112 :                     for ( j = 0; j < L_frame - i; j++ )
     526             :                     {
     527  3760689408 :                         s += speech[j - L_frame] * speech[j + i - L_frame];
     528             :                     }
     529    12435704 :                     r[i] = s;
     530             :                 }
     531      731512 :                 if ( r[0] < 100.0f )
     532             :                 {
     533        5890 :                     r[0] = 100.0f;
     534             :                 }
     535      731512 :                 r[0] *= 1.0001f;
     536      731512 :                 lev_dur( Aest, r, M, NULL );
     537      731512 :                 A = Aest;
     538             :             }
     539             : 
     540      743740 :             if ( hTcxEnc->tcxltp_gain > 0.f )
     541             :             {
     542      647353 :                 predict_signal( speech - M, buf_zir, hTcxEnc->tcxltp_pitch_int, hTcxEnc->tcxltp_pitch_fr, st->pit_res_max, M );
     543             :             }
     544             :             else
     545             :             {
     546       96387 :                 set_f( buf_zir, 0.0f, M );
     547             :             }
     548             : 
     549    12643580 :             for ( n = 0; n < M; n++ )
     550             :             {
     551    11899840 :                 buf_zir[n] = speech_ltp[n - M] - speech[n - M] + hTcxEnc->tcxltp_gain * buf_zir[n];
     552             :             }
     553             : 
     554      743740 :             zir = buf_zir + M;
     555      743740 :             set_f( zir, 0.0f, L_subfr );
     556      743740 :             syn_filt( A, M, zir, zir, L_subfr, buf_zir, 0 );
     557      743740 :             alpha = 1.f;
     558      743740 :             step = 1.f / (float) ( L_subfr / 2 );
     559             : 
     560    24543420 :             for ( n = L_subfr / 2; n < L_subfr; n++ )
     561             :             {
     562    23799680 :                 zir[n] *= alpha;
     563    23799680 :                 alpha -= step;
     564             :             }
     565             : 
     566    48343100 :             for ( n = 0; n < L_subfr; n++ )
     567             :             {
     568    47599360 :                 speech_ltp[n] = ( speech[n] - hTcxEnc->tcxltp_gain * pred_speech[n] ) + zir[n];
     569             :             }
     570             :         }
     571             : 
     572     2727388 :         if ( SideInfoOnly || hTcxEnc->tcxltp_gain == 0.0f )
     573             :         {
     574   770760627 :             for ( n = L_subfr; n < L_frame; n++ )
     575             :             {
     576   768818880 :                 speech_ltp[n] = speech[n];
     577             :             }
     578             :         }
     579             :         else
     580             :         {
     581   193858921 :             for ( n = L_subfr; n < L_frame; n++ )
     582             :             {
     583   193073280 :                 speech_ltp[n] = speech[n] - hTcxEnc->tcxltp_gain * pred_speech[n];
     584             :             }
     585             :         }
     586             :     }
     587             : 
     588             :     /* Update */
     589    14830182 :     hTcxEnc->tcxltp_pitch_int_past = hTcxEnc->tcxltp_pitch_int;
     590    14830182 :     hTcxEnc->tcxltp_pitch_fr_past = hTcxEnc->tcxltp_pitch_fr;
     591    14830182 :     hTcxEnc->tcxltp_gain_past = hTcxEnc->tcxltp_gain;
     592             : 
     593    14830182 :     if ( SideInfoOnly )
     594             :     {
     595     5896236 :         hTcxEnc->tcxltp_gain = si_gain;
     596             :     }
     597             : 
     598    14830182 :     hTcxEnc->tcxltp_norm_corr_past = norm_corr;
     599             : 
     600    14830182 :     return;
     601             : }

Generated by: LCOV version 1.14