LCOV - code coverage report
Current view: top level - lib_com - get_gain_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 37 37 100.0 %
Date: 2025-05-03 01:55:50 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             : #include "prot_fx.h"
      40             : #include "wmc_auto.h"
      41             : 
      42             : /*----------------------------------------------------------------------------------*
      43             :  *  get_gain()
      44             :  *
      45             :  *
      46             :  *----------------------------------------------------------------------------------*/
      47             : 
      48       98554 : Word32 get_gain(                   /* output: codebook gain (adaptive or fixed)   Q16 */
      49             :                  const Word16 x[], /* input : target signal                       Qx  */
      50             :                  const Word16 y[], /* input : filtered codebook excitation        Qx  */
      51             :                  const Word16 n    /* input : segment length                          */
      52             : )
      53             : {
      54             :     Word32 tcorr, tener, Lgain;
      55             :     Word16 exp_c, exp_e, exp, tmp;
      56             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      57       98554 :     Flag Overflow = 0;
      58       98554 :     move32();
      59             : #endif
      60             : 
      61             : 
      62       98554 :     tcorr = L_deposit_l( 0 );
      63       98554 :     tener = L_deposit_l( 0 );
      64             : 
      65             : 
      66             :     /*----------------------------------------------------------------*
      67             :      * Find gain based on inter-correlation product
      68             :      *----------------------------------------------------------------*/
      69             : 
      70       98554 :     tcorr = Dot_product16HQ( 0, x, y, n, &exp_c );
      71       98554 :     tener = Dot_productSq16HQ( 0, y, n, &exp_e );
      72             : 
      73       98554 :     BASOP_Util_Divide_MantExp( round_fx_o( tcorr, &Overflow ), exp_c, s_max( round_fx_o( tener, &Overflow ), 1 ), exp_e, &tmp, &exp );
      74       98554 :     Lgain = L_shl_o( L_deposit_l( tmp ) /*Q15*/, add( 1, exp ), &Overflow ) /*Q16*/;
      75             : 
      76       98554 :     return Lgain;
      77             : }
      78             : 
      79     1389169 : Word32 get_gain2(                   /* output: codebook gain (adaptive or fixed)   Q16 */
      80             :                   const Word16 x[], /* input : target signal                        */
      81             :                   const Word16 y[], /* input : filtered codebook excitation         */
      82             :                   const Word16 n    /* input : segment length                       */
      83             : )
      84             : {
      85             :     Word32 tcorr, tener, Lgain;
      86             :     Word16 m_corr, m_ener, negative, Q_corr, Q_ener;
      87             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      88     1389169 :     Flag Overflow = 0;
      89     1389169 :     move32();
      90             : #endif
      91             : 
      92     1389169 :     negative = 0;
      93     1389169 :     move16();
      94             : 
      95             :     /*----------------------------------------------------------------*
      96             :      * Find gain based on inter-correlation product
      97             :      *----------------------------------------------------------------*/
      98     1389169 :     tcorr = Dot_product16HQ( 0, x, y, n, &Q_corr );
      99     1389169 :     tener = Dot_productSq16HQ( 0, y, n, &Q_ener );
     100             : 
     101     1389169 :     tener = L_max( tener, 1 );
     102             : 
     103     1389169 :     if ( tcorr <= 0 )
     104             :     {
     105       64042 :         negative = 1;
     106       64042 :         move16();
     107             :     }
     108             :     BASOP_SATURATE_WARNING_OFF_EVS /*tcorr max be negative maxvall -  not critical*/
     109     1389169 :         tcorr = L_abs( tcorr );
     110             :     BASOP_SATURATE_WARNING_ON_EVS
     111             : 
     112     1389169 :     m_corr = extract_h( tcorr );
     113             : 
     114     1389169 :     m_ener = extract_h( tener );
     115             : 
     116     1389169 :     IF( GT_16( m_corr, m_ener ) )
     117             :     {
     118      640822 :         m_corr = shr( m_corr, 1 );
     119      640822 :         Q_corr = add( Q_corr, 1 );
     120             :     }
     121     1389169 :     if ( m_ener == 0 )
     122             :     {
     123       18907 :         move16();
     124       18907 :         m_corr = 0x7FFF;
     125             :     }
     126     1389169 :     IF( m_ener != 0 )
     127             :     {
     128     1370262 :         m_corr = div_s( m_corr, m_ener );
     129             :     }
     130             : 
     131     1389169 :     Q_corr = sub( Q_corr, Q_ener );
     132             : 
     133     1389169 :     Lgain = L_shl_o( L_deposit_l( m_corr ), add( Q_corr, 1 ), &Overflow ); /* Lgain in Q16 */
     134             : 
     135     1389169 :     if ( negative != 0 )
     136             :     {
     137       64042 :         Lgain = L_negate( Lgain ); /* Lgain in Q16 */
     138             :     }
     139             : 
     140             : 
     141     1389169 :     return Lgain;
     142             : }

Generated by: LCOV version 1.14