LCOV - code coverage report
Current view: top level - lib_enc - long_enr.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 34 35 97.1 %
Date: 2025-05-23 08:37:30 Functions: 1 1 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 "debug.h"
      41             : #endif
      42             : #include "cnst.h"
      43             : #include "prot.h"
      44             : #include "wmc_auto.h"
      45             : 
      46             : /*-------------------------------------------------------------------*
      47             :  * long_enr()
      48             :  *
      49             :  * Compute relative energy, long-term average total noise energy and total active speech energy
      50             :  *-------------------------------------------------------------------*/
      51             : 
      52     1185802 : void long_enr(
      53             :     Encoder_State *st,                  /* i/o: encoder state structure                  */
      54             :     const float Etot,                   /* i  : total channel energy                     */
      55             :     const int16_t localVAD_HE_SAD,      /* i  : HE-SAD flag without hangover             */
      56             :     const int16_t high_lpn_flag,        /* i  : sp/mus LPN flag                          */
      57             :     FRONT_VAD_ENC_HANDLE hFrontVad[],   /* i/o: front-VAD handles                        */
      58             :     const int16_t n_chan,               /* i  : number of channels                       */
      59             :     const int16_t localVAD_HE_SAD_LR[], /* i  : HE-SAD flag without hangover LR channels */
      60             :     const float Etot_LR[]               /* i  : total channel energy LR channels         */
      61             : )
      62             : {
      63             :     float tmp;
      64             :     int16_t n;
      65             : 
      66             :     /*-----------------------------------------------------------------*
      67             :      * Compute long term estimate of total noise energy
      68             :      * and total active speech energy
      69             :      *-----------------------------------------------------------------*/
      70             : 
      71     1185802 :     if ( hFrontVad != NULL )
      72             :     {
      73       49758 :         if ( hFrontVad[0]->ini_frame < 4 )
      74             :         {
      75        1644 :             for ( n = 0; n < n_chan; n++ )
      76             :             {
      77        1004 :                 hFrontVad[n]->lp_noise = hFrontVad[n]->hNoiseEst->totalNoise;
      78        1004 :                 tmp = hFrontVad[n]->lp_noise + 10.0f;
      79             : 
      80        1004 :                 if ( hFrontVad[n]->lp_speech < tmp )
      81             :                 {
      82           0 :                     hFrontVad[n]->lp_speech = tmp;
      83             :                 }
      84             :             }
      85             :         }
      86             :         else
      87             :         {
      88             :             float smooth_prev, smooth_curr;
      89             : 
      90       49118 :             if ( hFrontVad[0]->ini_frame < 150 )
      91             :             {
      92       15270 :                 smooth_prev = 0.95f;
      93       15270 :                 smooth_curr = 0.05f;
      94             :             }
      95             :             else
      96             :             {
      97       33848 :                 smooth_prev = 0.98f;
      98       33848 :                 smooth_curr = 0.02f;
      99             :             }
     100             : 
     101      129840 :             for ( n = 0; n < n_chan; n++ )
     102             :             {
     103       80722 :                 hFrontVad[n]->lp_noise = smooth_prev * hFrontVad[n]->lp_noise + smooth_curr * hFrontVad[n]->hNoiseEst->totalNoise;
     104             : 
     105       80722 :                 if ( localVAD_HE_SAD_LR[n] && !high_lpn_flag )
     106             :                 {
     107       35395 :                     if ( ( hFrontVad[n]->lp_speech - Etot_LR[n] ) < 10.0f )
     108             :                     {
     109       24245 :                         hFrontVad[n]->lp_speech = 0.98f * hFrontVad[n]->lp_speech + 0.02f * Etot_LR[n];
     110             :                     }
     111             :                     else
     112             :                     {
     113       11150 :                         hFrontVad[n]->lp_speech = hFrontVad[n]->lp_speech - 0.05f;
     114             :                     }
     115             :                 }
     116             :             }
     117             :         }
     118             : 
     119             :         /* Update */
     120      131484 :         for ( n = 0; n < n_chan; n++ )
     121             :         {
     122       81726 :             hFrontVad[n]->hNoiseEst->Etot_last = Etot_LR[n];
     123             :         }
     124             :     }
     125             :     else
     126             :     {
     127     1136044 :         if ( st->ini_frame < 4 )
     128             :         {
     129       34187 :             st->lp_noise = st->hNoiseEst->totalNoise;
     130       34187 :             tmp = st->lp_noise + 10.0f;
     131             : 
     132       34187 :             if ( st->lp_speech < tmp )
     133             :             {
     134           6 :                 st->lp_speech = tmp;
     135             :             }
     136             :         }
     137             :         else
     138             :         {
     139     1101857 :             if ( st->ini_frame < 150 )
     140             :             {
     141      313037 :                 st->lp_noise = 0.95f * st->lp_noise + 0.05f * st->hNoiseEst->totalNoise;
     142             :             }
     143             :             else
     144             :             {
     145      788820 :                 st->lp_noise = 0.98f * st->lp_noise + 0.02f * st->hNoiseEst->totalNoise;
     146             :             }
     147             : 
     148     1101857 :             if ( localVAD_HE_SAD && !high_lpn_flag )
     149             :             {
     150      842463 :                 if ( ( st->lp_speech - Etot ) < 10.0f )
     151             :                 {
     152      655845 :                     st->lp_speech = 0.98f * st->lp_speech + 0.02f * Etot;
     153             :                 }
     154             :                 else
     155             :                 {
     156      186618 :                     st->lp_speech = st->lp_speech - 0.05f;
     157             :                 }
     158             :             }
     159             :         }
     160             : 
     161             :         /* Update */
     162     1136044 :         st->hNoiseEst->Etot_last = Etot;
     163             :     }
     164             : 
     165     1185802 :     return;
     166             : }

Generated by: LCOV version 1.14