LCOV - code coverage report
Current view: top level - lib_com - guided_plc_util.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 44 77 57.1 %
Date: 2025-05-23 08:37:30 Functions: 5 6 83.3 %

          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 "prot.h"
      40             : #include "rom_com.h"
      41             : #include "wmc_auto.h"
      42             : 
      43             : /*-------------------------------------------------------------------*
      44             :  * Local function prototypes
      45             :  *-------------------------------------------------------------------*/
      46             : 
      47             : static void reorder_lsfs( float *lsf, float min_dist, const int16_t n, const int32_t sr_core );
      48             : 
      49             : 
      50             : /*-------------------------------------------------------------------*
      51             :  * getLookAheadResSig()
      52             :  *
      53             :  *
      54             :  *-------------------------------------------------------------------*/
      55             : 
      56         315 : void getLookAheadResSig(
      57             :     float *speechLookAhead,
      58             :     const float *A,
      59             :     float *res,
      60             :     const int16_t L_frame,
      61             :     const int16_t L_subfr,
      62             :     const int16_t m,
      63             :     const int16_t numSubFrame )
      64             : {
      65             :     const float *p_A;
      66             :     int16_t i_subfr;
      67             :     int16_t subfr_len[2];
      68             : 
      69         315 :     subfr_len[0] = L_subfr;
      70         315 :     subfr_len[1] = L_frame < L_FRAME16k ? (int16_t) ( 0.75 * L_subfr ) : L_subfr;
      71             : 
      72         315 :     p_A = A;
      73         945 :     for ( i_subfr = 0; i_subfr < numSubFrame * L_subfr; i_subfr += L_subfr )
      74             :     {
      75         630 :         residu( p_A, m, &speechLookAhead[i_subfr], &res[i_subfr], subfr_len[i_subfr / L_subfr] );
      76         630 :         p_A += ( m + 1 );
      77             :     }
      78             : 
      79         315 :     return;
      80             : }
      81             : 
      82             : /*-------------------------------------------------------------------*
      83             :  * updatelsfForConcealment()
      84             :  *
      85             :  *
      86             :  *-------------------------------------------------------------------*/
      87             : 
      88        1250 : void updatelsfForConcealment(
      89             :     PLC_ENC_EVS_HANDLE decState,
      90             :     float *lsf )
      91             : {
      92             :     int16_t i;
      93             : 
      94       21250 :     for ( i = 0; i < M; i++ )
      95             :     {
      96       20000 :         decState->lsf_adaptive_mean[i] = ( decState->lsfoldbfi1[i] + decState->lsfoldbfi0[i] + lsf[i] ) / 3;
      97       20000 :         decState->lsfoldbfi1[i] = decState->lsfoldbfi0[i];
      98       20000 :         decState->lsfoldbfi0[i] = lsf[i];
      99             :     }
     100             : 
     101        1250 :     return;
     102             : }
     103             : 
     104             : 
     105             : /*-------------------------------------------------------------------*
     106             :  * getConcealedLP()
     107             :  *
     108             :  *
     109             :  *-------------------------------------------------------------------*/
     110             : 
     111         315 : void getConcealedLP(
     112             :     PLC_ENC_EVS_HANDLE memDecState,
     113             :     float *AqCon,
     114             :     const float lsfBase[],
     115             :     const int32_t sr_core,
     116             :     const int16_t last_good,
     117             :     const int16_t L_frame )
     118             : {
     119         315 :     float *lsf = memDecState->lsf_con;
     120             :     float lsp[( NB_DIV + 1 ) * M];
     121             :     int16_t k;
     122             : 
     123         315 :     dlpc_bfi( L_frame, &lsf[0], memDecState->lsfold, last_good, 1 /* assumes packet loss */, memDecState->mem_MA, memDecState->mem_AR, &( memDecState->stab_fac ), memDecState->lsf_adaptive_mean, 1, NULL, 0, NULL, NULL, lsfBase );
     124             : 
     125         315 :     mvr2r( memDecState->lspold, lsp, M );
     126             : 
     127         630 :     for ( k = 0; k < 1; k++ )
     128             :     {
     129         315 :         lsf2lsp( &lsf[k * M], &lsp[( k + 1 ) * M], M, sr_core );
     130             :     }
     131             : 
     132         315 :     int_lsp( L_FRAME, &lsp[0], &lsp[M], AqCon, M, interpol_frac_12k8, 0 );
     133             : 
     134         315 :     return;
     135             : }
     136             : 
     137             : /*-------------------------------------------------------------------*
     138             :  * RecLpcSpecPowDiffuseLc()
     139             :  *
     140             :  *
     141             :  *-------------------------------------------------------------------*/
     142             : 
     143          75 : void RecLpcSpecPowDiffuseLc(
     144             :     float *lspq,
     145             :     float *lsp_old,
     146             :     float *lsfq,
     147             :     Decoder_State *st,
     148             :     const int16_t reset_q )
     149             : {
     150             :     const float *means;
     151             :     float lsf_old[M];
     152             :     int16_t i;
     153             : 
     154          75 :     means = PlcGetlsfBase( st->lpcQuantization, st->narrowBand, st->sr_core );
     155             : 
     156          75 :     mvr2r( st->lsf_old, lsf_old, M );
     157             : 
     158          75 :     modify_lsf( lsf_old, M, st->sr_core, reset_q );
     159             : 
     160          75 :     lsf2lsp( lsf_old, lsp_old, M, st->sr_core );
     161             : 
     162          75 :     if ( reset_q )
     163             :     {
     164           0 :         for ( i = 0; i < M; i++ )
     165             :         {
     166           0 :             lsfq[i] = st->mem_MA[i] + means[i];
     167             :         }
     168             : 
     169           0 :         v_sort( lsfq, 0, M - 1 );
     170             : 
     171           0 :         reorder_lsfs( lsfq, LSF_GAP, M, st->sr_core );
     172             : 
     173           0 :         lsf2lsp( lsfq, lspq, M, st->sr_core );
     174             :     }
     175             :     else
     176             :     {
     177          75 :         modify_lsf( lsfq, M, st->sr_core, reset_q );
     178             : 
     179          75 :         lsf2lsp( lsfq, lspq, M, st->sr_core );
     180             :     }
     181             : 
     182             : 
     183          75 :     return;
     184             : }
     185             : 
     186             : 
     187             : /*-------------------------------------------------------------------*
     188             :  * modify_lsf()
     189             :  *
     190             :  *
     191             :  *-------------------------------------------------------------------*/
     192             : 
     193         754 : void modify_lsf(
     194             :     float *lsf,
     195             :     const int16_t n,
     196             :     const int32_t sr_core,
     197             :     const int16_t reset_q )
     198             : {
     199             :     int16_t i, k;
     200             :     float gap;
     201             :     float th;
     202             : 
     203         754 :     th = 1900;
     204             : 
     205         754 :     if ( reset_q == 0 )
     206             :     {
     207         150 :         th = 800;
     208             :     }
     209             : 
     210         754 :     if ( sr_core == INT_FS_16k )
     211             :     {
     212         754 :         th *= 1.25;
     213             :     }
     214             : 
     215             : 
     216         754 :     i = 1;
     217             : 
     218        3385 :     while ( lsf[i] < th && i < n )
     219             :     {
     220        2631 :         i++;
     221             :     }
     222         754 :     gap = lsf[i - 1] / i;
     223             : 
     224        3385 :     for ( k = 0; k < i - 1; k++ )
     225             :     {
     226        2631 :         lsf[k] = gap * ( k + 1 );
     227             :     }
     228             : 
     229         754 :     return;
     230             : }
     231             : 
     232             : 
     233             : /*-------------------------------------------------------------------*
     234             :  * reorder_lsfs()
     235             :  *
     236             :  *
     237             :  *-------------------------------------------------------------------*/
     238             : 
     239           0 : static void reorder_lsfs(
     240             :     float *lsf,      /* i/o: vector of lsfs in the frequency domain (0..0.5)*/
     241             :     float min_dist,  /* i  : minimum required distance */
     242             :     const int16_t n, /* i  : LPC order                 */
     243             :     const int32_t sr_core )
     244             : {
     245             :     int16_t i;
     246             :     float lsf_min;
     247             :     float lsf_max;
     248             :     float fac;
     249             :     float th1, th2;
     250             : 
     251           0 :     th1 = 1000.0f;
     252           0 :     th2 = 1900.0f;
     253             : 
     254           0 :     if ( sr_core == INT_FS_16k )
     255             :     {
     256           0 :         min_dist *= 1.25;
     257           0 :         th1 *= 1.25;
     258           0 :         th2 *= 1.25;
     259             :     }
     260             : 
     261             :     /*-----------------------------------------------------------------*
     262             :      * Verify the LSF ordering and minimum GAP
     263             :      *-----------------------------------------------------------------*/
     264           0 :     fac = 3.0;
     265             : 
     266           0 :     lsf_min = min_dist * fac;
     267           0 :     for ( i = 0; i < n; i++ )
     268             :     {
     269             : 
     270           0 :         if ( lsf[i] > th1 )
     271             :         {
     272           0 :             fac = 2.0;
     273             :         }
     274             :         else
     275             :         {
     276           0 :             if ( lsf[i] > 1900.0 )
     277             :             {
     278           0 :                 fac = 1.0;
     279             :             }
     280             :         }
     281             : 
     282           0 :         if ( lsf[i] < lsf_min )
     283             :         {
     284           0 :             lsf[i] = lsf_min;
     285             :         }
     286             : 
     287           0 :         lsf_min = lsf[i] + min_dist * fac;
     288             :     }
     289             : 
     290             :     /*------------------------------------------------------------------------------------------*
     291             :      * Reverify the LSF ordering and minimum GAP in the reverse order (security)
     292             :      *------------------------------------------------------------------------------------------*/
     293             : 
     294           0 :     lsf_max = (float) ( sr_core ) / 2.0f - min_dist * fac;
     295             : 
     296           0 :     if ( lsf[n - 1] > lsf_max ) /* If danger of unstable filter in case of resonance in HF */
     297             :     {
     298           0 :         for ( i = n - 1; i >= 0; i-- ) /* Reverify the minimum LSF gap in the reverse sens */
     299             :         {
     300             : 
     301           0 :             if ( lsf[i] <= th2 )
     302             :             {
     303           0 :                 fac = 2.0;
     304             :             }
     305             :             else
     306             :             {
     307           0 :                 if ( lsf[i] <= th1 )
     308             :                 {
     309           0 :                     fac = 3.0;
     310             :                 }
     311             :             }
     312             : 
     313           0 :             if ( lsf[i] > lsf_max )
     314             :             {
     315           0 :                 lsf[i] = lsf_max;
     316             :             }
     317             : 
     318           0 :             lsf_max = lsf[i] - min_dist * fac;
     319             :         }
     320             :     }
     321             : 
     322           0 :     return;
     323             : }

Generated by: LCOV version 1.14