LCOV - code coverage report
Current view: top level - lib_enc - enc_gain.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 62 84 73.8 %
Date: 2025-05-23 08:37:30 Functions: 2 3 66.7 %

          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 <assert.h>
      38             : #include <stdint.h>
      39             : #include "options.h"
      40             : #include "prot.h"
      41             : #include "rom_enc.h"
      42             : #include "rom_com.h"
      43             : #include "wmc_auto.h"
      44             : 
      45             : 
      46             : /*
      47             :  * E_GAIN_norm_corr_interpolate
      48             :  *
      49             :  * Parameters:
      50             :  *    x           I: input vector
      51             :  *    frac        I: fraction (-4..+3)
      52             :  *
      53             :  * Function:
      54             :  *    Interpolating the normalized correlation
      55             :  *
      56             :  * Returns:
      57             :  *    interpolated value
      58             :  */
      59           0 : static float E_GAIN_norm_corr_interpolate(
      60             :     float *x,
      61             :     int16_t frac )
      62             : {
      63             :     float s, *x1, *x2;
      64             :     const float *c1, *c2;
      65             : 
      66           0 :     if ( frac < 0 )
      67             :     {
      68           0 :         frac += 4;
      69           0 :         x--;
      70             :     }
      71             : 
      72           0 :     x1 = &x[0];
      73           0 :     x2 = &x[1];
      74           0 :     c1 = &E_ROM_inter4_1[frac];
      75           0 :     c2 = &E_ROM_inter4_1[4 - frac];
      76           0 :     s = x1[0] * c1[0] + x2[0] * c2[0];
      77           0 :     s += x1[-1] * c1[4] + x2[1] * c2[4];
      78           0 :     s += x1[-2] * c1[8] + x2[2] * c2[8];
      79           0 :     s += x1[-3] * c1[12] + x2[3] * c2[12];
      80             : 
      81           0 :     return s;
      82             : }
      83             : 
      84       14441 : static float E_GAIN_norm_corr_interpolate6(
      85             :     float *x,
      86             :     int16_t frac )
      87             : {
      88             :     float s, *x1, *x2;
      89             :     const float *c1, *c2;
      90             : 
      91       14441 :     if ( frac < 0 )
      92             :     {
      93        5780 :         frac += 6;
      94        5780 :         x--;
      95             :     }
      96             : 
      97       14441 :     x1 = &x[0];
      98       14441 :     x2 = &x[1];
      99       14441 :     c1 = &E_ROM_inter6_1[frac];
     100       14441 :     c2 = &E_ROM_inter6_1[6 - frac];
     101       14441 :     s = x1[0] * c1[0] + x2[0] * c2[0];
     102       14441 :     s += x1[-1] * c1[6] + x2[1] * c2[6];
     103       14441 :     s += x1[-2] * c1[12] + x2[2] * c2[12];
     104       14441 :     s += x1[-3] * c1[18] + x2[3] * c2[18];
     105             : 
     106       14441 :     return s;
     107             : }
     108             : 
     109             : /*
     110             :  * E_GAIN_closed_loop_search
     111             :  *
     112             :  * Parameters:
     113             :  *    exc            I: excitation buffer
     114             :  *    xn             I: target signal
     115             :  *    h              I: weighted synthesis filter impulse response
     116             :  *    dn             I: residual domain target signal
     117             :  *    t0_min         I: minimum value in the searched range
     118             :  *    t0_max         I: maximum value in the searched range
     119             :  *    pit_frac       O: chosen fraction
     120             :  *    i_subfr        I: flag to first subframe
     121             :  *    t0_fr2         I: minimum value for resolution 1/2
     122             :  *    t0_fr1         I: minimum value for resolution 1
     123             :  *
     124             :  * Function:
     125             :  *    Find the closed loop pitch period with 1/4 subsample resolution.
     126             :  *
     127             :  * Returns:
     128             :  *    chosen integer pitch lag
     129             :  */
     130        3020 : int16_t E_GAIN_closed_loop_search(
     131             :     float exc[],
     132             :     float xn[],
     133             :     float h[],
     134             :     int16_t t0_min,
     135             :     int16_t t0_min_frac,
     136             :     int16_t t0_max,
     137             :     int16_t t0_max_frac,
     138             :     const int16_t t0_min_max_res,
     139             :     int16_t *pit_frac,
     140             :     int16_t *pit_res,
     141             :     const int16_t pit_res_max,
     142             :     const int16_t i_subfr,
     143             :     const int16_t pit_min,
     144             :     const int16_t pit_fr2,
     145             :     const int16_t pit_fr1,
     146             :     const int16_t L_subfr )
     147             : {
     148             :     float corr_v[32 + 2 * L_INTERPOL1 + 1];
     149             :     float cor_max, max_val, temp;
     150             :     float *corr;
     151             :     int16_t i, fraction, frac1, frac2, step;
     152             :     int16_t t0, t_min, t_max;
     153             : 
     154             :     /* Find interval to compute normalized correlation */
     155        3020 :     if ( t0_min_frac > 0 )
     156             :     {
     157        2717 :         t0_min++;
     158             :     }
     159        3020 :     t_min = t0_min - L_INTERPOL1;
     160        3020 :     t_max = t0_max + L_INTERPOL1;
     161             : 
     162             :     /* allocate memory to normalized correlation vector */
     163        3020 :     corr = &corr_v[-t_min]; /* corr[t_min..t_max] */
     164             : 
     165             :     /* Compute normalized correlation between target and filtered excitation */
     166        3020 :     norm_corr( exc, xn, h, t_min, t_max, corr, L_subfr );
     167             : 
     168             :     /*  find integer pitch */
     169        3020 :     max_val = corr[t0_min];
     170        3020 :     t0 = t0_min;
     171       57757 :     for ( i = t0_min + 1; i <= t0_max; i++ )
     172             :     {
     173       54737 :         if ( corr[i] >= max_val )
     174             :         {
     175       20064 :             max_val = corr[i];
     176       20064 :             t0 = i;
     177             :         }
     178             :     }
     179             : 
     180             :     /* If first subframe and t0 >= pit_fr1, do not search fractionnal pitch */
     181        3020 :     if ( ( i_subfr == 0 ) & ( t0 >= pit_fr1 ) )
     182             :     {
     183         108 :         *pit_frac = 0;
     184         108 :         *pit_res = 1;
     185         108 :         return ( t0 );
     186             :     }
     187             : 
     188             :     /*
     189             :      * Search fractionnal pitch
     190             :      * Test the fractions around t0 and choose the one which maximizes
     191             :      * the interpolated normalized correlation.
     192             :      */
     193             : 
     194        2912 :     if ( t0_min_max_res == ( pit_res_max >> 1 ) )
     195             :     {
     196        2912 :         t0_min_frac = t0_min_frac << 1;
     197        2912 :         t0_max_frac = t0_max_frac << 1;
     198             :     }
     199             : 
     200        2912 :     step = 1;
     201        2912 :     frac1 = -( pit_res_max - 1 );
     202        2912 :     frac2 = pit_res_max - 1;
     203        2912 :     if ( ( ( i_subfr == 0 ) & ( t0 >= pit_fr2 ) ) | ( pit_fr2 <= pit_min ) )
     204             :     {
     205        2912 :         step = 2;
     206        2912 :         frac1 = -( pit_res_max - 2 );
     207        2912 :         frac2 = pit_res_max - 2;
     208             :     }
     209             : 
     210        2912 :     if ( ( t0 == t0_min ) && ( t0_min_frac == 0 ) )
     211             :     {
     212          10 :         frac1 = t0_min_frac;
     213             :     }
     214        2902 :     else if ( ( t0 == t0_min ) && ( frac1 + pit_res_max < t0_min_frac ) )
     215             :     {
     216          24 :         frac1 = t0_min_frac - pit_res_max;
     217             :     }
     218        2912 :     if ( t0 == t0_max )
     219             :     {
     220          65 :         frac2 = t0_max_frac;
     221             :     }
     222        2912 :     assert( frac1 <= 0 && frac2 >= 0 && frac2 > frac1 );
     223        2912 :     if ( pit_res_max == 6 )
     224             :     {
     225        2912 :         cor_max = E_GAIN_norm_corr_interpolate6( &corr[t0], frac1 );
     226        2912 :         fraction = frac1;
     227       14441 :         for ( i = ( frac1 + step ); i <= frac2; i += step )
     228             :         {
     229       11529 :             temp = E_GAIN_norm_corr_interpolate6( &corr[t0], i );
     230       11529 :             if ( temp > cor_max )
     231             :             {
     232        5851 :                 cor_max = temp;
     233        5851 :                 fraction = i;
     234             :             }
     235             :         }
     236             :     }
     237             :     else
     238             :     {
     239           0 :         cor_max = E_GAIN_norm_corr_interpolate( &corr[t0], frac1 );
     240           0 :         fraction = frac1;
     241           0 :         for ( i = ( frac1 + step ); i <= frac2; i += step )
     242             :         {
     243           0 :             temp = E_GAIN_norm_corr_interpolate( &corr[t0], i );
     244           0 :             if ( temp > cor_max )
     245             :             {
     246           0 :                 cor_max = temp;
     247           0 :                 fraction = i;
     248             :             }
     249             :         }
     250             :     }
     251             : 
     252             :     /* limit the fraction value */
     253        2912 :     if ( fraction < 0 )
     254             :     {
     255         749 :         fraction += pit_res_max;
     256         749 :         t0 -= 1;
     257             :     }
     258        2912 :     if ( ( ( i_subfr == 0 ) & ( t0 >= pit_fr2 ) ) | ( pit_fr2 <= pit_min ) )
     259             :     {
     260        2912 :         *pit_res = pit_res_max >> 1;
     261        2912 :         *pit_frac = fraction >> 1;
     262             :     }
     263             :     else
     264             :     {
     265           0 :         *pit_res = pit_res_max;
     266           0 :         *pit_frac = fraction;
     267             :     }
     268             : 
     269        2912 :     return ( t0 );
     270             : }

Generated by: LCOV version 1.14