LCOV - code coverage report
Current view: top level - lib_enc - pitch_ol.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 356 356 100.0 %
Date: 2025-09-11 08:49:05 Functions: 6 6 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             : #include <math.h>
      40             : #include "prot.h"
      41             : #include "cnst.h"
      42             : #include "rom_com.h"
      43             : #include "rom_enc.h"
      44             : #include "wmc_auto.h"
      45             : 
      46             : /*---------------------------------------------------------------------*
      47             :  * Local constants
      48             :  *---------------------------------------------------------------------*/
      49             : 
      50             : #define PIT_MIN2   20 /* pit_min for pitch tracking                                                  */
      51             : #define PIT_MIN_1  44 /* pitch tracking */
      52             : #define PIT_MIN2_1 24
      53             : #define THR_relE   -11.0f
      54             : #define THRES0     1.17f                                                      /* Threshold to favor smaller pitch lags                                       */
      55             : #define DELTA0     2.0f                                                       /* initial range of multiples search                                           */
      56             : #define STEP       1.0f                                                       /* increment in range of multiples search                                      */
      57             : #define THRES1     0.4f                                                       /* Threshold to favor pitch lags coherence for neighbours                      */
      58             : #define DELTA_COH  14                                                         /* Maximum pitch lags difference for neighbours to be considered as coherent   */
      59             : #define THRES3     0.7f                                                       /* Threshold to favor pitch lags coherence with previous frames                */
      60             : #define CORR_TH0   0.4f                                                       /* Noise threshold for reinforcement with past frame pitch                     */
      61             : #define CORR_TH1   0.5f                                                       /* Noise threshold for reinforcement with neighbourhood pitch correlations     */
      62             : #define LEN_X      ( ( PIT_MAX / OPL_DECIM ) - ( PIT_MIN2 / OPL_DECIM ) + 1 ) /* Correlation buffer length             */
      63             : #define COH_FAC    1.4f                                                       /* Factor for measuring the pitch coherence                                    */
      64             : #define NSECT      4
      65             : #define NHFR       3
      66             : #define L_FIR_PO   5
      67             : #define L_MEM      ( L_FIR_PO - 2 )
      68             : 
      69             : /*-----------------------------------------------------------------*
      70             :  * Local function prototypes
      71             :  *-----------------------------------------------------------------*/
      72             : 
      73             : static void pitch_neighbour( const int16_t sect0, const int16_t pitch_tmp[], int16_t pitch[NHFR][2 * NSECT], const float corr_tmp[], float corr[3][2 * NSECT], const float thres1[2 * NHFR], const int16_t ind_tmp[2 * NHFR] );
      74             : 
      75             : static void find_mult( float *fac, const int16_t pitch0, const int16_t pitch1, const int16_t pit_max0, float *corr, int16_t *old_pitch, float *old_corr, float delta, const float step );
      76             : 
      77             : static int16_t pitch_coherence( const int16_t pitch0, const int16_t pitch1, const float fac_max, const int16_t diff_max );
      78             : 
      79             : static void lp_decim2( const float x[], float y[], const int16_t l, float *mem );
      80             : 
      81             : 
      82             : /*-----------------------------------------------------------------*
      83             :  * pitch_ol_init
      84             :  *
      85             :  * Open loop pitch variable initialization
      86             :  *-----------------------------------------------------------------*/
      87             : 
      88     3033065 : void pitch_ol_init(
      89             :     float *old_thres,   /* o  : threshold for reinforcement of past pitch influence */
      90             :     int16_t *old_pitch, /* o  : pitch  of the 1st half-frame of previous frame      */
      91             :     int16_t *delta_pit, /* o  : pitch evolution extrapolation                       */
      92             :     float *old_corr     /* o  : correlation                                         */
      93             : )
      94             : {
      95     3033065 :     *old_thres = 0.0f;
      96     3033065 :     *old_pitch = 0;
      97     3033065 :     *delta_pit = 0;
      98     3033065 :     *old_corr = 0.0f;
      99             : 
     100     3033065 :     return;
     101             : }
     102             : 
     103             : /*-----------------------------------------------------------------*
     104             :  * pitch_ol()
     105             :  *
     106             :  * Compute the open loop pitch lag.
     107             :  *
     108             :  * The pitch lag search is divided in three sections of two sets.
     109             :  * Each section cannot have a pitch multiple.
     110             :  * We find a maximum for each section.
     111             :  * We compare the maxima of each section.
     112             :  *
     113             :  * As there is a margin between section overlaps, especially for
     114             :  * longer delays, this section selection is more robust for not
     115             :  * to find multiples in the same section when pitch evolves rapidly
     116             :  *
     117             :  * For each section, the length of the vectors to correlate is
     118             :  * greater than or equal to the longest pitch delay
     119             :  *------------------------------------------------------------------*/
     120             : 
     121    16218896 : void pitch_ol(
     122             :     int16_t pitch[3],         /* o  : open loop pitch lag for each half-frame                        */
     123             :     float voicing[3],         /* o  : maximum normalized correlation for each half-frame             */
     124             :     int16_t *old_pitch,       /* i/o: OL pitch of the 2nd half-frame of the last frame               */
     125             :     float *old_corr,          /* i/o: correlation                                                    */
     126             :     float corr_shift,         /* i  : normalized correlation correction                              */
     127             :     float *old_thres,         /* i/o: maximum correlation weighting with respect to past frame pitch */
     128             :     int16_t *delta_pit,       /* i/o: old pitch extrapolation correction (added to old pitch)        */
     129             :     float *st_old_wsp2,       /* i/o: weighted speech memory                                         */
     130             :     const float *wsp,         /* i  : weighted speech for current frame and look-ahead               */
     131             :     float mem_decim2[3],      /* i/o: wsp decimation filter memory                                   */
     132             :     const float relE,         /* i  : relative frame energy                                          */
     133             :     const int16_t L_look,     /* i  : look-ahead length                                              */
     134             :     const int16_t last_class, /* i  : frame classification of last frame                             */
     135             :     const int16_t bwidth,     /* i  : audio bandwidth                                                */
     136             :     const int16_t Opt_SC_VBR  /* i  : SC-VBR flag                                                    */
     137             : )
     138             : {
     139             :     float old_wsp2[( L_WSP - L_INTERPOL ) / OPL_DECIM], *wsp2;
     140             :     float tmp_mem[3], scale1[2 * DELTA_COH - 1];
     141             :     float scaled_buf[2 * LEN_X + 3 * ( DELTA_COH - 1 )];
     142    16218896 :     float cor_temp, cor_buf[2 * LEN_X], *pt1, *pt2, *pt3, *pt4, *pt5 = 0, *pt6 = 0, *pt_cor0, *pt_cor1, *pt_cor2, *pt_cor3, *pt_cor4;
     143             :     float thres1[2 * NHFR];
     144    16218896 :     int16_t diff, cnt, ind, ind1, offset, offset1, offset_la = 0, offset_la1 = 0, coh_flag, coh_flag1;
     145             : 
     146             :     int16_t i, j, k, m, pit_min, pit_min1, sect0, subsect0, old_tmp, old_tmp1, len_x, len_x1, len_temp, len_temp1;
     147             :     int16_t pitchX[NHFR][2 * NSECT], pitch_tmp[2 * NHFR], ind_tmp[2 * NHFR], tmp_buf[NHFR + 1];
     148    16218896 :     float enr, enr1 = 0.0f, enr_norm[NSECT], enr_norm1[NSECT], fac;
     149             :     float scaledX[NHFR][2 * NSECT], corX[NHFR][2 * NSECT], cor_tmp[2 * NHFR], cor_mean;
     150             : 
     151             :     const int16_t *nb_sect, *nb_subsect, *len, *len1, *sublen, *sublen1, *pit_max, *sec_length, *sec_length1;
     152             :     int16_t ind_corX, ind1_corX;
     153             :     float pit_min_coding;
     154             : 
     155             :     /*--------------------------------------------------------------*
     156             :      * Initialization
     157             :      *--------------------------------------------------------------*/
     158             : 
     159    16218896 :     nb_sect = nb_sect_12k8;
     160    16218896 :     nb_subsect = nb_subsect_12k8;
     161             : 
     162    16218896 :     len = len_12k8;
     163    16218896 :     len1 = len1_12k8;
     164    16218896 :     sublen = sublen_12k8;
     165    16218896 :     sublen1 = sublen1_12k8;
     166    16218896 :     pit_max = pit_max_12k8;
     167    16218896 :     sec_length = sec_length_12k8;
     168    16218896 :     sec_length1 = sec_length1_12k8;
     169             : 
     170    16218896 :     if ( last_class < VOICED_TRANSITION && bwidth != NB )
     171             :     {
     172             :         /* reset last pitch reinforcement in case of unvoiced or transitions: it avoids some pitch doublings */
     173    10703631 :         *old_thres = 0.0f;
     174             :     }
     175             : 
     176    16218896 :     pit_min_coding = PIT_MIN_EXTEND;
     177    16218896 :     if ( ( bwidth != NB && *old_pitch > PIT_MIN ) ||
     178      178549 :          ( bwidth == NB && ( *old_pitch > PIT_MIN2_1 || *old_thres < 0.1 ) ) )
     179             :     {
     180     6853367 :         pit_min = PIT_MIN / OPL_DECIM;
     181     6853367 :         pit_min1 = PIT_MIN_1 / OPL_DECIM;
     182     6853367 :         subsect0 = 2;
     183     6853367 :         sect0 = 1;
     184             :     }
     185             :     else
     186             :     {
     187     9365529 :         pit_min = PIT_MIN2 / OPL_DECIM;
     188     9365529 :         pit_min1 = PIT_MIN2_1 / OPL_DECIM;
     189     9365529 :         subsect0 = 0;
     190     9365529 :         sect0 = 0;
     191             :     }
     192             : 
     193    16218896 :     len_x = PIT_MAX / OPL_DECIM - pit_min + 1;
     194    16218896 :     len_x1 = PIT_MAX / OPL_DECIM - pit_min1 + 1;
     195             : 
     196             :     /*--------------------------------------------------------------*
     197             :      * Find decimated weighted speech
     198             :      * Update wsp buffer with the memory
     199             :      * decimation of wsp[] to search pitch in LF and to reduce complexity
     200             :      * Extend the decimation of wsp to the end of the speech buffer
     201             :      * Update wsp memory
     202             :      *--------------------------------------------------------------*/
     203             : 
     204    16218896 :     mvr2r( st_old_wsp2, old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM );
     205    16218896 :     wsp2 = old_wsp2 + ( ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM );
     206    16218896 :     lp_decim2( wsp, wsp2, L_FRAME, mem_decim2 );
     207             : 
     208    16218896 :     mvr2r( mem_decim2, tmp_mem, 3 );
     209    16218896 :     lp_decim2( &wsp[L_FRAME], &wsp2[L_FRAME / OPL_DECIM], L_look, tmp_mem );
     210             : 
     211    16218896 :     mvr2r( &old_wsp2[L_FRAME / OPL_DECIM], st_old_wsp2, ( L_WSP_MEM - L_INTERPOL ) / OPL_DECIM );
     212             : 
     213             :     /*-----------------------------------------------------------------*
     214             :      * attenuate the correlation correction factor due to noise
     215             :      * reset correlation buffer outside the useful range
     216             :      * Find the scaling functions for immediate neigbours and
     217             :      * further ones
     218             :      *-----------------------------------------------------------------*/
     219             : 
     220    16218896 :     corr_shift *= 0.5f;
     221    16218896 :     set_f( scaled_buf, 0, DELTA_COH - 1 );
     222    16218896 :     set_f( scaled_buf + ( DELTA_COH - 1 ) + len_x, 0, DELTA_COH - 1 );
     223    16218896 :     set_f( scaled_buf + 2 * ( DELTA_COH - 1 ) + len_x + len_x1, 0, DELTA_COH - 1 );
     224             : 
     225    16218896 :     pt1 = scale1 + DELTA_COH - 1;
     226    16218896 :     pt2 = pt1;
     227   243283440 :     for ( i = 0; i < DELTA_COH; i++ )
     228             :     {
     229   227064544 :         *pt1 = -( *old_thres ) / DELTA_COH * i + *old_thres + 1.0f;
     230   227064544 :         *pt2-- = *pt1++;
     231             :     }
     232             : 
     233             :     /*-----------------------------------------------------------------*
     234             :      * Estimate the new pitch by extrapolating the old pitch value
     235             :      * for 2 half-frames
     236             :      *-----------------------------------------------------------------*/
     237             : 
     238    16218896 :     old_tmp = *old_pitch + *delta_pit;
     239             : 
     240    16218896 :     if ( old_tmp > PIT_MAX / OPL_DECIM )
     241             :     {
     242       35410 :         old_tmp = PIT_MAX / OPL_DECIM;
     243             :     }
     244             : 
     245    16218896 :     if ( old_tmp < pit_min )
     246             :     {
     247     3111301 :         old_tmp = pit_min;
     248             :     }
     249             : 
     250    16218896 :     old_tmp1 = old_tmp + *delta_pit;
     251    16218896 :     if ( old_tmp1 > PIT_MAX / OPL_DECIM )
     252             :     {
     253       57169 :         old_tmp1 = PIT_MAX / OPL_DECIM;
     254             :     }
     255             : 
     256    16218896 :     if ( old_tmp1 < pit_min )
     257             :     {
     258      198894 :         old_tmp1 = pit_min;
     259             :     }
     260             : 
     261             : 
     262             :     /*-----------------------------------------------------------------*
     263             :      * Loop for all three half-frames (current frame + look-ahead)
     264             :      *-----------------------------------------------------------------*/
     265    16218896 :     pt_cor0 = scaled_buf + DELTA_COH - 1;
     266             : 
     267    16218896 :     pt_cor2 = pt_cor0 - pit_min + old_tmp;
     268    16218896 :     pt_cor4 = pt_cor0 - pit_min1 + old_tmp + ( DELTA_COH - 1 ) + len_x;
     269             : 
     270    64875584 :     for ( i = 0; i < NHFR; i++ )
     271             :     {
     272    48656688 :         pt1 = wsp2 + i * 2 * ( L_SUBFR / OPL_DECIM );
     273    48656688 :         pt2 = pt1 - pit_min;
     274    48656688 :         enr = 0.01f;
     275    48656688 :         pt_cor1 = pt_cor0;
     276    48656688 :         pt4 = pt1 - pit_min1;
     277    48656688 :         pt_cor3 = pt_cor0 + ( DELTA_COH - 1 ) + len_x;
     278             : 
     279             :         /*-----------------------------------------------------------------*
     280             :          * First two half-frames (corresponding to current frame)
     281             :          *-----------------------------------------------------------------*/
     282    48656688 :         if ( i < NHFR - 1 )
     283             :         {
     284    32437792 :             pt3 = pt1;
     285    32437792 :             pt5 = pt1;
     286             : 
     287   148482226 :             for ( j = sect0; j < nb_sect[i]; j++ ) /* loop for each section */
     288             :             {
     289             :                 /*-----------------------------------------------------------------*
     290             :                  * Find fixed vector energy
     291             :                  *-----------------------------------------------------------------*/
     292             : 
     293             :                 /* 1st set */
     294   116044434 :                 k = (int16_t) ( pt1 - pt3 );
     295  3846390514 :                 for ( k = k + len[j]; k > 0; k-- )
     296             :                 {
     297  3730346080 :                     enr += *pt3 * *pt3;
     298  3730346080 :                     pt3++;
     299             :                 }
     300   116044434 :                 enr_norm[j] = enr;
     301             : 
     302             :                 /* Reduce complexity (length of 'enr1' section is equal or larger than 'enr') */
     303   116044434 :                 pt5 = pt3;
     304   116044434 :                 enr1 = enr;
     305             : 
     306             :                 /* 2nd set */
     307   116044434 :                 k = (int16_t) ( pt1 - pt5 );
     308  1024302610 :                 for ( k = k + len1[j]; k > 0; k-- )
     309             :                 {
     310   908258176 :                     enr1 += *pt5 * *pt5;
     311   908258176 :                     pt5++;
     312             :                 }
     313   116044434 :                 enr_norm1[j] = enr1;
     314             :             }
     315             : 
     316             :             /*-----------------------------------------------------------------*
     317             :              * Find correlation for the non-overlapping pitch lag values
     318             :              *-----------------------------------------------------------------*/
     319    32437792 :             k = (int16_t) ( pt2 - pt1 );
     320   138433578 :             for ( k = k + pit_max[subsect0]; k >= 0; k-- )
     321             :             {
     322   105995786 :                 *pt_cor1++ = dotp( pt1, pt2--, sublen[0] );
     323             :             }
     324             : 
     325             :             /*-----------------------------------------------------------------*
     326             :              * For each subsection, find the correlation
     327             :              *-----------------------------------------------------------------*/
     328   232088868 :             for ( j = subsect0; j < nb_subsect[i]; j++ )
     329             :             {
     330   199651076 :                 len_temp = sublen[j];
     331   199651076 :                 len_temp1 = sublen1[j];
     332             : 
     333   199651076 :                 k = (int16_t) ( pt2 - pt1 );
     334   199651076 :                 if ( len_temp < len_temp1 )
     335             :                 {
     336  1070447136 :                     for ( k = k + pit_max[j + 1]; k >= 0; k-- )
     337             :                     {
     338  1005571552 :                         cor_temp = pt1[0] * pt2[0];
     339 55209121984 :                         for ( m = 1; m < len_temp; m++ )
     340             :                         {
     341 54203550432 :                             cor_temp += pt1[m] * pt2[m];
     342             :                         }
     343  1005571552 :                         *pt_cor1++ = cor_temp;
     344 16510836128 :                         for ( ; m < len_temp1; m++ )
     345             :                         {
     346 15505264576 :                             cor_temp += pt1[m] * pt2[m];
     347             :                         }
     348  1005571552 :                         *pt_cor3++ = cor_temp;
     349  1005571552 :                         pt2--;
     350             :                     }
     351             :                 }
     352             :                 else
     353             :                 {
     354  2365666968 :                     for ( k = k + pit_max[j + 1]; k >= 0; k-- )
     355             :                     {
     356  2230891476 :                         cor_temp = pt1[0] * pt2[0];
     357 >20536*10^7 :                         for ( m = 1; m < len_temp1; m++ )
     358             :                         {
     359 >20313*10^7 :                             cor_temp += pt1[m] * pt2[m];
     360             :                         }
     361  2230891476 :                         *pt_cor3++ = cor_temp;
     362 23899336532 :                         for ( ; m < len_temp; m++ )
     363             :                         {
     364 21668445056 :                             cor_temp += pt1[m] * pt2[m];
     365             :                         }
     366  2230891476 :                         *pt_cor1++ = cor_temp;
     367  2230891476 :                         pt2--;
     368             :                     }
     369             :                 }
     370             :             }
     371             :         }
     372             : 
     373             :         /*-----------------------------------------------------------------*
     374             :          * Third half-frame (look-ahead)
     375             :          *-----------------------------------------------------------------*/
     376             : 
     377             :         else
     378             :         {
     379             :             /*-----------------------------------------------------------------*
     380             :              * For each section in both sets, find fixed vector energy
     381             :              *-----------------------------------------------------------------*/
     382             : 
     383    16218896 :             pt6 = pt1 + L_look / OPL_DECIM - 1;
     384    16218896 :             pt3 = pt6;
     385    16218896 :             pt5 = pt6;
     386             : 
     387    74241113 :             for ( j = sect0; j < nb_sect[i]; j++ ) /* loop for each section */
     388             :             {
     389             :                 /* 1st set */
     390    58022217 :                 k = (int16_t) ( pt3 - pt6 );
     391  1923195257 :                 for ( k = k + len[j]; k > 0; k-- )
     392             :                 {
     393  1865173040 :                     enr += *pt3 * *pt3;
     394  1865173040 :                     pt3--;
     395             :                 }
     396             : 
     397    58022217 :                 enr_norm[j] = enr;
     398             : 
     399    58022217 :                 pt5 = pt3;
     400    58022217 :                 enr1 = enr;
     401             : 
     402             :                 /* 2nd set */
     403    58022217 :                 k = (int16_t) ( pt5 - pt6 );
     404   512151305 :                 for ( k = k + len1[j]; k > 0; k-- )
     405             :                 {
     406   454129088 :                     enr1 += *pt5 * *pt5;
     407   454129088 :                     pt5--;
     408             :                 }
     409             : 
     410    58022217 :                 enr_norm1[j] = enr1;
     411             :             }
     412             : 
     413             :             /* Set pointers */
     414    16218896 :             if ( sect0 == 0 )
     415             :             {
     416     9365529 :                 pt2 = pt6 - pit_min;
     417     9365529 :                 k = 2;
     418             :             }
     419             :             else
     420             :             {
     421     6853367 :                 pt2 = pt6 - pit_max[1] - 1;
     422     6853367 :                 k = pit_max[2] - pit_max[1];
     423             :             }
     424             : 
     425             :             /*-----------------------------------------------------------------*
     426             :              * Find correlation for the non-overlapping pitch lag values
     427             :              *-----------------------------------------------------------------*/
     428             : 
     429    69216789 :             for ( ; k > 0; k-- )
     430             :             {
     431    52997893 :                 *pt_cor1 = 0;
     432  2172913613 :                 for ( m = 0; m < sublen[0]; m++ )
     433             :                 {
     434  2119915720 :                     *pt_cor1 += pt6[-m] * pt2[-m];
     435             :                 }
     436    52997893 :                 pt_cor1++;
     437    52997893 :                 pt2--;
     438             :             }
     439             : 
     440             :             /*-----------------------------------------------------------------*
     441             :              * For each subsection, find the correlation (overlapping pitch lag values)
     442             :              *-----------------------------------------------------------------*/
     443             : 
     444   116044434 :             for ( j = subsect0; j < nb_subsect[i]; j++ )
     445             :             {
     446    99825538 :                 len_temp = sublen[j];
     447    99825538 :                 len_temp1 = sublen1[j];
     448             : 
     449    99825538 :                 k = pit_max[j + 1] - pit_max[j];
     450    99825538 :                 if ( len_temp < len_temp1 )
     451             :                 {
     452   535223568 :                     for ( ; k > 0; k-- )
     453             :                     {
     454   502785776 :                         cor_temp = pt6[0] * pt2[0];
     455 27604560992 :                         for ( m = 1; m < len_temp; m++ )
     456             :                         {
     457 27101775216 :                             cor_temp += pt6[-m] * pt2[-m];
     458             :                         }
     459   502785776 :                         *pt_cor1++ = cor_temp;
     460  8255418064 :                         for ( ; m < len_temp1; m++ )
     461             :                         {
     462  7752632288 :                             cor_temp += pt6[-m] * pt2[-m];
     463             :                         }
     464   502785776 :                         *pt_cor3++ = cor_temp;
     465   502785776 :                         pt2--;
     466             :                     }
     467             :                 }
     468             :                 else
     469             :                 {
     470  1182833484 :                     for ( ; k > 0; k-- )
     471             :                     {
     472  1115445738 :                         cor_temp = pt6[0] * pt2[0];
     473 >10268*10^7 :                         for ( m = 1; m < len_temp1; m++ )
     474             :                         {
     475 >10156*10^7 :                             cor_temp += pt6[-m] * pt2[-m];
     476             :                         }
     477  1115445738 :                         *pt_cor3++ = cor_temp;
     478 11949668266 :                         for ( ; m < len_temp; m++ )
     479             :                         {
     480 10834222528 :                             cor_temp += pt6[-m] * pt2[-m];
     481             :                         }
     482  1115445738 :                         *pt_cor1++ = cor_temp;
     483  1115445738 :                         pt2--;
     484             :                     }
     485             :                 }
     486             :             }
     487             :         }
     488             : 
     489             :         /* Save unscaled correlation vector  */
     490    48656688 :         mvr2r( pt_cor0, cor_buf, len_x );
     491    48656688 :         mvr2r( pt_cor0 + ( DELTA_COH - 1 ) + len_x, cor_buf + len_x, len_x1 );
     492             : 
     493             :         /*-----------------------------------------------------------------*
     494             :          * scale correlation function in the neighbourhood of
     495             :          * the extrapolated pitch
     496             :          *-----------------------------------------------------------------*/
     497    48656688 :         pt_cor1 = pt_cor2 - ( DELTA_COH - 1 );
     498    48656688 :         pt_cor3 = pt_cor4 - ( DELTA_COH - 1 );
     499    48656688 :         pt2 = scale1;
     500             : 
     501  1362387264 :         for ( k = 0; k < 2 * DELTA_COH - 1; k++ )
     502             :         {
     503  1313730576 :             *pt_cor1++ *= ( *pt2 );
     504  1313730576 :             *pt_cor3++ *= ( *pt2++ );
     505             :         }
     506             : 
     507             :         /* update for next half-frame */
     508    48656688 :         pt_cor2 = pt_cor0 - pit_min + old_tmp1;
     509    48656688 :         pt_cor4 = pt_cor0 - pit_min1 + old_tmp1 + ( DELTA_COH - 1 ) + len_x;
     510             :         /*-----------------------------------------------------------------*
     511             :          * For each section, find maximum correlation and compute
     512             :          * normalized correlation
     513             :          *-----------------------------------------------------------------*/
     514             : 
     515    48656688 :         pt_cor1 = pt_cor0;
     516    48656688 :         offset = 0;
     517    48656688 :         pt_cor3 = pt_cor0 + ( DELTA_COH - 1 ) + len_x;
     518    48656688 :         offset1 = 0;
     519   222723339 :         for ( j = sect0; j < nb_sect[i]; j++ ) /* loop for each section */
     520             :         {
     521             :             /* 1st set */
     522   174066651 :             if ( i == 2 )
     523             :             {
     524    58022217 :                 offset_la = L_look / OPL_DECIM - 1 - ( len[j] - 1 );
     525             :             }
     526             :             else
     527             :             {
     528   116044434 :                 offset_la = 0;
     529             :             }
     530             : 
     531             :             /* 2nd set */
     532   174066651 :             if ( i == 2 )
     533             :             {
     534    58022217 :                 offset_la1 = L_look / OPL_DECIM - 1 - ( len1[j] - 1 );
     535             :             }
     536             :             else
     537             :             {
     538   116044434 :                 offset_la1 = 0;
     539             :             }
     540             : 
     541             :             /* 1st set of candidates */
     542   174066651 :             ind = maximum( pt_cor1, sec_length[j], 0 ) + offset;
     543   174066651 :             pitchX[i][j] = ind + pit_min;
     544   174066651 :             pt2 = pt1 - pitchX[i][j] + offset_la; /* selected moving vector  */
     545   174066651 :             enr1 = dotp( pt2, pt2, len[j] ) + 0.01f;
     546   174066651 :             enr1 = inv_sqrt( enr_norm[j] * enr1 ); /* 1/sqrt(energy)    */
     547   174066651 :             corX[i][j] = cor_buf[ind] * enr1;      /* find best normalized correlation per section  */
     548   174066651 :             scaledX[i][j] = pt_cor0[ind] * enr1;   /* find best scaled normalized correlation per section  */
     549             : 
     550   174066651 :             pt_cor1 += sec_length[j];
     551   174066651 :             offset = offset + sec_length[j];
     552             : 
     553             :             /* 2nd set of candidates */
     554   174066651 :             ind1 = maximum( pt_cor3, sec_length1[j], 0 ) + offset1;
     555   174066651 :             pitchX[i][j + NSECT] = ind1 + pit_min1;
     556   174066651 :             pt4 = pt1 - pitchX[i][j + NSECT] + offset_la1; /* selected moving vector  */
     557   174066651 :             enr1 = dotp( pt4, pt4, len1[j] ) + 0.01f;
     558   174066651 :             enr1 = inv_sqrt( enr_norm1[j] * enr1 );                                   /* 1/sqrt(energy) */
     559   174066651 :             corX[i][j + NSECT] = cor_buf[ind1 + len_x] * enr1;                        /* find best normalized correlation per section */
     560   174066651 :             scaledX[i][j + NSECT] = pt_cor0[ind1 + ( DELTA_COH - 1 ) + len_x] * enr1; /* find best scaled normalized correlation per section */
     561             : 
     562   174066651 :             pt_cor3 += sec_length1[j];
     563   174066651 :             offset1 = offset1 + sec_length1[j];
     564             :         }
     565             :     }
     566             :     /*-----------------------------------------------------------------*
     567             :      * Favor a smaller delay if it happens that it has its multiple
     568             :      * in the longer-delay sections  (harmonics check)
     569             :      *-----------------------------------------------------------------*/
     570             : 
     571    48656688 :     for ( i = 0; i < 2; i++ ) /* loop for the 2 half-frames */
     572             :     {
     573    32437792 :         fac = THRES0;
     574    32437792 :         find_mult( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in longest-delay section */
     575    32437792 :         find_mult( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */
     576             : 
     577    32437792 :         if ( ( sect0 == 0 ) && ( ( pitchX[i][0] * 2 ) >= pit_min_coding ) )
     578             :         {
     579    18731058 :             find_mult( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */
     580             :         }
     581    32437792 :         fac = THRES0;
     582    32437792 :         find_mult( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in longest-delay section */
     583    32437792 :         find_mult( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */
     584             : 
     585    32437792 :         if ( ( sect0 == 0 ) && ( pitchX[i][NSECT + 0] * 2 >= pit_min_coding ) )
     586             :         {
     587    18731058 :             find_mult( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */
     588             :         }
     589             :     }
     590             : 
     591    16218896 :     fac = THRES0;                                                                                                 /*  the look-ahead  */
     592    16218896 :     find_mult( &fac, pitchX[i][2], pitchX[i][3], pit_max[7], &scaledX[i][2], old_pitch, old_corr, 2.0f, 2.0f );   /* Multiples in longest-delay section */
     593    16218896 :     find_mult( &fac, pitchX[i][1], pitchX[i][2], pit_max[5], &scaledX[i][1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */
     594             : 
     595    16218896 :     if ( ( sect0 == 0 ) && ( pitchX[i][0] * 2 >= pit_min_coding ) )
     596             :     {
     597     9365529 :         find_mult( &fac, pitchX[i][0], pitchX[i][1], pit_max[3], &scaledX[i][0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */
     598             :     }
     599             : 
     600    16218896 :     fac = THRES0;                                                                                                                         /*  the look-ahead  */
     601    16218896 :     find_mult( &fac, pitchX[i][NSECT + 2], pitchX[i][NSECT + 3], pit_max[7], &scaledX[i][NSECT + 2], old_pitch, old_corr, 2.0f, 2.0f );   /* Multiples in longest-delay section */
     602    16218896 :     find_mult( &fac, pitchX[i][NSECT + 1], pitchX[i][NSECT + 2], pit_max[6], &scaledX[i][NSECT + 1], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 3rd section */
     603             : 
     604    16218896 :     if ( ( sect0 == 0 ) && ( pitchX[i][NSECT + 0] * 2 >= pit_min_coding ) )
     605             :     {
     606     9365529 :         find_mult( &fac, pitchX[i][NSECT + 0], pitchX[i][NSECT + 1], pit_max[4], &scaledX[i][NSECT + 0], old_pitch, old_corr, DELTA0, STEP ); /* Multiples in 2nd section */
     607             :     }
     608             : 
     609             :     /*-----------------------------------------------------------------*
     610             :      * Do 1st estimate for pitch values
     611             :      * Adjust the normalized correlation using estimated noise level
     612             :      * Compute the maximum scaling for the neighbour correlation
     613             :      * reinforcement
     614             :      *-----------------------------------------------------------------*/
     615             : 
     616    64875584 :     for ( i = 0; i < NHFR; i++ )
     617             :     {
     618    48656688 :         ind = maximum( scaledX[i] + sect0, (int16_t) ( NSECT - sect0 ), 0 );
     619    48656688 :         ind = ind + sect0;
     620    48656688 :         ind_tmp[i] = ind;
     621    48656688 :         pitch_tmp[i] = pitchX[i][ind];
     622    48656688 :         cor_tmp[i] = corX[i][ind];
     623    48656688 :         cor_tmp[i] += corr_shift;
     624             : 
     625    48656688 :         if ( cor_tmp[i] > 1.0f )
     626             :         {
     627       16969 :             cor_tmp[i] = 1.0f;
     628             :         }
     629    48656688 :         thres1[i] = THRES1 * cor_tmp[i]; /* Higher is the neighbour's correlation, higher is the weighting  */
     630             : 
     631             :         /* 2nd set of pitch candidates */
     632    48656688 :         ind1 = maximum( scaledX[i] + sect0 + NSECT, (int16_t) ( NSECT - sect0 ), 0 );
     633    48656688 :         ind1 += ( sect0 + NSECT );
     634    48656688 :         ind_tmp[i + NHFR] = ind1;
     635    48656688 :         pitch_tmp[i + NHFR] = pitchX[i][ind1];
     636    48656688 :         cor_tmp[i + NHFR] = corX[i][ind1];
     637    48656688 :         cor_tmp[i + NHFR] += corr_shift;
     638             : 
     639    48656688 :         if ( cor_tmp[i + NHFR] > 1.0f )
     640             :         {
     641       16499 :             cor_tmp[i + NHFR] = 1.0f;
     642             :         }
     643    48656688 :         thres1[i + NHFR] = THRES1 * cor_tmp[i + NHFR]; /* Higher is the neighbour's correlation, higher is the weighting */
     644             :     }
     645             :     /*-----------------------------------------------------------------*
     646             :      * Take into account previous and next pitch values of the present
     647             :      * frame and look-ahead. Choose the pitch lags and normalize
     648             :      * correlations for each half-frame & look-ahead
     649             :      *-----------------------------------------------------------------*/
     650             : 
     651    16218896 :     pitch_neighbour( sect0, pitch_tmp, pitchX, cor_tmp, scaledX, thres1, ind_tmp );
     652    64875584 :     for ( i = 0; i < NHFR; i++ )
     653             :     {
     654    48656688 :         ind = maximum( scaledX[i] + sect0, (int16_t) ( NSECT - sect0 ), 0 );
     655    48656688 :         ind = ind + sect0;
     656    48656688 :         ind_corX = maximum( corX[i] + sect0, (int16_t) ( NSECT - sect0 ), 0 );
     657    48656688 :         ind_corX = ind_corX + sect0;
     658             : 
     659    48656688 :         ind1 = maximum( scaledX[i] + sect0 + NSECT, (int16_t) ( NSECT - sect0 ), 0 );
     660    48656688 :         ind1 += ( sect0 + NSECT );
     661    48656688 :         ind1_corX = maximum( corX[i] + sect0 + NSECT, (int16_t) ( NSECT - sect0 ), 0 );
     662    48656688 :         ind1_corX += ( sect0 + NSECT );
     663             : 
     664    48656688 :         if ( scaledX[i][ind1] > scaledX[i][ind] )
     665             :         {
     666    18575993 :             ind = ind1;
     667             :         }
     668             : 
     669    48656688 :         if ( Opt_SC_VBR && corX[i][ind1_corX] > corX[i][ind_corX] )
     670             :         {
     671        2239 :             ind_corX = ind1_corX;
     672             :         }
     673             : 
     674    48656688 :         if ( Opt_SC_VBR && ( pitchX[i][ind] * 0.4 < pitchX[i][ind_corX] ) && ( pitchX[i][ind] * 0.6 > pitchX[i][ind_corX] ) && ( corX[i][ind_corX] >= 0.9 ) ) /* && (pitchX[i][ind]>50)) */
     675             :         {
     676          18 :             pitch[i] = pitchX[i][ind_corX];
     677          18 :             voicing[i] = corX[i][ind_corX];
     678             :         }
     679             :         else
     680             :         {
     681    48656670 :             pitch[i] = pitchX[i][ind];
     682    48656670 :             voicing[i] = corX[i][ind];
     683             :         }
     684             :     }
     685             : 
     686             :     /*-----------------------------------------------------------------*
     687             :      * Increase the threshold for correlation reinforcement with
     688             :      * the past if correlation is high and pitch is stable
     689             :      *-----------------------------------------------------------------*/
     690             : 
     691    16218896 :     cor_mean = 0.5f * ( voicing[0] + voicing[1] ) + corr_shift;
     692    16218896 :     if ( cor_mean > 1.0f )
     693             :     {
     694        3749 :         cor_mean = 1.0f;
     695             :     }
     696             : 
     697             :     /* pitch unstable in present frame or from previous frame or normalized correlation too low  */
     698    16218896 :     coh_flag = pitch_coherence( (int16_t) pitch[0], (int16_t) pitch[1], COH_FAC, DELTA_COH );
     699    16218896 :     coh_flag1 = pitch_coherence( (int16_t) pitch[0], (int16_t) *old_pitch, COH_FAC, DELTA_COH );
     700    16218896 :     if ( ( coh_flag == 0 ) || ( coh_flag1 == 0 ) || ( cor_mean < CORR_TH0 ) || ( relE < THR_relE ) )
     701             :     {
     702     9736193 :         *old_thres = 0.0f; /* Reset the threshold          */
     703             :     }
     704             :     else
     705             :     {
     706     6482703 :         *old_thres += ( 0.16f * cor_mean ); /* The threshold increase is directly dependent on normalized correlation  */
     707             :     }
     708             : 
     709    16218896 :     if ( *old_thres > THRES3 )
     710             :     {
     711     2786907 :         *old_thres = THRES3;
     712             :     }
     713             : 
     714    16218896 :     if ( voicing[1] > voicing[0] )
     715             :     {
     716     7630794 :         *old_corr = voicing[1];
     717             :     }
     718             :     else
     719             :     {
     720     8588102 :         *old_corr = cor_mean;
     721             :     }
     722             : 
     723             :     /*-----------------------------------------------------------------*
     724             :      * Extrapolate the pitch value for the next frame by estimating
     725             :      * the pitch evolution. This value is added to the old_pitch
     726             :      * in the next frame and is then used when the normalized
     727             :      * correlation is reinforced by the past estimate
     728             :      *-----------------------------------------------------------------*/
     729             : 
     730    16218896 :     tmp_buf[0] = *old_pitch;
     731    64875584 :     for ( i = 0; i < NHFR; i++ )
     732             :     {
     733    48656688 :         tmp_buf[i + 1] = pitch[i];
     734             :     }
     735             : 
     736    16218896 :     *delta_pit = 0;
     737    16218896 :     cnt = 0;
     738    64875584 :     for ( i = 0; i < NHFR; i++ )
     739             :     {
     740    48656688 :         diff = tmp_buf[i + 1] - tmp_buf[i];
     741    48656688 :         coh_flag = pitch_coherence( (int16_t) tmp_buf[i], (int16_t) tmp_buf[i + 1], COH_FAC, DELTA_COH );
     742    48656688 :         if ( coh_flag != 0 )
     743             :         {
     744    32003539 :             *delta_pit = *delta_pit + diff;
     745    32003539 :             cnt++;
     746             :         }
     747             :     }
     748             : 
     749    16218896 :     if ( cnt == 2 )
     750             :     {
     751     3856379 :         *delta_pit /= 2;
     752             :     }
     753             : 
     754    16218896 :     if ( cnt == 3 )
     755             :     {
     756     7011354 :         *delta_pit /= 3;
     757             :     }
     758             : 
     759             :     /*-----------------------------------------------------------------*
     760             :      * update old pitch, upsample pitch
     761             :      *-----------------------------------------------------------------*/
     762             : 
     763    16218896 :     *old_pitch = pitch[1];
     764             : 
     765    64875584 :     for ( i = 0; i < NHFR; i++ )
     766             :     {
     767    48656688 :         pitch[i] *= OPL_DECIM;
     768             :     }
     769             : 
     770             : 
     771    16218896 :     return;
     772             : }
     773             : 
     774             : /*-----------------------------------------------------------------*
     775             :  * find_mult
     776             :  *
     777             :  * Verifies whether max pitch delays in higher sections have multiples
     778             :  * in lower sections
     779             :  *-----------------------------------------------------------------*/
     780             : 
     781   250819926 : static void find_mult(
     782             :     float *fac,             /* i/o: correlation scaling factor                           */
     783             :     const int16_t pitch0,   /* i  : pitch of max correlation in the c section            */
     784             :     const int16_t pitch1,   /* i  : pitch of max correlation in the longer-delay section */
     785             :     const int16_t pit_max0, /* i  : max pitch delay in the longer-delay section          */
     786             :     float *corr,            /* i/o: max correlation in the shorter-delay section         */
     787             :     int16_t *old_pitch,     /* i  : pitch from previous frame                            */
     788             :     float *old_corr,        /* i  : max correlation from previous frame                  */
     789             :     float delta,            /* i  : initial multiples search range                       */
     790             :     const float step        /* i  : increment in range of multiples search               */
     791             : )
     792             : {
     793             :     int16_t pit_min;
     794             : 
     795   250819926 :     pit_min = 2 * pitch0;                           /* double the shorter-delay section pitch */
     796   550515163 :     while ( pit_min <= pit_max0 + (int16_t) delta ) /* check for section boundary */
     797             :     {
     798   299695237 :         if ( abs( pit_min - pitch1 ) <= (int16_t) delta ) /* if multiple in the allowed range */
     799             :         {
     800    82526072 :             if ( *old_corr < 0.6f || (float) pitch0 > (float) *old_pitch * 0.4f )
     801             :             {
     802             :                 /* reinforce the normalized correlation */
     803    77552651 :                 *corr *= *fac;
     804             :             }
     805    82526072 :             *fac *= THRES0;
     806             :         }
     807   299695237 :         pit_min = pit_min + pitch0; /* next multiple */
     808   299695237 :         delta += step;              /* add the incertitude to the allowed range */
     809             :     }
     810   250819926 :     return;
     811             : }
     812             : 
     813             : /*---------------------------------------------------------------------------*
     814             :  * pitch_neighbour
     815             :  *
     816             :  * Verifies if the maximum correlation pitch lag is coherent with neighbour
     817             :  * values
     818             :  *---------------------------------------------------------------------------*/
     819    16218896 : static void pitch_neighbour(
     820             :     const int16_t sect0,            /* i  : indicates whether section 0 (below PIT_MIN) is used     */
     821             :     const int16_t pitch_tmp[],      /* i  : estimated pitch values for each half-frame & look-ahead */
     822             :     int16_t pitch[NHFR][2 * NSECT], /* i  : tested pitch values for each half-frame & look-ahead    */
     823             :     const float corr_tmp[],         /* i  : raw normalized correlation (before different scalings)  */
     824             :     float corr[NHFR][2 * NSECT],    /* i/o: normalized correlation for each half-frame & look-ahead */
     825             :     const float thres1[2 * NHFR],   /* i  : maximum scaling for the immediate neighbours            */
     826             :     const int16_t ind_tmp[2 * NHFR] /* i  : maximum section indices                                 */
     827             : )
     828             : {
     829             :     int16_t delta, i, j, k, K, coh_flag;
     830             : 
     831    74241113 :     for ( k = sect0; k < NSECT; k++ ) /* loop for each section */
     832             :     {
     833    58022217 :         if ( k == ( NSECT - 1 ) )
     834             :         {
     835    16218896 :             K = 2; /* the number of tests depends on the section */
     836             :         }
     837             :         else
     838             :         {
     839    41803321 :             K = 3;
     840             :         }
     841   215869972 :         for ( i = 0; i < K; i++ ) /* loop for the 2 half-frames and the look-ahead  */
     842             :         {
     843             :             /* Compare pitch values of the present frame */
     844   598953228 :             for ( j = 0; j < K; j++ ) /* Verify pitch coherence with neighbours (including past pitch) */
     845             :             {
     846   441105473 :                 if ( j != i ) /* Exclude itself */
     847             :                 {
     848   283257718 :                     if ( corr_tmp[j] >= CORR_TH1 ) /* reinforcement can happen only if the correlation is high enough */
     849             :                     {
     850   176884491 :                         delta = (int16_t) abs( pitch[i][k] - pitch_tmp[j] ); /* Find difference of pitch values  */
     851   176884491 :                         coh_flag = pitch_coherence( (int16_t) pitch[i][k], (int16_t) pitch_tmp[j], COH_FAC, DELTA_COH );
     852   176884491 :                         if ( coh_flag != 0 )
     853             :                         {
     854             :                             /* Favour section-wise stability */
     855    63214880 :                             if ( ind_tmp[j] == k )
     856             :                             {
     857    47695637 :                                 corr[i][k] *= ( -thres1[j] / DELTA_COH * delta + thres1[j] + 1.0f ); /* Favour closer values */
     858             :                             }
     859             :                             else
     860             :                             {
     861    15519243 :                                 corr[i][k] *= ( -thres1[j] / DELTA_COH * 0.625f * delta + thres1[j] * 0.625f + 1.0f );
     862             :                             }
     863             :                         }
     864             :                     }
     865             :                 }
     866             :             }
     867             :         }
     868             :     }
     869             :     /*---------------------*
     870             :      * 2nd set of sections
     871             :      *---------------------*/
     872    74241113 :     for ( k = sect0; k < NSECT; k++ ) /* loop for each section */
     873             :     {
     874    58022217 :         if ( k == ( NSECT - 1 ) )
     875             :         {
     876    16218896 :             K = 2; /* the number of tests depends on the section */
     877             :         }
     878             :         else
     879             :         {
     880    41803321 :             K = 3;
     881             :         }
     882   215869972 :         for ( i = 0; i < K; i++ ) /* loop for the 2 half-frames and the look-ahead */
     883             :         {
     884             :             /* Compare pitch values of the present frame */
     885   598953228 :             for ( j = 0; j < K; j++ ) /* Verify pitch coherence with neighbours (including past pitch) */
     886             :             {
     887   441105473 :                 if ( j != i ) /* Exclude itself */
     888             :                 {
     889   283257718 :                     if ( corr_tmp[j + NHFR] >= CORR_TH1 ) /* reinforcement can happen only if the correlation is high enough */
     890             :                     {
     891   171220431 :                         delta = (int16_t) abs( pitch[i][NSECT + k] - pitch_tmp[j + NHFR] ); /* Find difference of pitch values */
     892   171220431 :                         coh_flag = pitch_coherence( (int16_t) pitch[i][NSECT + k], (int16_t) pitch_tmp[j + NHFR], COH_FAC, DELTA_COH );
     893   171220431 :                         if ( coh_flag != 0 )
     894             :                         {
     895             :                             /* Favour section-wise stability */
     896    63688093 :                             if ( ind_tmp[j + NHFR] == ( NSECT + k ) )
     897             :                             {
     898    48674296 :                                 corr[i][NSECT + k] *= ( -thres1[j + NHFR] / DELTA_COH * delta + thres1[j + NHFR] + 1.0f ); /* Favour closer values */
     899             :                             }
     900             :                             else
     901             :                             {
     902    15013797 :                                 corr[i][NSECT + k] *= ( -thres1[j + NHFR] / DELTA_COH * 0.625f * delta + thres1[j + NHFR] * 0.625f + 1.0f );
     903             :                             }
     904             :                         }
     905             :                     }
     906             :                 }
     907             :             }
     908             :         }
     909             :     }
     910    16218896 :     return;
     911             : }
     912             : 
     913             : /*-----------------------------------------------------------------*
     914             :  * pitch_coherence
     915             :  *
     916             :  * Verify if pitch evolution is smooth
     917             :  *-----------------------------------------------------------------*/
     918             : 
     919   429199402 : static int16_t pitch_coherence(
     920             :     const int16_t pitch0,  /* i  : first pitch to compare         */
     921             :     const int16_t pitch1,  /* i  : 2nd pitch to compare           */
     922             :     const float fac_max,   /* i  : max ratio of both values       */
     923             :     const int16_t diff_max /* i  : max difference of both values  */
     924             : )
     925             : {
     926             :     int16_t smaller, larger;
     927   429199402 :     if ( pitch1 < pitch0 ) /* Finds smaller and larger of 2 short values */
     928             :     {
     929   176763203 :         smaller = pitch1;
     930   176763203 :         larger = pitch0;
     931             :     }
     932             :     else
     933             :     {
     934   252436199 :         smaller = pitch0;
     935   252436199 :         larger = pitch1;
     936             :     }
     937   429199402 :     if ( ( (float) larger < fac_max * (float) smaller ) && ( ( larger - smaller ) < diff_max ) )
     938             :     {
     939   179274252 :         return 1;
     940             :     }
     941             :     else
     942             :     {
     943   249925150 :         return 0;
     944             :     }
     945             : }
     946             : 
     947             : 
     948             : /*-----------------------------------------------------------------*
     949             :  * lp_decim2:
     950             :  *
     951             :  * Decimate a vector by 2 with 2nd order fir filter.
     952             :  *-----------------------------------------------------------------*/
     953             : 
     954    32437792 : static void lp_decim2(
     955             :     const float x[], /* i  : signal to process         */
     956             :     float y[],       /* o  : processed signals         */
     957             :     const int16_t l, /* i  : size of filtering         */
     958             :     float *mem       /* i/o: memory (size=3)           */
     959             : )
     960             : {
     961             :     const float *p_h;
     962             :     float temp, *p_x, x_buf[L_FRAME_PLUS + L_MEM];
     963             :     int16_t i, j, k;
     964             : 
     965             :     /* copy initial filter states into buffer */
     966    32437792 :     p_x = x_buf;
     967   129751168 :     for ( i = 0; i < L_MEM; i++ )
     968             :     {
     969    97313376 :         *p_x++ = mem[i];
     970             :     }
     971  6000991520 :     for ( i = 0; i < l; i++ )
     972             :     {
     973  5968553728 :         *p_x++ = x[i];
     974             :     }
     975   129751168 :     for ( i = 0; i < L_MEM; i++ )
     976             :     {
     977    97313376 :         mem[i] = x[l - L_MEM + i];
     978             :     }
     979  3016714656 :     for ( i = 0, j = 0; i < l; i += 2, j++ )
     980             :     {
     981  2984276864 :         p_x = &x_buf[i];
     982  2984276864 :         p_h = h_fir;
     983  2984276864 :         temp = 0.0f;
     984             : 
     985 17905661184 :         for ( k = 0; k < L_FIR_PO; k++ )
     986             :         {
     987 14921384320 :             temp += *p_x++ * *p_h++;
     988             :         }
     989  2984276864 :         y[j] = temp;
     990             :     }
     991    32437792 :     return;
     992             : }

Generated by: LCOV version 1.14