LCOV - code coverage report
Current view: top level - lib_enc - vlpc_1st_cod.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 36 36 100.0 %
Date: 2025-05-23 08:37:30 Functions: 2 2 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             : #ifdef DEBUGGING
      40             : #include <assert.h>
      41             : #endif
      42             : #include "cnst.h"
      43             : #include "prot.h"
      44             : #include "rom_com.h"
      45             : #include "wmc_auto.h"
      46             : 
      47             : 
      48             : /*------------------------------------------------------------------*
      49             :  * lsf_weight()
      50             :  *
      51             :  * outputs only the weightings, doesn't do anything with the lsfq
      52             :  *------------------------------------------------------------------*/
      53             : 
      54      108975 : static void lsf_weight(
      55             :     const float *lsfq,
      56             :     float *w,
      57             :     const int32_t sr_core )
      58             : {
      59             :     int16_t i;
      60             :     float inv_di0, inv_di1;
      61      108975 :     float scale = ( (float) sr_core ) / INT_FS_12k8;
      62      108975 :     float freq_max = sr_core / 2.f;
      63             : 
      64             : #ifdef DEBUGGING
      65             :     /* Verify, that M is pair, otherwise adapt exit of loop below */
      66             :     assert( ( M & 1 ) == 0 );
      67             : #endif
      68             : 
      69             :     /* weighting function */
      70      108975 :     inv_di0 = scale / lsfq[0];
      71      871800 :     for ( i = 1; i < ( M - 2 ); i += 2 )
      72             :     {
      73      762825 :         inv_di1 = scale / ( lsfq[i] - lsfq[i - 1] );
      74      762825 :         w[i - 1] = inv_di0 + inv_di1;
      75             : 
      76      762825 :         inv_di0 = scale / ( lsfq[i + 1] - lsfq[i] );
      77      762825 :         w[i] = inv_di1 + inv_di0;
      78             :     }
      79      108975 :     inv_di1 = scale / ( lsfq[i] - lsfq[i - 1] );
      80      108975 :     w[i - 1] = inv_di0 + inv_di1;
      81             : 
      82      108975 :     inv_di0 = scale / ( freq_max - lsfq[i] );
      83      108975 :     w[i] = inv_di1 + inv_di0;
      84             : 
      85      108975 :     return;
      86             : }
      87             : 
      88             : 
      89             : /*------------------------------------------------------------------*
      90             :  * vlpc_1st_cod()
      91             :  *
      92             :  *
      93             :  *------------------------------------------------------------------*/
      94             : 
      95             : /*! r: codebook index */
      96      108975 : int16_t vlpc_1st_cod(
      97             :     const float *lsf,      /* i  : vector to quantize                */
      98             :     float *lsfq,           /* i/o: i:prediction   o:quantized lsf    */
      99             :     const int32_t sr_core, /* i  : internal sampling rate            */
     100             :     float *wout            /* o  : lsf weights                       */
     101             : )
     102             : {
     103             :     int16_t i, j, index;
     104             :     float w[M], x[M];
     105             :     float dist_min, dist, temp;
     106             :     const float *p_dico;
     107             : #ifdef DEBUGGING
     108             :     int16_t hit = 0;
     109             : #endif
     110      108975 :     float scale = ( (float) sr_core ) / INT_FS_12k8;
     111      108975 :     float scaleinv = 1.f / scale;
     112             : 
     113             :     /* weighting */
     114      108975 :     lsf_weight( lsf, w, sr_core );
     115             : 
     116      108975 :     mvr2r( w, wout, M );
     117             : 
     118             :     /* remove lsf prediction/means */
     119             : 
     120     1852575 :     for ( i = 0; i < M; i++ )
     121             :     {
     122     1743600 :         x[i] = ( lsf[i] - lsfq[i] ) * scaleinv;
     123             :     }
     124             : 
     125      108975 :     dist_min = 1.0e30f;
     126      108975 :     p_dico = dico_lsf_abs_8b;
     127      108975 :     index = 0;
     128             : 
     129    28006575 :     for ( i = 0; i < 256; i++ )
     130             :     {
     131    27897600 :         dist = 0.0;
     132             : 
     133   474259200 :         for ( j = 0; j < M; j++ )
     134             :         {
     135   446361600 :             temp = x[j] - *p_dico++;
     136   446361600 :             dist += w[j] * temp * temp;
     137             :         }
     138             : 
     139    27897600 :         if ( dist < dist_min )
     140             :         {
     141      602437 :             dist_min = dist;
     142      602437 :             index = i;
     143             : #ifdef DEBUGGING
     144             :             hit++; /*just for testing*/
     145             : #endif
     146             :         }
     147             :     }
     148             : 
     149             :     /* quantized vector */
     150      108975 :     p_dico = &dico_lsf_abs_8b[index * M];
     151             : 
     152     1852575 :     for ( j = 0; j < M; j++ )
     153             :     {
     154     1743600 :         lsfq[j] += scale * *p_dico++; /* += cause it's differential */
     155             :     }
     156             : 
     157             : #ifdef DEBUGGING
     158             :     assert( index < 256 );
     159             :     assert( hit > 0 );
     160             : #endif
     161             : 
     162      108975 :     return index;
     163             : }

Generated by: LCOV version 1.14