LCOV - code coverage report
Current view: top level - lib_com - gs_preech.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 9 27 33.3 %
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 <math.h>
      43             : #include "cnst.h"
      44             : #include "rom_com.h"
      45             : #include "prot.h"
      46             : #include "wmc_auto.h"
      47             : 
      48             : /*-------------------------------------------------------------------*
      49             :  * Local constants
      50             :  *-------------------------------------------------------------------*/
      51             : 
      52             : #define ATT_LENGHT16k   80
      53             : #define INV_L_FRAME16k  ( 1.0f / L_FRAME16k )
      54             : #define ATT_LENGHT      64
      55             : #define ATT_SEG_LEN     ( L_FRAME / ATT_LENGHT )
      56             : #define INV_ATT_SEG_LEN ( 1.0f / ATT_SEG_LEN )
      57             : #define INV_L_FRAME     ( 1.0f / L_FRAME )
      58             : 
      59             : 
      60             : /*-------------------------------------------------------------------*
      61             :  * pre_echo_att()
      62             :  *
      63             :  * Attenuation of the pre-echo when encoder specifies an attack
      64             :  *-------------------------------------------------------------------*/
      65             : 
      66       90525 : void pre_echo_att(
      67             :     float *Last_frame_ener,        /* i/o: Energy of the last frame         */
      68             :     float *exc,                    /* i/o: Excitation of the current frame  */
      69             :     const int16_t attack_flag,     /* i  : attack flag (GSC or TC)          */
      70             :     const int16_t last_coder_type, /* i  : Last coder type                  */
      71             :     const int16_t L_frame          /* i  : frame length                     */
      72             : )
      73             : {
      74             :     float etmp;
      75             :     float etmp1;
      76             :     float finc[ATT_LENGHT16k], ratio, inv_l_frame;
      77             :     int16_t att_len;
      78             :     int16_t attack_pos, i;
      79             : 
      80       90525 :     if ( attack_flag > 0 && last_coder_type == AUDIO )
      81             :     {
      82             :         /*-------------------------------------------------------------------------*
      83             :          * Find where the onset (attack) occurs by computing the energy per section
      84             :          * The inverse weighting aims to favor the first maxima in case of
      85             :          * gradual onset
      86             :          *-------------------------------------------------------------------------*/
      87             : 
      88           0 :         att_len = ATT_LENGHT;
      89           0 :         if ( L_frame == L_FRAME16k )
      90             :         {
      91           0 :             att_len = ATT_LENGHT16k;
      92             :         }
      93           0 :         for ( i = 0; i < att_len; i++ )
      94             :         {
      95           0 :             finc[i] = sum2_f( exc + i * ATT_SEG_LEN, ATT_SEG_LEN ) * ( (float) ( att_len - i ) / ( att_len ) );
      96             :         }
      97           0 :         etmp = -1;
      98           0 :         attack_pos = maximum( finc, att_len, &etmp );
      99             : 
     100             :         /* Scaled the maximum energy and allowed 6 dB increase*/
     101           0 :         etmp *= INV_ATT_SEG_LEN;
     102           0 :         etmp1 = etmp;
     103           0 :         *Last_frame_ener *= 4.0f;
     104             : 
     105             :         /* If the maximum normalized energy > last frame energy + 6dB */
     106           0 :         if ( etmp > *Last_frame_ener && attack_pos > 0 )
     107             :         {
     108             :             /* Find the average energy before the attack */
     109           0 :             etmp = sum_f( finc, attack_pos ) + 0.01f;
     110           0 :             etmp /= ( attack_pos * ATT_SEG_LEN );
     111             : 
     112             :             /* Find the correction factor and apply it before the attack */
     113           0 :             ratio = (float) sqrt( *Last_frame_ener / etmp );
     114             : 
     115             : 
     116             :             /* Pre-echo atttenuation should never increase the energy */
     117           0 :             ratio = min( ratio, 1.0f );
     118           0 :             for ( i = 0; i < attack_pos * ATT_SEG_LEN; i++ )
     119             :             {
     120           0 :                 exc[i] *= ratio;
     121             :             }
     122             :         }
     123           0 :         *Last_frame_ener = etmp1;
     124             :     }
     125             :     else
     126             :     {
     127             :         /*-------------------------------------------------------*
     128             :          * In normal cases, just compute the energy of the frame
     129             :          *-------------------------------------------------------*/
     130             : 
     131       90525 :         etmp = sum2_f( exc, L_frame ) + 0.01f;
     132       90525 :         inv_l_frame = INV_L_FRAME;
     133       90525 :         if ( L_frame == L_FRAME16k )
     134             :         {
     135       10509 :             inv_l_frame = INV_L_FRAME16k;
     136             :         }
     137       90525 :         etmp *= inv_l_frame;
     138       90525 :         *Last_frame_ener = etmp;
     139             :     }
     140             : 
     141       90525 :     return;
     142             : }

Generated by: LCOV version 1.14