LCOV - code coverage report
Current view: top level - lib_com - findpulse.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 24 37 64.9 %
Date: 2025-05-03 01:55:50 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             : #include <math.h>
      40             : #include "prot_fx.h"
      41             : #include "cnst.h"
      42             : #include "wmc_auto.h"
      43             : 
      44             : /*----------------------------------------------------------------------------------*
      45             :  *  findpulse()
      46             :  *
      47             :  *  Find first pitch pulse in a frame
      48             :  *----------------------------------------------------------------------------------*/
      49             : 
      50             : 
      51       14444 : Word16 findpulse_fx(                       /* o  : pulse position               Q0 */
      52             :                      const Word16 L_frame, /* i  : length of the frame   */
      53             :                      const Word16 res[],   /* i  : Residual signal     <12 bits  Qx */
      54             :                      const Word16 T0,      /* i  : Pitch estimation    Q0        */
      55             :                      const Word16 enc,     /* i  : enc = 1 -> encoder side; enc = 0 -> decoder side */
      56             :                      Word16 *sign          /* i/o: sign of the maximum */
      57             : )
      58             : {
      59             :     const Word16 *ptr;
      60             :     Word16 maxval;
      61             :     Word16 i, maxi;
      62             :     Word32 Ltmp;
      63             :     Word16 resf[L_FRAME16k]; /* Low pass filtered residual */
      64             : 
      65       14444 :     IF( NE_16( enc, DEC ) )
      66             :     {
      67             :         /*------------------------------------------------------------------------*
      68             :          * 1. Very simple LP filter
      69             :          *------------------------------------------------------------------------*/
      70             : 
      71             :         /* resf[0] = 0.50f * res[0] + 0.25f * res[1] */
      72       14444 :         Ltmp = L_mult( res[0], 16384 /*0.5 (Q15)*/ );          /*Q(x + 15 + 1) => Q(x + 16)*/
      73       14444 :         resf[0] = mac_r( Ltmp, res[1], 8192 /*0.25( Q15 )*/ ); /*Q(x + 16)*/
      74       14444 :         move16();
      75     4607636 :         FOR( i = 1; i < L_frame - 1; i++ )
      76             :         {
      77             :             /* resf[i] = 0.25f * res[i-1] + 0.5f * res[i] + 0.25f * res[i+1] */
      78     4593192 :             Ltmp = L_mult( 8192 /*0.25 (Q15)*/, res[i - 1] );         /*Q(x + 16)*/
      79     4593192 :             Ltmp = L_mac( Ltmp, 16384 /*0.5 (Q15)*/, res[i] );        /*Q(x + 16)*/
      80     4593192 :             resf[i] = mac_r( Ltmp, 8192 /*0.25 (Q15)*/, res[i + 1] ); /*Q(x*/
      81     4593192 :             move16();
      82             :         }
      83             : 
      84             :         /* resf[L_frame-1] = 0.25f * res[L_frame-2] + 0.50f * res[L_frame-1] */
      85       14444 :         Ltmp = L_mult( res[L_frame - 2], 8192 /*0.25 (Q15)*/ );                   /*Q(x + 16)*/
      86       14444 :         resf[L_frame - 1] = mac_r( Ltmp, 16384 /*0.5 (Q15)*/, res[L_frame - 1] ); /*Q(x)*/
      87       14444 :         move16();
      88             : 
      89             :         /*------------------------------------------------------------------------*
      90             :          * 2. Find "biggest" pitch pulse
      91             :          *------------------------------------------------------------------------*/
      92             : 
      93       14444 :         ptr = resf + L_frame - 1;
      94       14444 :         maxi = 0;
      95       14444 :         move16();
      96             : 
      97     1421480 :         FOR( i = 1; i < T0; i++ )
      98             :         {
      99     1407036 :             Ltmp = L_mult0( ptr[-maxi], ptr[-maxi] ); /*Q( 2 * x )*/
     100     1407036 :             if ( L_msu0( Ltmp, ptr[-i], ptr[-i] ) < 0 )
     101             :             {
     102       75323 :                 maxi = i;
     103       75323 :                 move16();
     104             :             }
     105             :         }
     106       14444 :         *sign = negate( shr( ptr[-maxi], 15 ) ); /*extracting sign : Q0*/
     107       14444 :         move16();
     108             :     }
     109             :     ELSE
     110             :     {
     111             :         /*-----------------------------------------------------------------*
     112             :          * 2. Find "biggest" pulse in the last pitch section according to the sign
     113             :          *-----------------------------------------------------------------*/
     114             : 
     115           0 :         maxval = 0;
     116           0 :         move16();
     117           0 :         maxi = 0;
     118           0 :         move16();
     119             : 
     120           0 :         IF( *sign == 0 )
     121             :         {
     122           0 :             FOR( i = 0; i < T0; i++ )
     123             :             {
     124           0 :                 if ( GE_16( res[i], maxval ) )
     125             :                 {
     126           0 :                     maxi = add( i, 1 );
     127             :                 }
     128           0 :                 maxval = s_max( res[i], maxval );
     129             :             }
     130             :         }
     131             :         ELSE
     132             :         {
     133           0 :             FOR( i = 0; i < T0; i++ )
     134             :             {
     135           0 :                 if ( LE_16( res[i], maxval ) )
     136             :                 {
     137           0 :                     maxi = add( i, 1 );
     138             :                 }
     139           0 :                 maxval = s_min( res[i], maxval );
     140             :             }
     141             :         }
     142             :     }
     143             : 
     144       14444 :     return maxi;
     145             : }

Generated by: LCOV version 1.14