LCOV - code coverage report
Current view: top level - lib_com - window_ola.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 1ecb9137d23f3dad766c8f6f3eb1e829e795f071 Lines: 192 208 92.3 %
Date: 2025-10-29 06:44:26 Functions: 4 4 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             : #ifdef DEBUGGING
      40             : #include "debug.h"
      41             : #endif
      42             : #include <math.h>
      43             : #include "cnst.h"
      44             : #include "rom_com.h"
      45             : #include "prot.h"
      46             : #include "wmc_auto.h"
      47             : 
      48             : /*--------------------------------------------------------------------------
      49             :  * window_ola()
      50             :  *
      51             :  * Windowing, Overlap and Add
      52             :  *--------------------------------------------------------------------------*/
      53             : 
      54             : 
      55    27893307 : void window_ola(
      56             :     const float *ImdctOut, /* i  : input                       */
      57             :     float *auOut,          /* o  : output audio                */
      58             :     float *OldauOut,       /* i/o: audio from previous frame   */
      59             :     const int16_t L,       /* i  : length                      */
      60             :     const int16_t right_mode,
      61             :     const int16_t left_mode,    /* i  : window overlap of current frame (0: full, 2: none, or 3: half) */
      62             :     const int16_t use_bfi_win,  /* i  : use BFI windowing           */
      63             :     const int16_t oldHqVoicing, /* i  : previous HqVoicing          */
      64             :     float *oldgapsynth          /* i  : previous gapsynth           */
      65             : )
      66             : {
      67             :     int16_t i, decimate, decay;
      68             :     int16_t n, n16, windecay48, windecay16;
      69             :     float win_right[R2_48];
      70             :     float win_int_left[R1_16];
      71             :     float win_left[R1_48];
      72             :     float win_int_right[R2_16];
      73             : 
      74             : 
      75             :     float SS2[L_FRAME48k - NS2SA( 48000, N_ZERO_MDCT_NS )];
      76             :     float wret2[L_FRAME48k - NS2SA( 48000, N_ZERO_MDCT_NS )];
      77             : 
      78             :     float *paout;
      79             : 
      80             : 
      81    27893307 :     n = (int16_t) ( (float) L * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
      82    27893307 :     n16 = (int16_t) ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
      83    27893307 :     windecay48 = (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_48;
      84    27893307 :     windecay16 = (int16_t) ( 2 * ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_16;
      85    27893307 :     decimate = 1;
      86    27893307 :     decay = 0;
      87             : 
      88    27893307 :     tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L );
      89             : 
      90    27893307 :     if ( L == L_FRAME32k || L == L_FRAME16k )
      91             :     {
      92    17134144 :         decimate = 3;
      93    17134144 :         decay = 1;
      94             :     }
      95    10759163 :     else if ( L == L_FRAME8k )
      96             :     {
      97         100 :         decimate = 6;
      98         100 :         decay = 2;
      99             :     }
     100             : 
     101    10759063 :     else if ( L == 512 )
     102             :     {
     103     3573779 :         windecay48 = (int16_t) ( 2 * ( (float) 512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_25;
     104     3573779 :         decimate = 1;
     105     3573779 :         decay = 0;
     106             :     }
     107     7185284 :     else if ( L == 256 )
     108             :     {
     109      750773 :         windecay48 = (int16_t) ( 2 * ( (float) 512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_25;
     110      750773 :         decimate = 2;
     111      750773 :         decay = 0;
     112             :     }
     113             : 
     114    27893307 :     paout = auOut - n;
     115             : 
     116    27893307 :     if ( use_bfi_win )
     117             :     {
     118         136 :         if ( L == L_FRAME32k )
     119             :         {
     120        1932 :             for ( i = 0; i < L / 2; i += 2 )
     121             :             {
     122        1920 :                 wret2[L / 2 - n + i + 1] = win_left[( L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay];
     123        1920 :                 wret2[L / 2 - n + i] = win_int_left[( L_FRAME16k / 2 - i / 2 - 1 )];
     124             :             }
     125             : 
     126         852 :             for ( i = n; i < L / 2; i += 2 )
     127             :             {
     128         840 :                 wret2[i - n] = win_left[( L_FRAME16k - i / 2 ) * decimate - decay - 1];
     129         840 :                 wret2[i + 1 - n] = win_int_left[L_FRAME16k - ( i / 2 ) - 1];
     130             :             }
     131             :         }
     132             :         else
     133             :         {
     134       19964 :             for ( i = 0; i < L / 2; i++ )
     135             :             {
     136       19840 :                 wret2[i + L / 2 - n] = win_left[( L / 2 - i - 1 ) * decimate + decay];
     137             :             }
     138             : 
     139        8804 :             for ( i = n; i < L / 2; i++ )
     140             :             {
     141        8680 :                 wret2[i - n] = win_left[( L - i ) * decimate - decay - 1];
     142             :             }
     143             :         }
     144         136 :         sinq( EVS_PI / ( 2 * ( L - n ) ), EVS_PI / ( 4 * ( L - n ) ), L - n, SS2 );
     145             : 
     146       10496 :         for ( i = n; i < L / 2; i++ )
     147             :         {
     148       10360 :             paout[i] = ImdctOut[L / 2 + i];
     149             :         }
     150             : 
     151       23816 :         for ( i = 0; i < L / 2; i++ )
     152             :         {
     153       23680 :             paout[L / 2 + i] = -ImdctOut[L - 1 - i];
     154             :         }
     155             : 
     156         136 :         if ( oldHqVoicing )
     157             :         {
     158           0 :             for ( i = 0; i < L - n; i++ )
     159             :             {
     160           0 :                 auOut[i] = auOut[i] * SS2[i] + oldgapsynth[i + n] * ( SS2[L - n - i - 1] );
     161             :             }
     162             :         }
     163             :         else
     164             :         {
     165       34176 :             for ( i = 0; i < L - n; i++ )
     166             :             {
     167       34040 :                 auOut[i] = auOut[i] * SS2[i] + OldauOut[i + n] * ( SS2[L - n - i - 1] ) / ( wret2[i] + 0.01f );
     168             :             }
     169             :         }
     170             :     }
     171             : 
     172    27893307 :     if ( L == L_FRAME32k )
     173             :     {
     174     9194789 :         if ( use_bfi_win == 0 )
     175             :         {
     176   652829167 :             for ( i = n; i < L / 2; i += 2 )
     177             :             {
     178   643634390 :                 paout[i] = ImdctOut[L / 2 + i] * win_right[( 2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) ) * decimate - 1 - decay - windecay48] + OldauOut[i];
     179   643634390 :                 paout[i + 1] = ImdctOut[L / 2 + i + 1] * win_int_right[2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) - 1 - windecay16] + OldauOut[i + 1];
     180             :             }
     181             : 
     182   652829167 :             for ( i = 0; i < L / 2 - n; i += 2 )
     183             :             {
     184   643634390 :                 paout[L / 2 + i + 1] = -ImdctOut[L - 1 - ( i + 1 )] * win_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) * decimate + decay - windecay48] + OldauOut[i + L / 2 + 1];
     185   643634390 :                 paout[L / 2 + i] = -ImdctOut[L - 1 - i] * win_int_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) - windecay16] + OldauOut[i + L / 2];
     186             :             }
     187             : 
     188   836724707 :             for ( i = L / 2 - n; i < L / 2; i += 2 )
     189             :             {
     190   827529930 :                 paout[L / 2 + i + 1] = -ImdctOut[L - 1 - ( i + 1 )] + OldauOut[i + L / 2 + 1];
     191   827529930 :                 paout[L / 2 + i] = -ImdctOut[L - 1 - i] + OldauOut[i + L / 2];
     192             :             }
     193             :         }
     194             : 
     195  1480361029 :         for ( i = 0; i < L / 2; i += 2 )
     196             :         {
     197  1471166240 :             OldauOut[L / 2 + i + 1] = -ImdctOut[i + 1] * win_left[( L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay];
     198  1471166240 :             OldauOut[L / 2 + i] = -ImdctOut[i] * win_int_left[( L_FRAME16k / 2 - i / 2 - 1 )];
     199             :         }
     200             : 
     201             : 
     202   652830019 :         for ( i = n; i < L / 2; i += 2 )
     203             :         {
     204   643635230 :             OldauOut[i] = -ImdctOut[L / 2 - 1 - i] * win_left[( L_FRAME16k - i / 2 ) * decimate - decay - 1];
     205   643635230 :             OldauOut[i + 1] = -ImdctOut[L / 2 - 1 - ( i + 1 )] * win_int_left[L_FRAME16k - ( i / 2 ) - 1];
     206             :         }
     207             :     }
     208             :     else
     209             :     {
     210    18698518 :         if ( use_bfi_win == 0 )
     211             :         {
     212             : 
     213  2368001910 :             for ( i = n; i < L / 2; i++ )
     214             :             {
     215  2349303516 :                 paout[i] = ImdctOut[L / 2 + i] * win_right[( 2 * L - i ) * decimate - 1 - decay - windecay48] + OldauOut[i];
     216             :             }
     217             : 
     218  2368001910 :             for ( i = 0; i < L / 2 - n; i++ )
     219             :             {
     220  2349303516 :                 paout[L / 2 + i] = -ImdctOut[L - 1 - i] * win_right[( 3 * L / 2 - 1 - i ) * decimate + decay - windecay48] + OldauOut[i + L / 2];
     221             :             }
     222             : 
     223  3039231486 :             for ( i = L / 2 - n; i < L / 2; i++ )
     224             :             {
     225  3020533092 :                 paout[L / 2 + i] = -ImdctOut[L - 1 - i] + OldauOut[i + L / 2];
     226             :             }
     227             :         }
     228             : 
     229  5388554966 :         for ( i = 0; i < L / 2; i++ )
     230             :         {
     231  5369856448 :             OldauOut[L / 2 + i] = -ImdctOut[i] * win_left[( L / 2 - i - 1 ) * decimate + decay];
     232             :         }
     233             : 
     234             : 
     235  2368010714 :         for ( i = n; i < L / 2; i++ )
     236             :         {
     237  2349312196 :             OldauOut[i] = -ImdctOut[L / 2 - 1 - i] * win_left[( L - i ) * decimate - decay - 1];
     238             :         }
     239             :     }
     240             : 
     241  4703499579 :     for ( i = 0; i < n; i++ )
     242             :     {
     243  4675606272 :         OldauOut[i] = -ImdctOut[L / 2 - 1 - i];
     244             :     }
     245  4703499579 :     for ( i = 0; i < n; i++ )
     246             :     {
     247  4675606272 :         paout[L + i] = OldauOut[i];
     248             :     }
     249             : 
     250    27893307 :     return;
     251             : }
     252             : 
     253             : 
     254             : /*-------------------------------------------------------------------*
     255             :  * window_ola_ext()
     256             :  *
     257             :  *
     258             :  *-------------------------------------------------------------------*/
     259             : 
     260        7368 : void window_ola_ext(
     261             :     const float *ImdstOut, /* i  : input                       */
     262             :     float *auOut,          /* o  : output audio                */
     263             :     float *OldauOut,       /* i/o: audio from previous frame   */
     264             :     const int16_t L,       /* i  : length                      */
     265             :     const int16_t right_mode,
     266             :     const int16_t left_mode,   /* i  : window overlap of current frame (0: full, 2: none, or 3: half) */
     267             :     const uint16_t kernel_type /* i  : transform kernel type  */
     268             : )
     269             : {
     270        7368 :     const float sign_left = ( kernel_type & 1 ? 1.f : -1.f );
     271        7368 :     const float sign_right = ( kernel_type >= MDCT_II ? -1.f : 1.f );
     272             :     int16_t i, decimate, decay;
     273             :     int16_t n, n16, windecay48, windecay16;
     274             :     float win_right[R2_48];
     275             :     float win_int_left[R1_16];
     276             :     float win_left[R1_48];
     277             :     float win_int_right[R2_16];
     278             :     float *paout;
     279             : 
     280        7368 :     n = (int16_t) ( (float) L * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
     281        7368 :     n16 = (int16_t) ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
     282        7368 :     windecay48 = (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_48;
     283        7368 :     windecay16 = (int16_t) ( 2 * ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_16;
     284        7368 :     decimate = 1;
     285        7368 :     decay = 0;
     286             : 
     287        7368 :     tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L );
     288             : 
     289        7368 :     if ( L == L_FRAME32k || L == L_FRAME16k )
     290             :     {
     291        3792 :         decimate = 3;
     292        3792 :         decay = 1;
     293             :     }
     294        3576 :     else if ( L == L_FRAME8k )
     295             :     {
     296           0 :         decimate = 6;
     297           0 :         decay = 2;
     298             :     }
     299             : 
     300        3576 :     else if ( L == 512 )
     301             :     {
     302        2386 :         windecay48 = (int16_t) ( 2 * ( (float) 512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_25;
     303        2386 :         decimate = 1;
     304        2386 :         decay = 0;
     305             :     }
     306        1190 :     else if ( L == 256 )
     307             :     {
     308           0 :         windecay48 = (int16_t) ( 2 * ( (float) 512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_25;
     309           0 :         decimate = 2;
     310           0 :         decay = 0;
     311             :     }
     312             : 
     313        7368 :     paout = auOut - n;
     314             : 
     315        7368 :     if ( L == L_FRAME32k )
     316             :     {
     317       99826 :         for ( i = n; i < L / 2; i += 2 )
     318             :         {
     319       98420 :             paout[i] = sign_right * ImdstOut[L / 2 + i] * win_right[( 2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) ) * decimate - 1 - decay - windecay48] + OldauOut[i];
     320       98420 :             paout[i + 1] = sign_right * ImdstOut[L / 2 + i + 1] * win_int_right[2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) - 1 - windecay16] + OldauOut[i + 1];
     321             :         }
     322             : 
     323       99826 :         for ( i = 0; i < L / 2 - n; i += 2 )
     324             :         {
     325       98420 :             paout[L / 2 + i + 1] = -ImdstOut[L - 1 - ( i + 1 )] * win_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) * decimate + decay - windecay48] + OldauOut[i + L / 2 + 1];
     326       98420 :             paout[L / 2 + i] = -ImdstOut[L - 1 - i] * win_int_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) - windecay16] + OldauOut[i + L / 2];
     327             :         }
     328             : 
     329      127946 :         for ( i = L / 2 - n; i < L / 2; i += 2 )
     330             :         {
     331      126540 :             paout[L / 2 + i + 1] = -ImdstOut[L - 1 - ( i + 1 )] + OldauOut[i + L / 2 + 1];
     332      126540 :             paout[L / 2 + i] = -ImdstOut[L - 1 - i] + OldauOut[i + L / 2];
     333             :         }
     334             : 
     335      226366 :         for ( i = 0; i < L / 2; i += 2 )
     336             :         {
     337      224960 :             OldauOut[L / 2 + i + 1] = sign_left * ImdstOut[i + 1] * win_left[( L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay];
     338      224960 :             OldauOut[L / 2 + i] = sign_left * ImdstOut[i] * win_int_left[( L_FRAME16k / 2 - i / 2 - 1 )];
     339             :         }
     340             : 
     341             : 
     342       99826 :         for ( i = n; i < L / 2; i += 2 )
     343             :         {
     344       98420 :             OldauOut[i] = -ImdstOut[L / 2 - 1 - i] * win_left[( L_FRAME16k - i / 2 ) * decimate - decay - 1];
     345       98420 :             OldauOut[i + 1] = -ImdstOut[L / 2 - 1 - ( i + 1 )] * win_int_left[L_FRAME16k - ( i / 2 ) - 1];
     346             :         }
     347             :     }
     348             :     else
     349             :     {
     350      690114 :         for ( i = n; i < L / 2; i++ )
     351             :         {
     352      684152 :             paout[i] = sign_right * ImdstOut[L / 2 + i] * win_right[( 2 * L - i ) * decimate - 1 - decay - windecay48] + OldauOut[i];
     353             :         }
     354             : 
     355      690114 :         for ( i = 0; i < L / 2 - n; i++ )
     356             :         {
     357      684152 :             paout[L / 2 + i] = -ImdstOut[L - 1 - i] * win_right[( 3 * L / 2 - 1 - i ) * decimate + decay - windecay48] + OldauOut[i + L / 2];
     358             :         }
     359             : 
     360      885586 :         for ( i = L / 2 - n; i < L / 2; i++ )
     361             :         {
     362      879624 :             paout[L / 2 + i] = -ImdstOut[L - 1 - i] + OldauOut[i + L / 2];
     363             :         }
     364             : 
     365     1569738 :         for ( i = 0; i < L / 2; i++ )
     366             :         {
     367     1563776 :             OldauOut[L / 2 + i] = sign_left * ImdstOut[i] * win_left[( L / 2 - i - 1 ) * decimate + decay];
     368             :         }
     369             : 
     370             : 
     371      690114 :         for ( i = n; i < L / 2; i++ )
     372             :         {
     373      684152 :             OldauOut[i] = -ImdstOut[L / 2 - 1 - i] * win_left[( L - i ) * decimate - decay - 1];
     374             :         }
     375             :     }
     376             : 
     377     1140072 :     for ( i = 0; i < n; i++ )
     378             :     {
     379     1132704 :         OldauOut[i] = -ImdstOut[L / 2 - 1 - i];
     380             :     }
     381     1140072 :     for ( i = 0; i < n; i++ )
     382             :     {
     383     1132704 :         paout[L + i] = OldauOut[i];
     384             :     }
     385             : 
     386        7368 :     return;
     387             : }
     388             : 
     389             : 
     390             : /*---------------------------------------------------------------------*
     391             :  * core_switching_OLA()
     392             :  *
     393             :  * modify window after HQ core decoding
     394             :  * Overlap ACELP and HQ
     395             :  *---------------------------------------------------------------------*/
     396             : 
     397         125 : void core_switching_OLA(
     398             :     const float *mem_over_hp,     /* i  : upsampling filter memory            */
     399             :     const int16_t last_L_frame,   /* i  : last L_frame lengthture             */
     400             :     const int32_t output_Fs,      /* i  : output sampling rate                */
     401             :     float *synth,                 /* i/o: synthesized signal from HQ core     */
     402             :     const float *synth_subfr_out, /* i  : synthesized signal from ACELP core  */
     403             :     float *synth_subfr_bwe,       /* i  : synthesized BWE from ACELP core     */
     404             :     const int16_t output_frame,   /* i  : output frame length                 */
     405             :     const int16_t bwidth          /* i  : output bandwidth                    */
     406             : )
     407             : {
     408             :     int16_t i, L, Loverlapp, out_filt_length, filt_delay, decimate, decay;
     409             :     float tmp_buf_switch[SWITCH_MAX_GAP], tmp_buf_switch2[HQ_DELAY_COMP * HQ_DELTA_MAX + 2];
     410             :     float delta;
     411             :     const float *win, *win_int;
     412             : 
     413         125 :     win = window_48kHz;
     414         125 :     win_int = window_8_16_32kHz;
     415         125 :     decimate = 1;
     416         125 :     decay = 0;
     417             : 
     418         125 :     if ( output_frame == L_FRAME32k || output_frame == L_FRAME16k )
     419             :     {
     420          31 :         decimate = 3;
     421          31 :         decay = 1;
     422             :     }
     423          94 :     else if ( output_frame == L_FRAME8k )
     424             :     {
     425           0 :         decimate = 6;
     426           0 :         decay = 2;
     427             :     }
     428             : 
     429             :     /* set multiplication factor according to the sampling rate */
     430         125 :     delta = 1;
     431         125 :     if ( output_frame == L_FRAME16k )
     432             :     {
     433           0 :         delta = 2;
     434             :     }
     435         125 :     else if ( output_frame == L_FRAME32k )
     436             :     {
     437          31 :         delta = 4;
     438             :     }
     439          94 :     else if ( output_frame == L_FRAME48k )
     440             :     {
     441          94 :         delta = 6;
     442             :     }
     443             : 
     444         125 :     set_f( tmp_buf_switch, 0, SWITCH_MAX_GAP );
     445         125 :     set_f( tmp_buf_switch2, 0, HQ_DELAY_COMP * HQ_DELTA_MAX + 2 );
     446             : 
     447         125 :     Loverlapp = (int16_t) ( delta * SWITCH_OVERLAP_8k );
     448             : 
     449         125 :     mvr2r( synth_subfr_out, tmp_buf_switch, NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ) ); /* copy 6.25 ms subframe  */
     450             : 
     451             :     /* conversion from 12.8kHz to output_Fs */
     452         125 :     if ( last_L_frame == L_FRAME )
     453             :     {
     454             :         /* resample filter memory */
     455          21 :         if ( output_frame == L_FRAME8k )
     456             :         {
     457           0 :             mvr2r( synth_subfr_out + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), tmp_buf_switch + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), NS2SA( output_Fs, DELAY_CLDFB_NS ) ); /* copy subframe to tmp buffer */
     458             :         }
     459             :         else
     460             :         {
     461          21 :             out_filt_length = modify_Fs_intcub3m_sup( mem_over_hp + 2, NS2SA( 12800, DELAY_CLDFB_NS ), 12800, tmp_buf_switch2, output_Fs, &filt_delay );
     462             : 
     463          69 :             for ( i = 0; i < filt_delay; i++ )
     464             :             {
     465          48 :                 tmp_buf_switch2[out_filt_length + i - filt_delay] = tmp_buf_switch2[out_filt_length - 1 - filt_delay];
     466             :             }
     467             : 
     468          21 :             if ( ( bwidth == NB && output_Fs >= 16000 ) || ( bwidth > NB && output_Fs > 16000 ) )
     469             :             {
     470             :                 /* mix cubic and CLDFB resampled buffers in case of resampling to higher frequency rates */
     471         981 :                 for ( i = 0; i < out_filt_length; i++ )
     472             :                 {
     473         960 :                     float a = (float) i / out_filt_length;
     474         960 :                     float b = 1.f - a;
     475             : 
     476         960 :                     tmp_buf_switch[NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ) + i] = a * tmp_buf_switch2[i] + b * synth_subfr_out[NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ) + i];
     477             :                 }
     478             :             }
     479             :             else
     480             :             {
     481             :                 /* copy cubic resampled buffer (memory) */
     482           0 :                 mvr2r( tmp_buf_switch2, tmp_buf_switch + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), out_filt_length );
     483             :             }
     484             :         }
     485             :     }
     486             :     else
     487             :     {
     488         104 :         if ( output_frame == L_FRAME16k )
     489             :         {
     490             :             /* no resampling */
     491           0 :             mvr2r( mem_over_hp + 2, tmp_buf_switch + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), NS2SA( output_Fs, DELAY_CLDFB_NS ) );
     492             :         }
     493             :         else
     494             :         {
     495         104 :             if ( output_frame == L_FRAME8k )
     496             :             {
     497           0 :                 mvr2r( synth_subfr_out + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), tmp_buf_switch + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), NS2SA( output_Fs, DELAY_CLDFB_NS ) ); /* copy subframe to tmp buffer */
     498             :             }
     499             :             else
     500             :             {
     501             :                 /* resample filter memory */
     502         104 :                 out_filt_length = modify_Fs_intcub3m_sup( mem_over_hp + 2, NS2SA( 16000, DELAY_CLDFB_NS ), 16000, tmp_buf_switch2, output_Fs, &filt_delay );
     503             : 
     504         296 :                 for ( i = 0; i < filt_delay; i++ )
     505             :                 {
     506         192 :                     tmp_buf_switch2[out_filt_length + i - filt_delay] = tmp_buf_switch2[out_filt_length - 1 - filt_delay];
     507             :                 }
     508             : 
     509         104 :                 if ( ( bwidth == NB && output_Fs >= 16000 ) || ( bwidth > NB && output_Fs > 16000 ) )
     510             :                 {
     511             :                     /* mix cubic and CLDFB resampled buffers in case of resampling to higher frequency rates */
     512        6024 :                     for ( i = 0; i < out_filt_length; i++ )
     513             :                     {
     514        5920 :                         float a = (float) i / out_filt_length;
     515        5920 :                         float b = 1.f - a;
     516             : 
     517        5920 :                         tmp_buf_switch[NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ) + i] = a * tmp_buf_switch2[i] + b * synth_subfr_out[NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ) + i];
     518             :                     }
     519             :                 }
     520             :                 else
     521             :                 {
     522             :                     /* copy cubic resampled buffer (memory) */
     523           0 :                     mvr2r( tmp_buf_switch2, tmp_buf_switch + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), out_filt_length );
     524             :                 }
     525             :             }
     526             :         }
     527             :     }
     528             : 
     529             :     /* Windowing for overlapadd */
     530         125 :     L = NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS + DELAY_CLDFB_NS ); /* 6.25 ms gap + 1.25 ms resamp  */
     531             : 
     532         125 :     set_f( synth, 0, L - Loverlapp );
     533             : 
     534         125 :     if ( output_frame == L_FRAME32k )
     535             :     {
     536        2201 :         for ( i = 0; i < NS2SA( output_Fs, 10000000.0f - N_ZERO_MDCT_NS ); i += 2 )
     537             :         {
     538        2170 :             synth[L - Loverlapp + i] /= win[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) * decimate + decay - (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) )];
     539        2170 :             synth[L - Loverlapp + i + 1] /= win_int[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) - (int16_t) ( 2 * ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) )];
     540             :         }
     541             :     }
     542             :     else
     543             :     {
     544       19834 :         for ( i = 0; i < NS2SA( output_Fs, 10000000.0f - N_ZERO_MDCT_NS ); i++ )
     545             :         {
     546       19740 :             synth[L - Loverlapp + i] /= win[( 3 * output_frame / 2 - 1 - i ) * decimate + decay - (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) )];
     547             :         }
     548             :     }
     549             : 
     550             : 
     551       10445 :     for ( i = 0; i < Loverlapp; i++ ) /* Windowing for overlapadd */
     552             :     {
     553       10320 :         synth[i + (int16_t) ( L - Loverlapp )] *= (float) sin( ( i + 1 ) * EVS_PI / ( 2 * ( Loverlapp + 1 ) ) );
     554       10320 :         synth_subfr_bwe[i + (int16_t) ( L - Loverlapp ) - NS2SA( output_Fs, DELAY_CLDFB_NS )] *= (float) cos( ( i + 1 ) * EVS_PI / ( 2 * ( Loverlapp + 1 ) ) ) * (float) cos( ( i + 1 ) * EVS_PI / ( 2 * ( Loverlapp + 1 ) ) );
     555       10320 :         tmp_buf_switch[i + (int16_t) ( L - Loverlapp )] *= (float) cos( ( i + 1 ) * EVS_PI / ( 2 * ( Loverlapp + 1 ) ) ) * (float) cos( ( i + 1 ) * EVS_PI / ( 2 * ( Loverlapp + 1 ) ) );
     556             :     }
     557             : 
     558             :     /* overlap-add ACELP (tmp_buf_switch) + HQ (synth) */
     559        7005 :     for ( i = 0; i < NS2SA( output_Fs, DELAY_CLDFB_NS ); i++ )
     560             :     {
     561        6880 :         synth[i] += tmp_buf_switch[i];
     562             :     }
     563       34525 :     for ( i = NS2SA( output_Fs, DELAY_CLDFB_NS ); i < L; i++ )
     564             :     {
     565       34400 :         synth[i] += tmp_buf_switch[i] + synth_subfr_bwe[i - NS2SA( output_Fs, DELAY_CLDFB_NS )];
     566             :     }
     567             : 
     568         125 :     return;
     569             : }
     570             : 
     571             : 
     572             : /*-------------------------------------------------------------------*
     573             :  * sinq()
     574             :  *
     575             :  * Fast sinus generate sin(tmp*i+phi)
     576             :  *-------------------------------------------------------------------*/
     577             : 
     578        1887 : void sinq(
     579             :     const float tmp, /* i  : sinus factor cos(tmp*i+phi)  */
     580             :     const float phi, /* i  : sinus phase cos(tmp*i+phi)  */
     581             :     const int16_t N, /* i  : size of output */
     582             :     float x[]        /* o  : output vector  */
     583             : )
     584             : {
     585             :     float A;
     586             :     int16_t i;
     587             : 
     588        1887 :     x[0] = (float) sin( phi );
     589        1887 :     x[1] = (float) sin( tmp + phi );
     590        1887 :     x[2] = (float) sin( 2 * tmp + phi );
     591             : 
     592        1887 :     if ( fabs( (float) ( tmp ) ) > 0.0001f )
     593             :     {
     594        1887 :         A = ( x[2] + x[0] ) / x[1];
     595             :     }
     596             :     else
     597             :     {
     598           0 :         A = 0;
     599             :     }
     600             : 
     601      151093 :     for ( i = 3; i < N; i++ )
     602             :     {
     603      149206 :         x[i] = A * x[i - 1] - x[i - 2];
     604             :     }
     605             : 
     606        1887 :     return;
     607             : }

Generated by: LCOV version 1.14