LCOV - code coverage report
Current view: top level - lib_com - basop_com_lpc.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 67 73 91.8 %
Date: 2025-05-23 08:37:30 Functions: 5 5 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 <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( x, y ) )
      53             : #define Msub_32_16( accu, x, y ) L_sub( accu, Mpy_32_16( 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       68415 : void basop_weight_a( const Word16 *a, Word16 *ap, const Word16 gamma )
      71             : {
      72             :     Word16 i, fac;
      73             :     Word32 Amax;
      74             :     Word16 shift;
      75             : 
      76             : 
      77       68415 :     fac = gamma;
      78       68415 :     Amax = L_mult( 16384, a[0] );
      79     1094640 :     FOR( i = 1; i < M; i++ )
      80             :     {
      81     1026225 :         Amax = L_max( Amax, L_abs( L_mult0( fac, a[i] ) ) );
      82     1026225 :         fac = mult_r( fac, gamma );
      83             :     }
      84       68415 :     Amax = L_max( Amax, L_abs( L_mult0( fac, a[M] ) ) );
      85       68415 :     shift = norm_l( Amax );
      86       68415 :     fac = gamma;
      87       68415 :     ap[0] = shl( a[0], sub( shift, 1 ) );
      88       68415 :     move16();
      89     1094640 :     FOR( i = 1; i < M; i++ )
      90             :     {
      91     1026225 :         ap[i] = round_fx( L_shl( L_mult0( a[i], fac ), shift ) );
      92     1026225 :         move16();
      93     1026225 :         fac = mult_r( fac, gamma );
      94             :     }
      95       68415 :     ap[M] = round_fx( L_shl( L_mult0( a[M], fac ), shift ) );
      96       68415 :     move16();
      97             : 
      98             : 
      99       68415 :     return;
     100             : }
     101             : 
     102             : /*
     103             :  * weight_a_inv
     104             :  *
     105             :  * Parameters:
     106             :  *    a              I: LP filter coefficients          Q12
     107             :  *    ap             O: weighted LP filter coefficients Q12
     108             :  *    inv_gamma      I: inverse weighting factor        Q14
     109             :  *
     110             :  * Function:
     111             :  *    Weighting of LP filter coefficients, ap[i] = a[i] * (inv_gamma^i).
     112             :  *
     113             :  * Returns:
     114             :  *    void
     115             :  */
     116       68415 : void basop_weight_a_inv( const Word16 *a, Word16 *ap, const Word16 inv_gamma )
     117             : {
     118             :     Word16 i;
     119             :     static const Word16 inv_gamma_tab_12k8[16] = { 17809, 19357, 21041, 22870, 24859, 27020, 29370, 31924,   /* Q14 */
     120             :                                                    17350, 18859, 20499, 22281, 24219, 26325, 28614, 31102 }; /* Q13 */
     121             :     static const Word16 inv_gamma_tab_16k[16] = { 17430, 18542, 19726, 20985, 22324, 23749, 25265, 26878,    /* Q14 */
     122             :                                                   14297, 15209, 16180, 17213, 18312, 19480, 20724, 22047 };  /* Q13 */
     123             :     const Word16 *inv_gamma_tab;
     124             :     Word32 L_tmp;
     125             :     Word32 Amax;
     126             :     Word16 shift;
     127             : 
     128             : 
     129       68415 :     IF( inv_gamma == 16384 )
     130             :     {
     131           0 :         FOR( i = 0; i <= M; i++ )
     132             :         {
     133           0 :             ap[i] = a[i];
     134           0 :             move16();
     135             :         }
     136           0 :         return;
     137             :     }
     138             : 
     139       68415 :     assert( inv_gamma == GAMMA1_INV || inv_gamma == GAMMA16k_INV );
     140             : 
     141       68415 :     inv_gamma_tab = inv_gamma_tab_12k8;
     142       68415 :     move16();
     143       68415 :     if ( sub( inv_gamma, GAMMA16k_INV ) == 0 )
     144             :     {
     145           0 :         inv_gamma_tab = inv_gamma_tab_16k;
     146           0 :         move16();
     147             :     }
     148             : 
     149       68415 :     Amax = L_mult( 16384, a[0] );
     150      615735 :     FOR( i = 1; i < 9; i++ )
     151             :     {
     152      547320 :         Amax = L_max( Amax, L_abs( L_mult( a[i], inv_gamma_tab[i - 1] ) ) );
     153             :     }
     154      615735 :     FOR( i = 9; i < 17; i++ )
     155             :     {
     156      547320 :         Amax = L_max( Amax, L_abs( L_shl( L_mult( a[i], inv_gamma_tab[i - 1] ), 1 ) ) );
     157             :     }
     158       68415 :     shift = norm_l( Amax );
     159       68415 :     ap[0] = shl( a[0], sub( shift, 1 ) );
     160       68415 :     move16();
     161      615735 :     FOR( i = 1; i < 9; i++ )
     162             :     {
     163      547320 :         L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] );
     164      547320 :         ap[i] = round_fx( L_shl( L_tmp, shift ) );
     165      547320 :         move16();
     166             :     }
     167       68415 :     shift = add( shift, 1 );
     168      615735 :     FOR( i = 9; i < 17; i++ )
     169             :     {
     170      547320 :         L_tmp = L_mult( a[i], inv_gamma_tab[i - 1] );
     171      547320 :         ap[i] = round_fx( L_shl( L_tmp, shift ) );
     172      547320 :         move16();
     173             :     }
     174             : 
     175             : 
     176       68415 :     return;
     177             : }
     178             : 
     179             : /*
     180             :  * basop_E_LPC_a_add_tilt
     181             :  *
     182             :  * Parameters:
     183             :  *    a              I: LP filter coefficients (m+1 coeffs)
     184             :  *    ap             O: modified LP filter coefficients (m+2 coeffs)
     185             :  *    gamma          I: tilt factor
     186             :  *
     187             :  * Function:
     188             :  *    Modified LP filter by adding 1st order pre-premphasis, Ap(z)=A(z).(1-gamma.z^(-1))
     189             :  *
     190             :  * Returns:
     191             :  *    void
     192             :  */
     193       68415 : void basop_E_LPC_a_add_tilt( const Word16 *a, Word16 *ap, Word16 gamma )
     194             : {
     195             :     Word16 i;
     196             :     Word32 Amax, Atmp[M + 2];
     197             :     Word16 shift;
     198             : 
     199             : 
     200       68415 :     Amax = L_mult( 16384, a[0] );
     201     1163055 :     FOR( i = 1; i <= M; i++ )
     202             :     {
     203     1094640 :         Atmp[i] = L_sub( L_mult( 16384, a[i] ), L_mult0( gamma, a[i - 1] ) );
     204     1094640 :         move32();
     205     1094640 :         Amax = L_max( Amax, L_abs( Atmp[i] ) );
     206             :     }
     207       68415 :     Atmp[M + 1] = L_negate( L_mult0( gamma, a[M] ) );
     208       68415 :     move32();
     209       68415 :     Amax = L_max( Amax, L_abs( Atmp[M + 1] ) );
     210       68415 :     shift = norm_l( Amax );
     211       68415 :     ap[0] = shl( a[0], sub( shift, 1 ) );
     212       68415 :     move16();
     213     1163055 :     FOR( i = 1; i <= M; i++ )
     214             :     {
     215     1094640 :         ap[i] = round_fx( L_shl( Atmp[i], shift ) );
     216     1094640 :         move16();
     217             :     }
     218       68415 :     ap[M + 1] = round_fx( L_shl( Atmp[M + 1], shift ) );
     219       68415 :     move16();
     220             : 
     221       68415 :     return;
     222             : }
     223             : 
     224             : 
     225     1094640 : static Word16 xsf_to_xsp( Word16 xsf )
     226             : {
     227             :     /* xsp = cos(xsf * 3.1415/6400); */
     228     1094640 :     return getCosWord16R2( xsf );
     229             : }
     230             : 
     231             : /*
     232             :  * lsf2lsp
     233             :  *
     234             :  * Parameters:
     235             :  *    lsf            I: lsf[m] normalized (range: 0 <= val <= 0.5)   x2.56
     236             :  *    lsp            O: lsp[m] (range: -1 <= val < 1)                Q15
     237             :  *
     238             :  * Function:
     239             :  *    Transformation lsf to lsp
     240             :  *
     241             :  *    LSF are line spectral pair in frequency domain (0 to 6400).
     242             :  *    LSP are line spectral pair in cosine domain (-1 to 1).
     243             :  *
     244             :  * Returns:
     245             :  *    void
     246             :  */
     247       68415 : void basop_lsf2lsp( const Word16 lsf[], Word16 lsp[] )
     248             : {
     249             :     Word16 i;
     250             : 
     251             : 
     252             :     /* convert ISFs to the cosine domain */
     253     1163055 :     FOR( i = 0; i < M; i++ )
     254             :     {
     255     1094640 :         *lsp++ = xsf_to_xsp( *lsf++ );
     256     1094640 :         move16();
     257             :     }
     258             : 
     259             : 
     260       68415 :     return;
     261             : }
     262             : 
     263             : #undef WMC_TOOL_SKIP

Generated by: LCOV version 1.14