LCOV - code coverage report
Current view: top level - lib_com - edct.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 867217ee32c8e8cd2cf5aae69e60c58e00160b49 Lines: 152 154 98.7 %
Date: 2025-12-13 06:47:12 Functions: 5 5 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 "cnst.h"
      43             : #include "rom_com.h"
      44             : #include "prot.h"
      45             : #include "wmc_auto.h"
      46             : #include <math.h> /* for cosf, sinf */
      47             : #include <assert.h>
      48             : 
      49    40491852 : static ivas_error get_edct_table(
      50             :     const float **edct_table,
      51             :     const int16_t length )
      52             : {
      53             :     ivas_error error;
      54             : 
      55    40491852 :     error = IVAS_ERR_OK;
      56    40491852 :     *edct_table = NULL;
      57             : 
      58    40491852 :     switch ( length )
      59             :     {
      60      112625 :         case 1200:
      61      112625 :             *edct_table = edct_table_600;
      62      112625 :             break;
      63    10958759 :         case 960:
      64    10958759 :             *edct_table = edct_table_480;
      65    10958759 :             break;
      66    10265624 :         case 640:
      67    10265624 :             *edct_table = edct_table_320;
      68    10265624 :             break;
      69     9734138 :         case 320:
      70     9734138 :             *edct_table = edct_table_160;
      71     9734138 :             break;
      72     2959411 :         case 256:
      73     2959411 :             *edct_table = edct_table_128;
      74     2959411 :             break;
      75      610811 :         case 240:
      76      610811 :             *edct_table = edct_table_120;
      77      610811 :             break;
      78          12 :         case 200:
      79          12 :             *edct_table = edct_table_100;
      80          12 :             break;
      81      931914 :         case 160:
      82      931914 :             *edct_table = edct_table_80;
      83      931914 :             break;
      84          96 :         case 40:
      85          96 :             *edct_table = edct_table_20;
      86          96 :             break;
      87       47136 :         case 800:
      88       47136 :             *edct_table = edct_table_400;
      89       47136 :             break;
      90     3689246 :         case 512:
      91     3689246 :             *edct_table = edct_table_256;
      92     3689246 :             break;
      93      289720 :         case 480:
      94      289720 :             *edct_table = edct_table_240;
      95      289720 :             break;
      96      137736 :         case 400:
      97      137736 :             *edct_table = edct_table_200;
      98      137736 :             break;
      99      278190 :         case 128:
     100      278190 :             *edct_table = edct_table_64;
     101      278190 :             break;
     102      476434 :         case 80:
     103      476434 :             *edct_table = edct_table_40;
     104      476434 :             break;
     105             : #ifdef DEBUGGING
     106             :         default:
     107             :             return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "edct/edst(): length is not in table!" );
     108             : #endif
     109             :     }
     110             : 
     111    40491852 :     return error;
     112             : }
     113             : 
     114             : 
     115             : /*-----------------------------------------------------------------*
     116             :  * edct()
     117             :  *
     118             :  * DCT-IV transform
     119             :  *-----------------------------------------------------------------*/
     120             : 
     121    37755623 : void edct(
     122             :     const float *x,            /* i  : input signal        */
     123             :     float *y,                  /* o  : output transform    */
     124             :     const int16_t length,      /* i  : length              */
     125             :     const int16_t element_mode /* i  : IVAS element mode   */
     126             : )
     127             : {
     128             :     int16_t i;
     129             :     float re[L_FRAME_PLUS / 2];
     130             :     float im[L_FRAME_PLUS / 2];
     131    37755623 :     const float *edct_table = 0;
     132             :     float local;
     133             : 
     134    37755623 :     get_edct_table( &edct_table, length );
     135             : 
     136             :     /* Twiddling and Pre-rotate */
     137 10686802235 :     for ( i = 0; i < length / 2; i++ )
     138             :     {
     139 10649046612 :         re[i] = x[2 * i] * edct_table[i] + x[length - 1 - 2 * i] * edct_table[length / 2 - 1 - i];
     140 10649046612 :         im[i] = x[length - 1 - 2 * i] * edct_table[i] - x[2 * i] * edct_table[length / 2 - 1 - i];
     141             :     }
     142             : 
     143    37755623 :     if ( element_mode == EVS_MONO )
     144             :     {
     145      387400 :         DoFFT( re, im, length / 2 );
     146             :     }
     147             :     else
     148             :     {
     149    37368223 :         fft( re, im, length / 2, 1 );
     150             :     }
     151             : 
     152    37755623 :     local = ( 0.75f * EVS_PI ) / length;
     153             : 
     154 10686802235 :     for ( i = 0; i < length / 2; i++ )
     155             :     {
     156             :         float tmp;
     157 10649046612 :         tmp = re[i] - im[i] * local; /* 3*pi/(4*length) is a constant */
     158 10649046612 :         im[i] = im[i] + re[i] * local;
     159 10649046612 :         re[i] = tmp;
     160             :     }
     161             : 
     162             :     /* Post-rotate and obtain the output data */
     163 10686802235 :     for ( i = 0; i < length / 2; i++ )
     164             :     {
     165 10649046612 :         y[2 * i] = re[i] * edct_table[i] + im[i] * edct_table[length / 2 - 1 - i];
     166 10649046612 :         y[length - 1 - 2 * i] = re[i] * edct_table[length / 2 - 1 - i] - im[i] * edct_table[i];
     167             :     }
     168             : 
     169    37755623 :     return;
     170             : }
     171             : 
     172             : 
     173             : /*-------------------------------------------------------------------------*
     174             :  * edst()
     175             :  *
     176             :  * DST-IV transform
     177             :  *-------------------------------------------------------------------------*/
     178             : 
     179     2736229 : void edst(
     180             :     const float *x,            /* i  : input signal        */
     181             :     float *y,                  /* o  : output transform    */
     182             :     const int16_t length,      /* i  : length              */
     183             :     const int16_t element_mode /* i  : IVAS element mode   */
     184             : )
     185             : {
     186             :     int16_t i;
     187             :     float re[L_FRAME_PLUS / 2];
     188             :     float im[L_FRAME_PLUS / 2];
     189     2736229 :     const float *edct_table = 0;
     190             :     float local;
     191             : 
     192     2736229 :     get_edct_table( &edct_table, length );
     193             : 
     194             :     /* Twiddling and Pre-rotate */
     195  1147831761 :     for ( i = 0; i < length / 2; i++ )
     196             :     {
     197  1145095532 :         re[i] = x[length - 1 - 2 * i] * edct_table[i] + x[2 * i] * edct_table[length / 2 - 1 - i];
     198  1145095532 :         im[i] = x[2 * i] * edct_table[i] - x[length - 1 - 2 * i] * edct_table[length / 2 - 1 - i];
     199             :     }
     200             : 
     201     2736229 :     if ( element_mode == EVS_MONO )
     202             :     {
     203       64447 :         DoFFT( re, im, length / 2 );
     204             :     }
     205             :     else
     206             :     {
     207     2671782 :         fft( re, im, length / 2, 1 );
     208             :     }
     209             : 
     210     2736229 :     local = ( 0.75f * EVS_PI ) / length;
     211             : 
     212  1147831761 :     for ( i = 0; i < length / 2; i++ )
     213             :     {
     214             :         float tmp;
     215  1145095532 :         tmp = re[i] - im[i] * local; /* 3*pi/(4*length) is a constant */
     216  1145095532 :         im[i] = im[i] + re[i] * local;
     217  1145095532 :         re[i] = tmp;
     218             :     }
     219             : 
     220             :     /* Post-rotate and obtain the output data */
     221  1147831761 :     for ( i = 0; i < length / 2; i++ )
     222             :     {
     223  1145095532 :         y[2 * i] = re[i] * edct_table[i] + im[i] * edct_table[length / 2 - 1 - i];
     224  1145095532 :         y[length - 1 - 2 * i] = im[i] * edct_table[i] - re[i] * edct_table[length / 2 - 1 - i];
     225             :     }
     226             : 
     227     2736229 :     return;
     228             : }
     229             : 
     230             : 
     231             : /*-------------------------------------------------------------------------*
     232             :  * edxt()
     233             :  *
     234             :  * DCT/DST-II or III transform (currently also calculates DCT-IV and DST-IV)
     235             :  *-------------------------------------------------------------------------*/
     236             : 
     237        7368 : void edxt(
     238             :     const float *x,            /* i  : input signal        */
     239             :     float *y,                  /* o  : output transform    */
     240             :     const int16_t length,      /* i  : length              */
     241             :     const uint16_t kernelType, /* i  : kernel type (0 - 3) */
     242             :     const uint16_t synthesis   /* i  : nonzero for inverse */
     243             : )
     244             : {
     245        7368 :     const float pi_len = EVS_PI / length;
     246             :     int16_t k;
     247             : 
     248        7368 :     if ( kernelType == MDST_II || kernelType == MDCT_II )
     249        7368 :     {
     250        7368 :         const int16_t Nm1 = length - 1;
     251        7368 :         const float xSign = 2.f * ( kernelType >> 1 ) - 1.f;
     252        7368 :         const float scale = 0.5f * pi_len;
     253             :         float re[L_FRAME_PLUS];
     254             :         float im[L_FRAME_PLUS];
     255             : 
     256        7368 :         if ( !synthesis )
     257             :         {
     258      246174 :             for ( k = Nm1 >> 1; k >= 0; k-- ) /* pre-modulation of audio input */
     259             :             {
     260      245400 :                 re[k] = x[2 * k];
     261      245400 :                 re[Nm1 - k] = x[2 * k + 1] * xSign;
     262      245400 :                 im[k] = im[Nm1 - k] = 0.f;
     263             :             }
     264             : 
     265         774 :             if ( length == 512 )
     266             :             {
     267           0 :                 DoRTFTn( re, im, 512 );
     268             :             }
     269             :             else /* fft() doesn't support 512 */
     270             :             {
     271         774 :                 fft( re, im, length, 1 );
     272             :             }
     273             : 
     274         774 :             if ( kernelType >> 1 )
     275             :             {
     276      123400 :                 for ( k = Nm1 >> 1; k > 0; k-- )
     277             :                 {
     278      123014 :                     volatile float angle_tmp = scale * k;
     279      123014 :                     const float wRe = cosf( angle_tmp );
     280      123014 :                     const float wIm = sinf( angle_tmp );
     281             : 
     282      123014 :                     y[k] /*pt 1*/ = wRe * re[k] + wIm * im[k];
     283      123014 :                     y[length - k] = wIm * re[k] - wRe * im[k];
     284             :                 }
     285         386 :                 y[length >> 1] = re[length >> 1] * sqrtf( 0.5f );
     286             :             }
     287             :             else /* forw. DST-II */
     288             :             {
     289      122000 :                 for ( k = Nm1 >> 1; k > 0; k-- )
     290             :                 {
     291      121612 :                     volatile float angle_tmp = scale * k;
     292      121612 :                     const float wRe = cosf( angle_tmp );
     293      121612 :                     const float wIm = sinf( angle_tmp );
     294             : 
     295      121612 :                     y[Nm1 - k] = wRe * re[k] + wIm * im[k];
     296      121612 :                     y[k - 1] = wIm * re[k] - wRe * im[k];
     297             :                 }
     298         388 :                 y[Nm1 >> 1] = re[length >> 1] * sqrtf( 0.5f );
     299             :             }
     300             : 
     301         774 :             y[Nm1 - Nm1 * ( kernelType >> 1 )] = re[0] * 0.5f;
     302             :         }
     303             :         else /* inverse II = III */
     304             :         {
     305        6594 :             if ( kernelType >> 1 )
     306             :             {
     307      950840 :                 for ( k = Nm1 >> 1; k > 0; k-- )
     308             :                 {
     309      947404 :                     volatile float angle_tmp = scale * k;
     310      947404 :                     const float wRe = cosf( angle_tmp ) * 0.5f;
     311      947404 :                     const float wIm = sinf( angle_tmp ) * 0.5f;
     312             : 
     313      947404 :                     re[k] = wRe * x[k] + wIm * x[length - k];
     314      947404 :                     im[k] = wRe * x[length - k] - wIm * x[k];
     315             :                 }
     316        3436 :                 re[length >> 1] = x[length >> 1] * sqrtf( 0.5f );
     317             :             }
     318             :             else /* DST type III */
     319             :             {
     320      818384 :                 for ( k = Nm1 >> 1; k > 0; k-- )
     321             :                 {
     322      815226 :                     volatile float angle_tmp = scale * k;
     323      815226 :                     const float wRe = cosf( angle_tmp ) * 0.5f;
     324      815226 :                     const float wIm = sinf( angle_tmp ) * 0.5f;
     325             : 
     326      815226 :                     re[k] = wRe * x[Nm1 - k] + wIm * x[k - 1];
     327      815226 :                     im[k] = wRe * x[k - 1] - wIm * x[Nm1 - k];
     328             :                 }
     329        3158 :                 re[length >> 1] = x[Nm1 >> 1] * sqrtf( 0.5f );
     330             :             }
     331             : 
     332        6594 :             re[0] = x[Nm1 - Nm1 * ( kernelType >> 1 )];
     333        6594 :             im[0] = im[length >> 1] = 0.f;
     334     1769224 :             for ( k = Nm1 >> 1; k > 0; k-- )
     335             :             {
     336     1762630 :                 re[length - k] = re[k];
     337     1762630 :                 im[length - k] = -im[k];
     338             :             }
     339             : 
     340        6594 :             if ( length == 512 )
     341             :             {
     342        2094 :                 DoRTFTn( re, im, 512 );
     343             :             }
     344             :             else /* fft() doesn't support 512 */
     345             :             {
     346        4500 :                 fft( re, im, length, 1 );
     347             :             }
     348             : 
     349     1775818 :             for ( k = Nm1 >> 1; k >= 0; k-- ) /* post-modulation of FFT output */
     350             :             {
     351     1769224 :                 y[2 * k] = re[k];
     352     1769224 :                 y[2 * k + 1] = re[Nm1 - k] * xSign;
     353             :             }
     354             :         }
     355             :     }
     356             :     else
     357             :     {
     358           0 :         assert( !"Unsupported Kernel type in edxt()" );
     359             :     }
     360             : 
     361        7368 :     v_multc( y, ( kernelType == MDCT_II ? -1.f : 1.f ) * sqrtf( 2.f / length ), y, length );
     362             : 
     363        7368 :     return;
     364             : }
     365             : 
     366             : /*-----------------------------------------------------------------*
     367             :  * iedct_short()
     368             :  *
     369             :  * Inverse EDCT for short frames
     370             :  *-----------------------------------------------------------------*/
     371             : 
     372       31612 : void iedct_short(
     373             :     const float *in,              /* i  : input vector          */
     374             :     float *out,                   /* o  : output vector         */
     375             :     const int16_t segment_length, /* i  : length                */
     376             :     const int16_t element_mode    /* i  : IVAS element mode     */
     377             : )
     378             : {
     379             :     float alias[MAX_SEGMENT_LENGTH];
     380             :     int16_t i;
     381             : 
     382       31612 :     edct( in, alias, segment_length / 2, element_mode );
     383             : 
     384     2270332 :     for ( i = 0; i < segment_length / 4; i++ )
     385             :     {
     386     2238720 :         out[i] = alias[segment_length / 4 + i];
     387     2238720 :         out[segment_length / 4 + i] = -alias[segment_length / 2 - 1 - i];
     388     2238720 :         out[segment_length / 2 + i] = -alias[segment_length / 4 - 1 - i];
     389     2238720 :         out[3 * segment_length / 4 + i] = -alias[i];
     390             :     }
     391             : 
     392       31612 :     return;
     393             : }

Generated by: LCOV version 1.14