LCOV - code coverage report
Current view: top level - lib_com - lerp.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 35 51 68.6 %
Date: 2025-05-23 08:37:30 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.h"
      40             : #include "wmc_auto.h"
      41             : 
      42             : 
      43             : /*-------------------------------------------------------------*
      44             :  * Local function prototypes
      45             :  *-------------------------------------------------------------*/
      46             : 
      47             : static void lerp_proc( const float *f, float *f_out, const int16_t bufferNewSize, const int16_t bufferOldSize );
      48             : 
      49             : 
      50             : /*-------------------------------------------------------------*
      51             :  * procedure lerp()                                            *
      52             :  *                                                             *
      53             :  *                                                             *
      54             :  *-------------------------------------------------------------*/
      55             : 
      56     2030874 : void lerp(
      57             :     const float *f,
      58             :     float *f_out,
      59             :     const int16_t bufferNewSize,
      60             :     const int16_t bufferOldSize_inp )
      61             : {
      62             :     float maxFac;
      63             :     int16_t bufferOldSize, tmpNewSize;
      64             : 
      65     2030874 :     maxFac = 507.0 / 128.0;
      66     2030874 :     bufferOldSize = bufferOldSize_inp;
      67             : 
      68     2030874 :     if ( (float) bufferNewSize / bufferOldSize > maxFac )
      69             :     {
      70           0 :         tmpNewSize = bufferOldSize * 2;
      71           0 :         while ( bufferNewSize > bufferOldSize )
      72             :         {
      73           0 :             if ( (float) bufferNewSize / bufferOldSize <= maxFac )
      74             :             {
      75           0 :                 tmpNewSize = bufferNewSize;
      76             :             }
      77             : 
      78           0 :             lerp_proc( f, f_out, tmpNewSize, bufferOldSize );
      79             : 
      80           0 :             f = f_out;
      81           0 :             bufferOldSize = tmpNewSize;
      82           0 :             tmpNewSize *= 2;
      83             :         }
      84             :     }
      85     2030874 :     else if ( (float) bufferOldSize / bufferNewSize > maxFac )
      86             :     {
      87           0 :         tmpNewSize = bufferOldSize / 2;
      88           0 :         while ( bufferNewSize < bufferOldSize )
      89             :         {
      90           0 :             if ( (float) bufferOldSize / bufferNewSize <= maxFac )
      91             :             {
      92           0 :                 tmpNewSize = bufferNewSize;
      93             :             }
      94             : 
      95           0 :             lerp_proc( f, f_out, tmpNewSize, bufferOldSize );
      96             : 
      97           0 :             f = f_out;
      98           0 :             bufferOldSize = tmpNewSize;
      99           0 :             tmpNewSize /= 2;
     100             :         }
     101             :     }
     102             :     else
     103             :     {
     104     2030874 :         lerp_proc( f, f_out, bufferNewSize, bufferOldSize );
     105             :     }
     106             : 
     107     2030874 :     return;
     108             : }
     109             : 
     110             : /*-------------------------------------------------------------*
     111             :  * procedure lerp_proc()                                       *
     112             :  *                                                             *
     113             :  *                                                             *
     114             :  *-------------------------------------------------------------*/
     115             : 
     116     2030874 : static void lerp_proc(
     117             :     const float *f,
     118             :     float *f_out,
     119             :     const int16_t bufferNewSize,
     120             :     const int16_t bufferOldSize )
     121             : {
     122             :     int16_t i, idx;
     123             :     float pos, shift, diff;
     124             :     float buf[2 * L_FRAME_MAX];
     125             :     Word16 tmp;
     126             : 
     127     2030874 :     if ( bufferNewSize == bufferOldSize )
     128             :     {
     129      203063 :         mvr2r( f, buf, bufferNewSize );
     130      203063 :         mvr2r( buf, f_out, bufferNewSize );
     131      203063 :         return;
     132             :     }
     133             : 
     134             :     /* Using the basop code to avoid reading beyond end of input for bufferOldSize=320, bufferNewSize=640 */
     135     1827811 :     tmp = div_s( bufferOldSize, shl( bufferNewSize, 4 ) );
     136     1827811 :     shift = (float) ( L_shl( L_deposit_l( tmp ), 4 - 15 + 16 ) ) / 65536.0f;
     137     1827811 :     pos = 0.5f * shift - 0.5f;
     138             : 
     139     1827811 :     if ( shift < 0.3f )
     140             :     {
     141       16173 :         pos = pos - 0.13f;
     142             :     }
     143             : 
     144             :     /* first point of interpolation */
     145     1827811 :     if ( pos < 0 )
     146             :     {
     147      377010 :         buf[0] = f[0] + pos * ( f[1] - f[0] );
     148             :     }
     149             :     else
     150             :     {
     151     1450801 :         idx = (int16_t) pos;
     152     1450801 :         diff = pos - idx;
     153     1450801 :         buf[0] = f[idx] + diff * ( f[idx + 1] - f[idx] );
     154             :     }
     155             : 
     156     1827811 :     pos += shift;
     157             : 
     158   371488445 :     for ( i = 1; i < bufferNewSize - 1; i++ )
     159             :     {
     160   369660634 :         idx = (int16_t) pos;
     161   369660634 :         diff = pos - idx;
     162             : 
     163   369660634 :         buf[i] = f[idx] + diff * ( f[idx + 1] - f[idx] );
     164   369660634 :         pos += shift;
     165             :     }
     166             : 
     167             : 
     168             :     /* last point */
     169     1827811 :     idx = (int16_t) pos;
     170             : 
     171     1827811 :     if ( pos > bufferOldSize - 1 )
     172             :     {
     173      369900 :         idx = bufferOldSize - 2;
     174             :     }
     175             : 
     176     1827811 :     diff = pos - idx;
     177             : 
     178     1827811 :     buf[bufferNewSize - 1] = f[idx] + diff * ( f[idx + 1] - f[idx] );
     179             : 
     180     1827811 :     mvr2r( buf, f_out, bufferNewSize );
     181             : 
     182     1827811 :     return;
     183             : }

Generated by: LCOV version 1.14