LCOV - code coverage report
Current view: top level - lib_dec - jbm_pcmdsp_window.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 17 33 51.5 %
Date: 2025-05-23 08:37:30 Functions: 2 3 66.7 %

          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 <math.h>
      38             : #include <stdlib.h>
      39             : #include <stdint.h>
      40             : #include "options.h"
      41             : #ifdef DEBUGGING
      42             : #include "debug.h"
      43             : #endif
      44             : #include "jbm_pcmdsp_window.h"
      45             : #include "cnst.h"
      46             : #include "wmc_auto.h"
      47             : 
      48             : /*-----------------------------------------------------------------------*
      49             :  * hannWindow()
      50             :  *
      51             :  * Generates a Hann window (cos-shaped) of length n
      52             :  *-----------------------------------------------------------------------*/
      53             : 
      54         105 : void hannWindow(
      55             :     uint16_t n,
      56             :     float *w )
      57             : {
      58             :     uint16_t i;
      59             :     float arg;
      60             : 
      61       43305 :     for ( i = 0; i < n / 2; i++ )
      62             :     {
      63       43200 :         arg = ( ( 2.0f * EVS_PI ) * i ) / (float) ( n );
      64       43200 :         w[i] = (float) ( ( 1.0f - cos( arg ) ) / 2.0f );
      65             :     }
      66             : 
      67       43305 :     for ( ; i < n; i++ )
      68             :     {
      69       43200 :         w[i] = 1.0f - w[i - n / 2];
      70             :     }
      71             : 
      72         105 :     return;
      73             : }
      74             : 
      75             : 
      76             : /*-----------------------------------------------------------------------*
      77             :  * overlapAdd()
      78             :  *
      79             :  *  Overlap/Add of two signal with a given window
      80             :  *-----------------------------------------------------------------------*/
      81             : 
      82         312 : void overlapAdd(
      83             :     const float *fadeOut,
      84             :     const float *fadeIn,
      85             :     float *out,
      86             :     uint16_t n,
      87             :     uint16_t nChannels,
      88             :     const float *fadeOutWin,
      89             :     const float *fadeInWin )
      90             : {
      91             :     float fdOutVal, fdInVal;
      92             :     int16_t i, j, hannIter;
      93             :     float combinedVal;
      94             : 
      95        1161 :     for ( j = 0; j < nChannels; j++ )
      96             :     {
      97             :         /* reset Hann window iterator to beginning (both channels use same window) */
      98         849 :         hannIter = 0;
      99      359409 :         for ( i = j; i < n; i += nChannels )
     100             :         {
     101      358560 :             fdOutVal = fadeOut[i] * fadeOutWin[hannIter];
     102      358560 :             fdInVal = fadeIn[i] * fadeInWin[hannIter];
     103             :             /* round combinedVal value (taking care of sign) */
     104      358560 :             combinedVal = fdInVal + fdOutVal;
     105      358560 :             out[i] = combinedVal;
     106      358560 :             hannIter++;
     107             :         }
     108             :     }
     109             : 
     110         312 :     return;
     111             : }
     112             : 
     113           0 : void overlapAddEvs(
     114             :     const float *fadeOut,
     115             :     const float *fadeIn,
     116             :     float *out,
     117             :     uint16_t n,
     118             :     uint16_t nChannels,
     119             :     const float *fadeOutWin,
     120             :     const float *fadeInWin )
     121             : {
     122             :     float fdOutVal, fdInVal;
     123             :     int16_t i, j, hannIter;
     124             :     float combinedVal;
     125             : 
     126           0 :     for ( j = 0; j < nChannels; j++ )
     127             :     {
     128             :         /* reset Hann window iterator to beginning (both channels use same window) */
     129           0 :         hannIter = 0;
     130           0 :         for ( i = j; i < n; i += nChannels )
     131             :         {
     132           0 :             fdOutVal = fadeOut[i] * fadeOutWin[hannIter];
     133           0 :             fdInVal = fadeIn[i] * fadeInWin[hannIter];
     134             :             /* round combinedVal value (taking care of sign) */
     135             : 
     136           0 :             combinedVal = floorf( ( fdInVal + fdOutVal ) + 0.5f );
     137           0 :             if ( fdInVal + fdOutVal < 0.0 )
     138             :             {
     139           0 :                 combinedVal = ceilf( ( fdInVal + fdOutVal ) - 0.5f );
     140             :             }
     141             : 
     142             :             /* saturate value */
     143           0 :             if ( combinedVal > MAX16B_FLT )
     144             :             {
     145           0 :                 combinedVal = MAX16B_FLT;
     146             :             }
     147           0 :             else if ( combinedVal < MIN16B_FLT )
     148             :             {
     149           0 :                 combinedVal = MIN16B_FLT;
     150             :             }
     151             : 
     152           0 :             out[i] = combinedVal;
     153             : 
     154           0 :             hannIter++;
     155             :         }
     156             :     }
     157             : 
     158           0 :     return;
     159             : }

Generated by: LCOV version 1.14