LCOV - code coverage report
Current view: top level - lib_com - basop_com_lpc.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 60 73 82.2 %
Date: 2025-05-03 01:55:50 Functions: 3 5 60.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 <assert.h>
      38             : #include <stdint.h>
      39             : #include "options.h"
      40             : #include "typedef.h"
      41             : #include "basop_proto_func.h"
      42             : #include "cnst.h"
      43             : #include "basop_util.h"
      44             : #include "stl.h"
      45             : 
      46             : #define WMC_TOOL_SKIP
      47             : 
      48             : #define UNROLL_CHEBYSHEV_INNER_LOOP
      49             : #define NC_MAX       8
      50             : #define GUESS_TBL_SZ 256
      51             : 
      52             : #define Madd_32_16( accu, x, y ) L_add( accu, Mpy_32_16_1( x, y ) )
      53             : #define Msub_32_16( accu, x, y ) L_sub( accu, Mpy_32_16_1( x, y ) )
      54             : 
      55             : 
      56             : /*
      57             :  * weight_a
      58             :  *
      59             :  * Parameters:
      60             :  *    a              I: LP filter coefficients          Q12
      61             :  *    ap             O: weighted LP filter coefficients Q12
      62             :  *    gamma          I: weighting factor                Q15
      63             :  *
      64             :  * Function:
      65             :  *    Weighting of LP filter coefficients, ap[i] = a[i] * (gamma^i).
      66             :  *
      67             :  * Returns:
      68             :  *    void
      69             :  */
      70      354079 : void basop_weight_a(
      71             :     const Word16 *a,   /* Q12 */
      72             :     Word16 *ap,        /* Q12 */
      73             :     const Word16 gamma /* Q15 */
      74             : )
      75             : {
      76             :     Word16 i, fac;
      77             :     Word32 Amax;
      78             :     Word16 shift;
      79             : 
      80             : 
      81      354079 :     fac = gamma;                  /* Q15 */
      82      354079 :     Amax = L_mult( 16384, a[0] ); /* Q27 */
      83     5665264 :     FOR( i = 1; i < M; i++ )
      84             :     {
      85     5311185 :         Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) );
      86     5311185 :         fac = mult_r( fac, gamma ); /* Q15 */
      87             :     }
      88      354079 :     Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) ); /* Q27 */
      89      354079 :     shift = norm_l( Amax );
      90      354079 :     fac = gamma;
      91      354079 :     ap[0] = shl( a[0], sub( shift, 1 ) );
      92      354079 :     move16();
      93     5665264 :     FOR( i = 1; i < M; i++ )
      94             :     {
      95     5311185 :         ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) ); /* Q12 */
      96     5311185 :         move16();
      97     5311185 :         fac = mult_r( fac, gamma ); /* Q15 */
      98             :     }
      99      354079 :     ap[M] = round_fx( L_shl( L_mult0( a[M], fac ), shift ) ); /* Q12 */
     100      354079 :     move16();
     101             : 
     102             : 
     103      354079 :     return;
     104             : }
     105             : 
     106             : /*
     107             :  * weight_a_inv
     108             :  *
     109             :  * Parameters:
     110             :  *    a              I: LP filter coefficients          Q12
     111             :  *    ap             O: weighted LP filter coefficients Q12
     112             :  *    inv_gamma      I: inverse weighting factor        Q14
     113             :  *
     114             :  * Function:
     115             :  *    Weighting of LP filter coefficients, ap[i] = a[i] * (inv_gamma^i).
     116             :  *
     117             :  * Returns:
     118             :  *    void
     119             :  */
     120       13989 : void basop_weight_a_inv(
     121             :     const Word16 *a,       /* Q12 */
     122             :     Word16 *ap,            /* Q12 */
     123             :     const Word16 inv_gamma /* Q14 */
     124             : )
     125             : {
     126             :     Word16 i;
     127             :     static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924,   /* Q14 */
     128             :                                                    17350, 18859, 20499, 22281, 24219, 26325, 28614, 31102 }; /* Q13 */
     129             :     static const Word16 inv_gamma_tab_16k[16] = { 17430, 18542, 19726, 20985, 22324, 23749, 25265, 26878,    /* Q14 */
     130             :                                                   14297, 15209, 16180, 17213, 18312, 19480, 20724, 22047 };  /* Q13 */
     131             :     const Word16 *inv_gamma_tab;
     132             :     Word32 L_tmp;
     133             :     Word32 Amax;
     134             :     Word16 shift;
     135             : 
     136             : 
     137       13989 :     IF( inv_gamma == 16384 )
     138             :     {
     139           0 :         FOR( i = 0; i <= M; i++ )
     140             :         {
     141           0 :             ap[i] = a[i]; /* Q12 */
     142           0 :             move16();
     143             :         }
     144           0 :         return;
     145             :     }
     146             : 
     147       13989 :     assert( inv_gamma == GAMMA1_INV || inv_gamma == GAMMA16k_INV );
     148             : 
     149       13989 :     inv_gamma_tab = inv_gamma_tab_12k8; /* Q14 */
     150       13989 :     move16();
     151       13989 :     if ( sub( inv_gamma, GAMMA16k_INV ) == 0 )
     152             :     {
     153           0 :         inv_gamma_tab = inv_gamma_tab_16k; /* Q14 */
     154           0 :         move16();
     155             :     }
     156             : 
     157       13989 :     Amax = L_mult( 16384, a[0] );
     158      125901 :     FOR( i = 1; i < 9; i++ )
     159             :     {
     160      111912 :         Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) ); /* Q27 */
     161             :     }
     162      125901 :     FOR( i = 9; i < 17; i++ )
     163             :     {
     164      111912 :         Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) ); /* Q27 */
     165             :     }
     166       13989 :     shift = norm_l( Amax );
     167       13989 :     ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */
     168       13989 :     move16();
     169      125901 :     FOR( i = 1; i < 9; i++ )
     170             :     {
     171      111912 :         L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */
     172      111912 :         ap[i] = round_fx( L_shl( L_tmp, shift ) );    /* Q11 + shift */
     173      111912 :         move16();
     174             :     }
     175       13989 :     shift = add( shift, 1 );
     176      125901 :     FOR( i = 9; i < 17; i++ )
     177             :     {
     178      111912 :         L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] ); /* Q27 */
     179      111912 :         ap[i] = round_fx( L_shl( L_tmp, shift ) );    /* Q11 + shift */
     180      111912 :         move16();
     181             :     }
     182             : 
     183             : 
     184       13989 :     return;
     185             : }
     186             : 
     187             : /*
     188             :  * basop_E_LPC_a_add_tilt
     189             :  *
     190             :  * Parameters:
     191             :  *    a              I: LP filter coefficients (m+1 coeffs)
     192             :  *    ap             O: modified LP filter coefficients (m+2 coeffs)
     193             :  *    gamma          I: tilt factor
     194             :  *
     195             :  * Function:
     196             :  *    Modified LP filter by adding 1st order pre-premphasis, Ap(z)=A(z).(1-gamma.z^(-1))
     197             :  *
     198             :  * Returns:
     199             :  *    void
     200             :  */
     201       13989 : void basop_E_LPC_a_add_tilt(
     202             :     const Word16 *a, /* Q12 */
     203             :     Word16 *ap,      /* Q12 */
     204             :     Word16 gamma     /* Q15 */
     205             : )
     206             : {
     207             :     Word16 i;
     208             :     Word32 Amax, Atmp[M + 2];
     209             :     Word16 shift;
     210             : 
     211             : 
     212       13989 :     Amax = L_mult( 16384, a[0] ); /* Q27 */
     213      237813 :     FOR( i = 1; i <= M; i++ )
     214             :     {
     215      223824 :         Atmp[i] = L_sub( L_mult( 16384, a[i] ), L_mult0( gamma, a[i - 1] ) ); /* Q27 */
     216      223824 :         move32();
     217      223824 :         Amax = L_max( Amax, L_abs( Atmp[i] ) ); /* Q27 */
     218             :     }
     219       13989 :     Atmp[M + 1] = L_negate( L_mult0( gamma, a[M] ) ); /* Q27 */
     220       13989 :     move32();
     221       13989 :     Amax = L_max( Amax, L_abs( Atmp[M + 1] ) ); /* Q27 */
     222       13989 :     shift = norm_l( Amax );
     223       13989 :     ap[0] = shl( a[0], sub( shift, 1 ) ); /* Q11 + shift */
     224       13989 :     move16();
     225      237813 :     FOR( i = 1; i <= M; i++ )
     226             :     {
     227      223824 :         ap[i] = round_fx( L_shl( Atmp[i], shift ) ); /* Q11 + shift */
     228      223824 :         move16();
     229             :     }
     230       13989 :     ap[M + 1] = round_fx( L_shl( Atmp[M + 1], shift ) ); /* Q12 */
     231       13989 :     move16();
     232             : 
     233       13989 :     return;
     234             : }
     235             : 
     236             : 
     237           0 : static Word16 xsf_to_xsp(
     238             :     Word16 xsf /* Q2.56 */
     239             : )
     240             : {
     241             :     /* xsp = cos(xsf * 3.1415/6400); */
     242           0 :     return getCosWord16R2( xsf );
     243             : }
     244             : 
     245             : /*
     246             :  * lsf2lsp
     247             :  *
     248             :  * Parameters:
     249             :  *    lsf            I: lsf[m] normalized (range: 0 <= val <= 0.5)   x2.56
     250             :  *    lsp            O: lsp[m] (range: -1 <= val < 1)                Q15
     251             :  *
     252             :  * Function:
     253             :  *    Transformation lsf to lsp
     254             :  *
     255             :  *    LSF are line spectral pair in frequency domain (0 to 6400).
     256             :  *    LSP are line spectral pair in cosine domain (-1 to 1).
     257             :  *
     258             :  * Returns:
     259             :  *    void
     260             :  */
     261           0 : void basop_lsf2lsp(
     262             :     const Word16 lsf[], /* Q2.56 */
     263             :     Word16 lsp[]        /* Q15 */
     264             : )
     265             : {
     266             :     Word16 i;
     267             : 
     268             : 
     269             :     /* convert ISFs to the cosine domain */
     270           0 :     FOR( i = 0; i < M; i++ )
     271             :     {
     272           0 :         *lsp++ = xsf_to_xsp( *lsf++ ); /* Q15 */
     273           0 :         move16();
     274             :     }
     275             : 
     276             : 
     277           0 :     return;
     278             : }
     279             : 
     280             : #undef WMC_TOOL_SKIP

Generated by: LCOV version 1.14