LCOV - code coverage report
Current view: top level - lib_com - get_gain_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 31 33 93.9 %
Date: 2025-08-23 01:22:27 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       27065 : 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             : #ifndef ISSUE_1836_replace_overflow_libcom
      57             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      58             :     Flag Overflow = 0;
      59             :     move32();
      60             : #endif
      61             : #endif
      62             : 
      63             : 
      64       27065 :     tcorr = L_deposit_l( 0 );
      65       27065 :     tener = L_deposit_l( 0 );
      66             : 
      67             : 
      68             :     /*----------------------------------------------------------------*
      69             :      * Find gain based on inter-correlation product
      70             :      *----------------------------------------------------------------*/
      71             : 
      72       27065 :     tcorr = Dot_product16HQ( 0, x, y, n, &exp_c );
      73       27065 :     tener = Dot_productSq16HQ( 0, y, n, &exp_e );
      74             : 
      75             : #ifdef ISSUE_1836_replace_overflow_libcom
      76       27065 :     BASOP_Util_Divide_MantExp( round_fx_sat( tcorr ), exp_c, s_max( round_fx_sat( tener ), 1 ), exp_e, &tmp, &exp );
      77       27065 :     Lgain = L_shl_sat( L_deposit_l( tmp ) /*Q15*/, add( 1, exp ) ) /*Q16*/; //?sat
      78             : #else
      79             :     BASOP_Util_Divide_MantExp( round_fx_o( tcorr, &Overflow ), exp_c, s_max( round_fx_o( tener, &Overflow ), 1 ), exp_e, &tmp, &exp );
      80             :     Lgain = L_shl_o( L_deposit_l( tmp ) /*Q15*/, add( 1, exp ), &Overflow ) /*Q16*/;
      81             : #endif
      82             : 
      83       27065 :     return Lgain;
      84             : }
      85             : 
      86        2360 : Word32 get_gain2(                   /* output: codebook gain (adaptive or fixed)   Q16 */
      87             :                   const Word16 x[], /* input : target signal                        */
      88             :                   const Word16 y[], /* input : filtered codebook excitation         */
      89             :                   const Word16 n    /* input : segment length                       */
      90             : )
      91             : {
      92             :     Word32 tcorr, tener, Lgain;
      93             :     Word16 m_corr, m_ener, negative, Q_corr, Q_ener;
      94             : #ifndef ISSUE_1836_replace_overflow_libcom
      95             : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
      96             :     Flag Overflow = 0;
      97             :     move32();
      98             : #endif
      99             : #endif
     100             : 
     101        2360 :     negative = 0;
     102        2360 :     move16();
     103             : 
     104             :     /*----------------------------------------------------------------*
     105             :      * Find gain based on inter-correlation product
     106             :      *----------------------------------------------------------------*/
     107        2360 :     tcorr = Dot_product16HQ( 0, x, y, n, &Q_corr );
     108        2360 :     tener = Dot_productSq16HQ( 0, y, n, &Q_ener );
     109             : 
     110        2360 :     tener = L_max( tener, 1 );
     111             : 
     112        2360 :     if ( tcorr <= 0 )
     113             :     {
     114           6 :         negative = 1;
     115           6 :         move16();
     116             :     }
     117             :     BASOP_SATURATE_WARNING_OFF_EVS /*tcorr max be negative maxvall -  not critical*/
     118        2360 :         tcorr = L_abs( tcorr );
     119             :     BASOP_SATURATE_WARNING_ON_EVS
     120             : 
     121        2360 :     m_corr = extract_h( tcorr );
     122             : 
     123        2360 :     m_ener = extract_h( tener );
     124             : 
     125        2360 :     IF( GT_16( m_corr, m_ener ) )
     126             :     {
     127         944 :         m_corr = shr( m_corr, 1 );
     128         944 :         Q_corr = add( Q_corr, 1 );
     129             :     }
     130        2360 :     if ( m_ener == 0 )
     131             :     {
     132           0 :         move16();
     133           0 :         m_corr = 0x7FFF;
     134             :     }
     135        2360 :     IF( m_ener != 0 )
     136             :     {
     137        2360 :         m_corr = div_s( m_corr, m_ener );
     138             :     }
     139             : 
     140        2360 :     Q_corr = sub( Q_corr, Q_ener );
     141             : 
     142             : #ifdef ISSUE_1836_replace_overflow_libcom
     143        2360 :     Lgain = L_shl_sat( L_deposit_l( m_corr ), add( Q_corr, 1 ) ); /* Lgain in Q16 */
     144             : #else
     145             :     Lgain = L_shl_o( L_deposit_l( m_corr ), add( Q_corr, 1 ), &Overflow ); /* Lgain in Q16 */
     146             : #endif
     147             : 
     148        2360 :     if ( negative != 0 )
     149             :     {
     150           6 :         Lgain = L_negate( Lgain ); /* Lgain in Q16 */
     151             :     }
     152             : 
     153             : 
     154        2360 :     return Lgain;
     155             : }

Generated by: LCOV version 1.14