LCOV - code coverage report
Current view: top level - lib_com - ivas_stereo_ica_com.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 63 64 98.4 %
Date: 2025-05-23 08:37:30 Functions: 3 3 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             : #include <assert.h>
      34             : #include <stdint.h>
      35             : #include "options.h"
      36             : #include "cnst.h"
      37             : #include "ivas_cnst.h"
      38             : #include "prot.h"
      39             : #include "ivas_prot.h"
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include "wmc_auto.h"
      44             : #include "rom_com.h"
      45             : #include "ivas_rom_com.h"
      46             : 
      47             : /*---------------------------------------------------------------
      48             :  * interpTargetChannel()
      49             :  *
      50             :  * Target signal correction for shift variations.
      51             :  * The pointer passsed into this function is assumed to be chanR/chanL + currNCShift.
      52             :  * ---------------------------------------------------------------*/
      53             : 
      54             : #define SPREAD_FACTOR1 ( 1.0f / INTERP_FACTOR1 )
      55             : 
      56        8849 : static void interpTargetChannel(
      57             :     float *target,
      58             :     const int16_t prevShift,
      59             :     const int16_t currShift,
      60             :     const int16_t L_shift_adapt )
      61             : {
      62             :     int16_t i, j, k, /*m,*/ d, N, signShift, lim1, lim2;
      63             :     const float *win;
      64             :     float *ptr1, *ptr2;
      65             :     float tempBuff1[INTERP_FACTOR1 * ( L_SHIFT_ADAPT_MAX + 2 * N_MAX_SHIFT_CHANGE + 2 )], tempBuff2[L_SHIFT_ADAPT_MAX - 1];
      66             :     float x[4], y[4], tempF, tempF1;
      67             :     float interp_factor2, factor;
      68             :     float spread_factor2;
      69             :     double tempD1, tempD2;
      70             : 
      71        8849 :     d = -( currShift - prevShift );
      72        8849 :     signShift = ( d >= 0 ) ? ( 1 ) : ( -1 );
      73             : 
      74        8849 :     if ( d == 0 )
      75             :     {
      76             :         /* this can happen in DFT->TD switching */
      77        3612 :         return;
      78             :     }
      79             : 
      80        5237 :     N = L_shift_adapt;
      81        5237 :     factor = ( (float) N ) / abs( d );
      82        5237 :     interp_factor2 = factor / INTERP_FACTOR1;
      83        5237 :     spread_factor2 = 1.0f / interp_factor2;
      84             : 
      85             :     /* start from (target - N - d + 1) : (extra lag = step1) :to: (target - 1 - d) : (extra lag = d) */
      86             :     /* sinc interp by a factor of 2 */
      87        5237 :     win = ica_sincInterp2 + SINC_ORDER1;
      88        5237 :     ptr1 = target;
      89        5237 :     ptr2 = tempBuff1 + ( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1;
      90             : 
      91     6051781 :     for ( i = -( N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i < ( N + N_MAX_SHIFT_CHANGE + 1 ) * INTERP_FACTOR1; i++ )
      92             :     {
      93     6046544 :         if ( i & 0x1 )
      94             :         {
      95     3023272 :             ptr2[i] = 0.0f;
      96             :             /* lim1 = ceil((i - SINC_ORDER1)*SPREAD_FACTOR1); */
      97             :             /* lim2 = floor((i + SINC_ORDER1)*SPREAD_FACTOR1); */
      98     3023272 :             tempF = ( i - SINC_ORDER1 ) * SPREAD_FACTOR1;
      99     3023272 :             lim1 = (int16_t) ( tempF );
     100     3023272 :             if ( lim1 < tempF )
     101             :             {
     102     2850451 :                 lim1++;
     103             :             }
     104             : 
     105     3023272 :             tempF = ( i + SINC_ORDER1 ) * SPREAD_FACTOR1;
     106     3023272 :             lim2 = (int16_t) ( tempF );
     107     3023272 :             if ( lim2 > tempF )
     108             :             {
     109       47133 :                 lim2--;
     110             :             }
     111             : 
     112    75581800 :             for ( j = lim1; j <= lim2; j++ )
     113             :             {
     114    72558528 :                 ptr2[i] += win[j * INTERP_FACTOR1 - i] * ptr1[j];
     115             :             }
     116             :         }
     117             :         else
     118             :         {
     119     3023272 :             ptr2[i] = ptr1[(int16_t) ( i * SPREAD_FACTOR1 )];
     120             :         }
     121             :     }
     122             : 
     123             :     /* cubic spline interp */
     124        5237 :     ptr1 = ptr2;
     125        5237 :     ptr2 = tempBuff2;
     126             : 
     127        5237 :     tempD1 = ( 1.0f / ( 6 * interp_factor2 * interp_factor2 * interp_factor2 ) );
     128        5237 :     tempD2 = 3.0f * tempD1;
     129     2803318 :     for ( tempF1 = d * factor - signShift, k = 0; k < N - 1; k++, tempF1 += ( factor - signShift ) )
     130             :     {
     131     2798081 :         tempF = tempF1 * spread_factor2 - 1;
     132     2798081 :         lim1 = (int16_t) ( tempF );
     133     2798081 :         if ( lim1 > tempF )
     134             :         {
     135        9472 :             lim1--;
     136             :         }
     137             : 
     138     2798081 :         y[0] = ptr1[lim1];
     139     2798081 :         y[1] = ptr1[lim1 + 1];
     140     2798081 :         y[2] = ptr1[lim1 + 2];
     141     2798081 :         y[3] = ptr1[lim1 + 3];
     142             : 
     143     2798081 :         x[0] = lim1 * interp_factor2;
     144     2798081 :         x[1] = x[0] + interp_factor2;
     145     2798081 :         x[2] = x[1] + interp_factor2;
     146     2798081 :         x[3] = x[2] + interp_factor2;
     147             : 
     148     2798081 :         ptr2[k] = (float) ( ( y[3] * ( ( tempF1 - x[0] ) * ( tempF1 - x[1] ) * ( tempF1 - x[2] ) ) - y[0] * ( ( tempF1 - x[1] ) * ( tempF1 - x[2] ) * ( tempF1 - x[3] ) ) ) * tempD1 + ( y[1] * ( ( tempF1 - x[0] ) * ( tempF1 - x[2] ) * ( tempF1 - x[3] ) ) - y[2] * ( ( tempF1 - x[0] ) * ( tempF1 - x[1] ) * ( tempF1 - x[3] ) ) ) * tempD2 );
     149             :     }
     150             : 
     151        5237 :     ptr1 = target;
     152        5237 :     mvr2r( ptr2, ptr1, N - 1 );
     153             : 
     154        5237 :     return;
     155             : }
     156             : 
     157             : 
     158             : /*---------------------------------------------------------------
     159             :  *  Function targetCh_AlignStereoDFT()
     160             :  *
     161             :  *  Align target channel in DFT stereo to correct for shift variations
     162             :  * ---------------------------------------------------------------*/
     163             : 
     164        3134 : static void targetCh_AlignStereoDFT(
     165             :     float *target,
     166             :     const int16_t prevShift,
     167             :     const int16_t currShift,
     168             :     const int16_t L_shift_adapt )
     169             : {
     170             :     int16_t i;
     171             :     float winSlope, alpha;
     172             :     int16_t d;
     173             : 
     174             :     float fadeOutBuff[L_SHIFT_ADAPT_MAX];
     175             :     float fadeInBuff[L_SHIFT_ADAPT_MAX];
     176             : 
     177        3134 :     d = -( currShift - prevShift );
     178             : 
     179        3134 :     mvr2r( target + d, fadeOutBuff, L_shift_adapt );
     180        3134 :     mvr2r( target, fadeInBuff, L_shift_adapt );
     181             : 
     182        3134 :     if ( L_shift_adapt > 0 )
     183             :     {
     184        3134 :         alpha = 0;
     185        3134 :         winSlope = 1.0f / L_shift_adapt;
     186     1663512 :         for ( i = 0; i < L_shift_adapt; i++ )
     187             :         {
     188     1660378 :             target[i] = alpha * fadeInBuff[i] + ( 1 - alpha ) * fadeOutBuff[i];
     189     1660378 :             alpha += winSlope;
     190             :         }
     191             :     }
     192             :     else
     193             :     {
     194           0 :         mvr2r( fadeInBuff, target, L_shift_adapt );
     195             :     }
     196             : 
     197        3134 :     return;
     198             : }
     199             : 
     200             : 
     201             : /*---------------------------------------------------------------
     202             :  * adjustTargetSignal()
     203             :  *
     204             :  * Target signal correction for shift variations.
     205             :  * ---------------------------------------------------------------*/
     206             : 
     207       11983 : void adjustTargetSignal(
     208             :     float *target,
     209             :     const int16_t prevShift,
     210             :     const int16_t currShift,
     211             :     const int16_t L_shift_adapt,
     212             :     const int16_t method )
     213             : {
     214             :     /* inter-frame shift variation and target shifting */
     215             : 
     216       11983 :     if ( method == 0 )
     217             :     {
     218        8849 :         interpTargetChannel( target, prevShift, currShift, L_shift_adapt );
     219             :     }
     220             :     else
     221             :     {
     222        3134 :         targetCh_AlignStereoDFT( target, prevShift, currShift, L_shift_adapt );
     223             :     }
     224             : 
     225       11983 :     return;
     226             : }

Generated by: LCOV version 1.14