LCOV - code coverage report
Current view: top level - lib_com - window_ola.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 6baab0c613aa6c7100498ed7b93676aa8198a493 Lines: 199 208 95.7 %
Date: 2025-05-29 08:28:55 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    59611049 : 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    59611049 :     n = (int16_t) ( (float) L * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
      82    59611049 :     n16 = (int16_t) ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
      83    59611049 :     windecay48 = (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_48;
      84    59611049 :     windecay16 = (int16_t) ( 2 * ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_16;
      85    59611049 :     decimate = 1;
      86    59611049 :     decay = 0;
      87             : 
      88    59611049 :     tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L );
      89             : 
      90    59611049 :     if ( L == L_FRAME32k || L == L_FRAME16k )
      91             :     {
      92    34357185 :         decimate = 3;
      93    34357185 :         decay = 1;
      94             :     }
      95    25253864 :     else if ( L == L_FRAME8k )
      96             :     {
      97        1436 :         decimate = 6;
      98        1436 :         decay = 2;
      99             :     }
     100             : 
     101    25252428 :     else if ( L == 512 )
     102             :     {
     103     8206566 :         windecay48 = (int16_t) ( 2 * ( (float) 512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_25;
     104     8206566 :         decimate = 1;
     105     8206566 :         decay = 0;
     106             :     }
     107    17045862 :     else if ( L == 256 )
     108             :     {
     109     1763692 :         windecay48 = (int16_t) ( 2 * ( (float) 512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_25;
     110     1763692 :         decimate = 2;
     111     1763692 :         decay = 0;
     112             :     }
     113             : 
     114    59611049 :     paout = auOut - n;
     115             : 
     116    59611049 :     if ( use_bfi_win )
     117             :     {
     118         225 :         if ( L == L_FRAME32k )
     119             :         {
     120        2898 :             for ( i = 0; i < L / 2; i += 2 )
     121             :             {
     122        2880 :                 wret2[L / 2 - n + i + 1] = win_left[( L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay];
     123        2880 :                 wret2[L / 2 - n + i] = win_int_left[( L_FRAME16k / 2 - i / 2 - 1 )];
     124             :             }
     125             : 
     126        1278 :             for ( i = n; i < L / 2; i += 2 )
     127             :             {
     128        1260 :                 wret2[i - n] = win_left[( L_FRAME16k - i / 2 ) * decimate - decay - 1];
     129        1260 :                 wret2[i + 1 - n] = win_int_left[L_FRAME16k - ( i / 2 ) - 1];
     130             :             }
     131             :         }
     132             :         else
     133             :         {
     134       35407 :             for ( i = 0; i < L / 2; i++ )
     135             :             {
     136       35200 :                 wret2[i + L / 2 - n] = win_left[( L / 2 - i - 1 ) * decimate + decay];
     137             :             }
     138             : 
     139       15607 :             for ( i = n; i < L / 2; i++ )
     140             :             {
     141       15400 :                 wret2[i - n] = win_left[( L - i ) * decimate - decay - 1];
     142             :             }
     143             :         }
     144         225 :         sinq( EVS_PI / ( 2 * ( L - n ) ), EVS_PI / ( 4 * ( L - n ) ), L - n, SS2 );
     145             : 
     146       18145 :         for ( i = n; i < L / 2; i++ )
     147             :         {
     148       17920 :             paout[i] = ImdctOut[L / 2 + i];
     149             :         }
     150             : 
     151       41185 :         for ( i = 0; i < L / 2; i++ )
     152             :         {
     153       40960 :             paout[L / 2 + i] = -ImdctOut[L - 1 - i];
     154             :         }
     155             : 
     156         225 :         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       59105 :             for ( i = 0; i < L - n; i++ )
     166             :             {
     167       58880 :                 auOut[i] = auOut[i] * SS2[i] + OldauOut[i + n] * ( SS2[L - n - i - 1] ) / ( wret2[i] + 0.01f );
     168             :             }
     169             :         }
     170             :     }
     171             : 
     172    59611049 :     if ( L == L_FRAME32k )
     173             :     {
     174    18739328 :         if ( use_bfi_win == 0 )
     175             :         {
     176  1330491010 :             for ( i = n; i < L / 2; i += 2 )
     177             :             {
     178  1311751700 :                 paout[i] = ImdctOut[L / 2 + i] * win_right[( 2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) ) * decimate - 1 - decay - windecay48] + OldauOut[i];
     179  1311751700 :                 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  1330491010 :             for ( i = 0; i < L / 2 - n; i += 2 )
     183             :             {
     184  1311751700 :                 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  1311751700 :                 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  1705277210 :             for ( i = L / 2 - n; i < L / 2; i += 2 )
     189             :             {
     190  1686537900 :                 paout[L / 2 + i + 1] = -ImdctOut[L - 1 - ( i + 1 )] + OldauOut[i + L / 2 + 1];
     191  1686537900 :                 paout[L / 2 + i] = -ImdctOut[L - 1 - i] + OldauOut[i + L / 2];
     192             :             }
     193             :         }
     194             : 
     195  3017031808 :         for ( i = 0; i < L / 2; i += 2 )
     196             :         {
     197  2998292480 :             OldauOut[L / 2 + i + 1] = -ImdctOut[i + 1] * win_left[( L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay];
     198  2998292480 :             OldauOut[L / 2 + i] = -ImdctOut[i] * win_int_left[( L_FRAME16k / 2 - i / 2 - 1 )];
     199             :         }
     200             : 
     201             : 
     202  1330492288 :         for ( i = n; i < L / 2; i += 2 )
     203             :         {
     204  1311752960 :             OldauOut[i] = -ImdctOut[L / 2 - 1 - i] * win_left[( L_FRAME16k - i / 2 ) * decimate - decay - 1];
     205  1311752960 :             OldauOut[i + 1] = -ImdctOut[L / 2 - 1 - ( i + 1 )] * win_int_left[L_FRAME16k - ( i / 2 ) - 1];
     206             :         }
     207             :     }
     208             :     else
     209             :     {
     210    40871721 :         if ( use_bfi_win == 0 )
     211             :         {
     212             : 
     213  5361314208 :             for ( i = n; i < L / 2; i++ )
     214             :             {
     215  5320442694 :                 paout[i] = ImdctOut[L / 2 + i] * win_right[( 2 * L - i ) * decimate - 1 - decay - windecay48] + OldauOut[i];
     216             :             }
     217             : 
     218  5361314208 :             for ( i = 0; i < L / 2 - n; i++ )
     219             :             {
     220  5320442694 :                 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  6881440692 :             for ( i = L / 2 - n; i < L / 2; i++ )
     224             :             {
     225  6840569178 :                 paout[L / 2 + i] = -ImdctOut[L - 1 - i] + OldauOut[i + L / 2];
     226             :             }
     227             :         }
     228             : 
     229 12201918793 :         for ( i = 0; i < L / 2; i++ )
     230             :         {
     231 12161047072 :             OldauOut[L / 2 + i] = -ImdctOut[i] * win_left[( L / 2 - i - 1 ) * decimate + decay];
     232             :         }
     233             : 
     234             : 
     235  5361329815 :         for ( i = n; i < L / 2; i++ )
     236             :         {
     237  5320458094 :             OldauOut[i] = -ImdctOut[L / 2 - 1 - i] * win_left[( L - i ) * decimate - decay - 1];
     238             :         }
     239             :     }
     240             : 
     241 10273279067 :     for ( i = 0; i < n; i++ )
     242             :     {
     243 10213668018 :         OldauOut[i] = -ImdctOut[L / 2 - 1 - i];
     244             :     }
     245 10273279067 :     for ( i = 0; i < n; i++ )
     246             :     {
     247 10213668018 :         paout[L + i] = OldauOut[i];
     248             :     }
     249             : 
     250    59611049 :     return;
     251             : }
     252             : 
     253             : 
     254             : /*-------------------------------------------------------------------*
     255             :  * window_ola_ext()
     256             :  *
     257             :  *
     258             :  *-------------------------------------------------------------------*/
     259             : 
     260       15546 : 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       15546 :     const float sign_left = ( kernel_type & 1 ? 1.f : -1.f );
     271       15546 :     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       15546 :     n = (int16_t) ( (float) L * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
     281       15546 :     n16 = (int16_t) ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS );
     282       15546 :     windecay48 = (int16_t) ( 2 * ( (float) L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_48;
     283       15546 :     windecay16 = (int16_t) ( 2 * ( (float) L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_16;
     284       15546 :     decimate = 1;
     285       15546 :     decay = 0;
     286             : 
     287       15546 :     tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L );
     288             : 
     289       15546 :     if ( L == L_FRAME32k || L == L_FRAME16k )
     290             :     {
     291        8763 :         decimate = 3;
     292        8763 :         decay = 1;
     293             :     }
     294        6783 :     else if ( L == L_FRAME8k )
     295             :     {
     296           0 :         decimate = 6;
     297           0 :         decay = 2;
     298             :     }
     299             : 
     300        6783 :     else if ( L == 512 )
     301             :     {
     302        4345 :         windecay48 = (int16_t) ( 2 * ( (float) 512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS ) ) + R1_25;
     303        4345 :         decimate = 1;
     304        4345 :         decay = 0;
     305             :     }
     306        2438 :     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       15546 :     paout = auOut - n;
     314             : 
     315       15546 :     if ( L == L_FRAME32k )
     316             :     {
     317      182896 :         for ( i = n; i < L / 2; i += 2 )
     318             :         {
     319      180320 :             paout[i] = sign_right * ImdstOut[L / 2 + i] * win_right[( 2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) ) * decimate - 1 - decay - windecay48] + OldauOut[i];
     320      180320 :             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      182896 :         for ( i = 0; i < L / 2 - n; i += 2 )
     324             :         {
     325      180320 :             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      180320 :             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      234416 :         for ( i = L / 2 - n; i < L / 2; i += 2 )
     330             :         {
     331      231840 :             paout[L / 2 + i + 1] = -ImdstOut[L - 1 - ( i + 1 )] + OldauOut[i + L / 2 + 1];
     332      231840 :             paout[L / 2 + i] = -ImdstOut[L - 1 - i] + OldauOut[i + L / 2];
     333             :         }
     334             : 
     335      414736 :         for ( i = 0; i < L / 2; i += 2 )
     336             :         {
     337      412160 :             OldauOut[L / 2 + i + 1] = sign_left * ImdstOut[i + 1] * win_left[( L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay];
     338      412160 :             OldauOut[L / 2 + i] = sign_left * ImdstOut[i] * win_int_left[( L_FRAME16k / 2 - i / 2 - 1 )];
     339             :         }
     340             : 
     341             : 
     342      182896 :         for ( i = n; i < L / 2; i += 2 )
     343             :         {
     344      180320 :             OldauOut[i] = -ImdstOut[L / 2 - 1 - i] * win_left[( L_FRAME16k - i / 2 ) * decimate - decay - 1];
     345      180320 :             OldauOut[i + 1] = -ImdstOut[L / 2 - 1 - ( i + 1 )] * win_int_left[L_FRAME16k - ( i / 2 ) - 1];
     346             :         }
     347             :     }
     348             :     else
     349             :     {
     350     1444680 :         for ( i = n; i < L / 2; i++ )
     351             :         {
     352     1431710 :             paout[i] = sign_right * ImdstOut[L / 2 + i] * win_right[( 2 * L - i ) * decimate - 1 - decay - windecay48] + OldauOut[i];
     353             :         }
     354             : 
     355     1444680 :         for ( i = 0; i < L / 2 - n; i++ )
     356             :         {
     357     1431710 :             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     1853740 :         for ( i = L / 2 - n; i < L / 2; i++ )
     361             :         {
     362     1840770 :             paout[L / 2 + i] = -ImdstOut[L - 1 - i] + OldauOut[i + L / 2];
     363             :         }
     364             : 
     365     3285450 :         for ( i = 0; i < L / 2; i++ )
     366             :         {
     367     3272480 :             OldauOut[L / 2 + i] = sign_left * ImdstOut[i] * win_left[( L / 2 - i - 1 ) * decimate + decay];
     368             :         }
     369             : 
     370             : 
     371     1444680 :         for ( i = n; i < L / 2; i++ )
     372             :         {
     373     1431710 :             OldauOut[i] = -ImdstOut[L / 2 - 1 - i] * win_left[( L - i ) * decimate - decay - 1];
     374             :         }
     375             :     }
     376             : 
     377     2319996 :     for ( i = 0; i < n; i++ )
     378             :     {
     379     2304450 :         OldauOut[i] = -ImdstOut[L / 2 - 1 - i];
     380             :     }
     381     2319996 :     for ( i = 0; i < n; i++ )
     382             :     {
     383     2304450 :         paout[L + i] = OldauOut[i];
     384             :     }
     385             : 
     386       15546 :     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         385 : 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         385 :     win = window_48kHz;
     414         385 :     win_int = window_8_16_32kHz;
     415         385 :     decimate = 1;
     416         385 :     decay = 0;
     417             : 
     418         385 :     if ( output_frame == L_FRAME32k || output_frame == L_FRAME16k )
     419             :     {
     420         162 :         decimate = 3;
     421         162 :         decay = 1;
     422             :     }
     423         223 :     else if ( output_frame == L_FRAME8k )
     424             :     {
     425          21 :         decimate = 6;
     426          21 :         decay = 2;
     427             :     }
     428             : 
     429             :     /* set multiplication factor according to the sampling rate */
     430         385 :     delta = 1;
     431         385 :     if ( output_frame == L_FRAME16k )
     432             :     {
     433          44 :         delta = 2;
     434             :     }
     435         341 :     else if ( output_frame == L_FRAME32k )
     436             :     {
     437         118 :         delta = 4;
     438             :     }
     439         223 :     else if ( output_frame == L_FRAME48k )
     440             :     {
     441         202 :         delta = 6;
     442             :     }
     443             : 
     444         385 :     set_f( tmp_buf_switch, 0, SWITCH_MAX_GAP );
     445         385 :     set_f( tmp_buf_switch2, 0, HQ_DELAY_COMP * HQ_DELTA_MAX + 2 );
     446             : 
     447         385 :     Loverlapp = (int16_t) ( delta * SWITCH_OVERLAP_8k );
     448             : 
     449         385 :     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         385 :     if ( last_L_frame == L_FRAME )
     453             :     {
     454             :         /* resample filter memory */
     455          78 :         if ( output_frame == L_FRAME8k )
     456             :         {
     457          11 :             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          67 :             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         204 :             for ( i = 0; i < filt_delay; i++ )
     464             :             {
     465         137 :                 tmp_buf_switch2[out_filt_length + i - filt_delay] = tmp_buf_switch2[out_filt_length - 1 - filt_delay];
     466             :             }
     467             : 
     468          67 :             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        2765 :                 for ( i = 0; i < out_filt_length; i++ )
     472             :                 {
     473        2700 :                     float a = (float) i / out_filt_length;
     474        2700 :                     float b = 1.f - a;
     475             : 
     476        2700 :                     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           2 :                 mvr2r( tmp_buf_switch2, tmp_buf_switch + NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS ), out_filt_length );
     483             :             }
     484             :         }
     485             :     }
     486             :     else
     487             :     {
     488         307 :         if ( output_frame == L_FRAME16k )
     489             :         {
     490             :             /* no resampling */
     491          42 :             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         265 :             if ( output_frame == L_FRAME8k )
     496             :             {
     497          10 :                 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         255 :                 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         707 :                 for ( i = 0; i < filt_delay; i++ )
     505             :                 {
     506         452 :                     tmp_buf_switch2[out_filt_length + i - filt_delay] = tmp_buf_switch2[out_filt_length - 1 - filt_delay];
     507             :                 }
     508             : 
     509         255 :                 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       14395 :                     for ( i = 0; i < out_filt_length; i++ )
     513             :                     {
     514       14140 :                         float a = (float) i / out_filt_length;
     515       14140 :                         float b = 1.f - a;
     516             : 
     517       14140 :                         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         385 :     L = NS2SA( output_Fs, SWITCH_GAP_LENGTH_NS + DELAY_CLDFB_NS ); /* 6.25 ms gap + 1.25 ms resamp  */
     531             : 
     532         385 :     set_f( synth, 0, L - Loverlapp );
     533             : 
     534         385 :     if ( output_frame == L_FRAME32k )
     535             :     {
     536        8378 :         for ( i = 0; i < NS2SA( output_Fs, 10000000.0f - N_ZERO_MDCT_NS ); i += 2 )
     537             :         {
     538        8260 :             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        8260 :             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       46502 :         for ( i = 0; i < NS2SA( output_Fs, 10000000.0f - N_ZERO_MDCT_NS ); i++ )
     545             :         {
     546       46235 :             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       27280 :     for ( i = 0; i < Loverlapp; i++ ) /* Windowing for overlapadd */
     552             :     {
     553       26895 :         synth[i + (int16_t) ( L - Loverlapp )] *= (float) sin( ( i + 1 ) * EVS_PI / ( 2 * ( Loverlapp + 1 ) ) );
     554       26895 :         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       26895 :         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       18315 :     for ( i = 0; i < NS2SA( output_Fs, DELAY_CLDFB_NS ); i++ )
     560             :     {
     561       17930 :         synth[i] += tmp_buf_switch[i];
     562             :     }
     563       90035 :     for ( i = NS2SA( output_Fs, DELAY_CLDFB_NS ); i < L; i++ )
     564             :     {
     565       89650 :         synth[i] += tmp_buf_switch[i] + synth_subfr_bwe[i - NS2SA( output_Fs, DELAY_CLDFB_NS )];
     566             :     }
     567             : 
     568         385 :     return;
     569             : }
     570             : 
     571             : 
     572             : /*-------------------------------------------------------------------*
     573             :  * sinq()
     574             :  *
     575             :  * Fast sinus generate sin(tmp*i+phi)
     576             :  *-------------------------------------------------------------------*/
     577             : 
     578       14030 : 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       14030 :     x[0] = (float) sin( phi );
     589       14030 :     x[1] = (float) sin( tmp + phi );
     590       14030 :     x[2] = (float) sin( 2 * tmp + phi );
     591             : 
     592       14030 :     if ( fabs( (float) ( tmp ) ) > 0.0001f )
     593             :     {
     594       14030 :         A = ( x[2] + x[0] ) / x[1];
     595             :     }
     596             :     else
     597             :     {
     598           0 :         A = 0;
     599             :     }
     600             : 
     601      797273 :     for ( i = 3; i < N; i++ )
     602             :     {
     603      783243 :         x[i] = A * x[i - 1] - x[i - 2];
     604             :     }
     605             : 
     606       14030 :     return;
     607             : }

Generated by: LCOV version 1.14