LCOV - code coverage report
Current view: top level - lib_com - ifft_rel.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 126 129 97.7 %
Date: 2025-05-23 08:37:30 Functions: 1 1 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 "prot.h"
      43             : #include "rom_com.h"
      44             : #include "wmc_auto.h"
      45             : 
      46             : /*-----------------------------------------------------------------*
      47             :  * Local constants
      48             :  *-----------------------------------------------------------------*/
      49             : 
      50             : #define N_MAX_FFT 1024
      51             : 
      52             : /*---------------------------------------------------------------------*
      53             :  * ifft_rel()
      54             :  *
      55             :  * Calculate the inverse FFT of a real signal
      56             :  *
      57             :  * Based on the FORTRAN code from the article "Real-valued Fast Fourier Transform Algorithms"
      58             :  * by Sorensen, ... in IEEE Trans. on ASSP, Vol. ASSP-35, No. June 6th 1987.
      59             :  *
      60             :  * Input: the io[] signal containing the spectrum in the following order :
      61             :  *
      62             :  * Re[0], Re[1], ..  Re[n/2], Im[n/2-1], .. Im[1]
      63             :  *---------------------------------------------------------------------*/
      64             : 
      65      337682 : void ifft_rel(
      66             :     float io[],      /* i/o: input/output vector   */
      67             :     const int16_t n, /* i  : vector length         */
      68             :     const int16_t m  /* i  : log2 of vector length */
      69             : )
      70             : {
      71             :     int16_t i, j, k;
      72             :     int16_t step;
      73             :     int16_t n2, n4, n8, i0;
      74             :     int16_t is, id;
      75             :     float *x, *xi0, *xi1, *xi2, *xi3, *xi4, *xup1, *xdn6, *xup3, *xdn8;
      76             :     float xt;
      77             :     float r1;
      78             :     float t1, t2, t3, t4, t5;
      79             :     float cc1, cc3, ss1, ss3;
      80             :     const float *s, *s3, *c, *c3;
      81             :     const int16_t *idx;
      82             :     float temp[512];
      83             :     float n_inv;
      84             : 
      85      337682 :     n_inv = 1.0f / n;
      86             : 
      87             :     /*-----------------------------------------------------------------*
      88             :      * IFFT
      89             :      *-----------------------------------------------------------------*/
      90             : 
      91      337682 :     x = &io[-1];
      92      337682 :     n2 = 2 * n;
      93     2358038 :     for ( k = 1; k < m; k++ )
      94             :     {
      95     2020356 :         is = 0;
      96     2020356 :         id = n2;
      97     2020356 :         n2 = n2 >> 1;
      98     2020356 :         n4 = n2 >> 2;
      99     2020356 :         n8 = n4 >> 1;
     100     6507825 :         while ( is < n - 1 )
     101             :         {
     102     4487469 :             xi1 = x + is + 1;
     103     4487469 :             xi2 = xi1 + n4;
     104     4487469 :             xi3 = xi2 + n4;
     105     4487469 :             xi4 = xi3 + n4;
     106             : 
     107    35431035 :             for ( i = is; i < n; i += id )
     108             :             {
     109    30943566 :                 t1 = *xi1 - *xi3;
     110    30943566 :                 *xi1 += *xi3;
     111    30943566 :                 *xi2 = 2.0f * *xi2;
     112    30943566 :                 *xi3 = t1 - 2.0f * *xi4;
     113    30943566 :                 *xi4 = t1 + 2.0f * *xi4;
     114    30943566 :                 if ( n4 != 1 )
     115             :                 {
     116    15414256 :                     t1 = ( *( xi2 + n8 ) - *( xi1 + n8 ) ) * INV_SQRT_2;
     117    15414256 :                     t2 = ( *( xi4 + n8 ) + *( xi3 + n8 ) ) * INV_SQRT_2;
     118             : 
     119    15414256 :                     *( xi1 + n8 ) += *( xi2 + n8 );
     120    15414256 :                     *( xi2 + n8 ) = *( xi4 + n8 ) - *( xi3 + n8 );
     121    15414256 :                     *( xi3 + n8 ) = (float) ( 2.0f * ( -t2 - t1 ) );
     122    15414256 :                     *( xi4 + n8 ) = (float) ( 2.0f * ( -t2 + t1 ) );
     123             :                 }
     124    30943566 :                 xi1 += id;
     125    30943566 :                 xi2 += id;
     126    30943566 :                 xi3 += id;
     127    30943566 :                 xi4 += id;
     128             :             }
     129     4487469 :             is = 2 * id - n2;
     130     4487469 :             id = 4 * id;
     131             :         }
     132     2020356 :         step = N_MAX_FFT / n2;
     133             : 
     134     2020356 :         s = sincos_t_ext + step;
     135     2020356 :         c = s + N_MAX_FFT / 4;
     136     2020356 :         s3 = sincos_t_ext + 3 * step;
     137     2020356 :         c3 = s3 + N_MAX_FFT / 4;
     138    23347752 :         for ( j = 2; j <= n8; j++ )
     139             :         {
     140    21327396 :             cc1 = *c;
     141    21327396 :             ss1 = *s;
     142    21327396 :             cc3 = *c3;
     143    21327396 :             ss3 = *s3;
     144             : 
     145    21327396 :             is = 0;
     146    21327396 :             id = 2 * n2;
     147             : 
     148    21327396 :             c += step;
     149    21327396 :             s += step;
     150             : 
     151    21327396 :             c3 += 3 * step;
     152    21327396 :             s3 += 3 * step;
     153    47783493 :             while ( is < n - 1 )
     154             :             {
     155    26456097 :                 xup1 = x + j + is;
     156    26456097 :                 xup3 = xup1 + 2 * n4;
     157    26456097 :                 xdn6 = xup3 - 2 * j + 2;
     158    26456097 :                 xdn8 = xdn6 + 2 * n4;
     159             : 
     160    66033687 :                 for ( i = is; i < n; i += id )
     161             :                 {
     162    39577590 :                     t1 = *xup1 - *xdn6;
     163    39577590 :                     *xup1 = *xup1 + *xdn6;
     164    39577590 :                     xup1 += n4;
     165    39577590 :                     xdn6 -= n4;
     166             : 
     167    39577590 :                     t2 = *xdn6 - *xup1;
     168    39577590 :                     *xdn6 = *xup1 + *xdn6;
     169             : 
     170    39577590 :                     xdn6 += n4;
     171    39577590 :                     t3 = *xdn8 + *xup3;
     172    39577590 :                     *xdn6 = *xdn8 - *xup3;
     173             : 
     174    39577590 :                     xup3 += n4;
     175    39577590 :                     xdn8 -= n4;
     176             : 
     177    39577590 :                     t4 = *xup3 + *xdn8;
     178    39577590 :                     *xup1 = *xup3 - *xdn8;
     179             : 
     180    39577590 :                     t5 = t1 - t4;
     181    39577590 :                     t1 = t1 + t4;
     182    39577590 :                     t4 = t2 - t3;
     183    39577590 :                     t2 = t2 + t3;
     184    39577590 :                     *xup3 = t1 * cc3 - t2 * ss3;
     185    39577590 :                     xup3 -= n4;
     186    39577590 :                     *xup3 = t5 * cc1 + t4 * ss1;
     187    39577590 :                     *xdn8 = -t4 * cc1 + t5 * ss1;
     188             : 
     189    39577590 :                     xdn8 += n4;
     190    39577590 :                     *xdn8 = t2 * cc3 + t1 * ss3;
     191             : 
     192    39577590 :                     xup1 -= n4;
     193    39577590 :                     xup1 += id;
     194    39577590 :                     xup3 += id;
     195    39577590 :                     xdn6 += id;
     196    39577590 :                     xdn8 += id;
     197             :                 }
     198    26456097 :                 is = 2 * id - n2;
     199    26456097 :                 id = 4 * id;
     200             :             }
     201             :         }
     202             :     }
     203             : 
     204             :     /*-----------------------------------------------------------------*
     205             :      * Length two butterflies
     206             :      *-----------------------------------------------------------------*/
     207             : 
     208      337682 :     is = 1;
     209      337682 :     id = 4;
     210     1628015 :     while ( is < n )
     211             :     {
     212     1290333 :         xi0 = x + is;
     213     1290333 :         xi1 = xi0 + 1;
     214             : 
     215    32456527 :         for ( i0 = is; i0 <= n; i0 += id )
     216             :         {
     217    31166194 :             r1 = *xi0;
     218    31166194 :             *xi0 = r1 + *xi1;
     219    31166194 :             *xi1 = r1 - *xi1;
     220    31166194 :             xi0 += id;
     221    31166194 :             xi1 += id;
     222             :         }
     223     1290333 :         is = 2 * id - 1;
     224     1290333 :         id = 4 * id;
     225             :     }
     226             : 
     227             :     /*-----------------------------------------------------------------*
     228             :      * Digit reverse counter
     229             :      *-----------------------------------------------------------------*/
     230             : 
     231      337682 :     idx = fft256_read_indexes;
     232      337682 :     xi0 = &temp[0] - 1;
     233      337682 :     if ( n == 128 )
     234             :     {
     235           0 :         for ( i = 0; i < n; i++ )
     236             :         {
     237           0 :             j = *idx++;
     238           0 :             temp[i] = x[1 + ( j >> 1 )];
     239             :         }
     240             :     }
     241      337682 :     else if ( n == 256 )
     242             :     {
     243     1690289 :         for ( i = 0; i < n; i++ )
     244             :         {
     245     1683712 :             j = *idx++;
     246     1683712 :             temp[i] = x[1 + j];
     247             :         }
     248             :     }
     249      331105 :     else if ( n == 512 )
     250             :     {
     251    42234352 :         for ( i = 0; i < 256; i++ )
     252             :         {
     253    42070016 :             j = *idx++;
     254    42070016 :             temp[i] = x[1 + 2 * j];
     255    42070016 :             temp[i + 256] = x[2 + 2 * j];
     256             :         }
     257             :     }
     258             :     else
     259             :     {
     260      166769 :         xi0 = x;
     261      166769 :         j = 1;
     262     7567264 :         for ( i = 1; i < n; i++ )
     263             :         {
     264     7400495 :             if ( i < j )
     265             :             {
     266     3231160 :                 xt = x[j];
     267     3231160 :                 x[j] = x[i];
     268     3231160 :                 x[i] = xt;
     269             :             }
     270     7400495 :             k = n >> 1;
     271    13974592 :             while ( k < j )
     272             :             {
     273     6574097 :                 j = j - k;
     274     6574097 :                 k = k >> 1;
     275             :             }
     276     7400495 :             j = j + k;
     277             :         }
     278             :     }
     279             : 
     280             :     /*-----------------------------------------------------------------*
     281             :      * Normalization
     282             :      *-----------------------------------------------------------------*/
     283             : 
     284    93728690 :     for ( i = 1; i <= n; i++ )
     285             :     {
     286    93391008 :         x[i] = xi0[i] * n_inv;
     287             :     }
     288             : 
     289      337682 :     return;
     290             : }

Generated by: LCOV version 1.14