LCOV - code coverage report
Current view: top level - lib_com - edct.c (source / functions) Hit Total Coverage
Test: Coverage on main -- long test vectors @ 0c5691e6405a865cd50088c4936e8acb16f658a1 Lines: 152 154 98.7 %
Date: 2025-12-18 05:48:39 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   112600617 : static ivas_error get_edct_table(
      50             :     const float **edct_table,
      51             :     const int16_t length )
      52             : {
      53             :     ivas_error error;
      54             : 
      55   112600617 :     error = IVAS_ERR_OK;
      56   112600617 :     *edct_table = NULL;
      57             : 
      58   112600617 :     switch ( length )
      59             :     {
      60      336580 :         case 1200:
      61      336580 :             *edct_table = edct_table_600;
      62      336580 :             break;
      63    40744852 :         case 960:
      64    40744852 :             *edct_table = edct_table_480;
      65    40744852 :             break;
      66    25288419 :         case 640:
      67    25288419 :             *edct_table = edct_table_320;
      68    25288419 :             break;
      69    17250723 :         case 320:
      70    17250723 :             *edct_table = edct_table_160;
      71    17250723 :             break;
      72    10625060 :         case 256:
      73    10625060 :             *edct_table = edct_table_128;
      74    10625060 :             break;
      75     1566401 :         case 240:
      76     1566401 :             *edct_table = edct_table_120;
      77     1566401 :             break;
      78          79 :         case 200:
      79          79 :             *edct_table = edct_table_100;
      80          79 :             break;
      81     2034094 :         case 160:
      82     2034094 :             *edct_table = edct_table_80;
      83     2034094 :             break;
      84         392 :         case 40:
      85         392 :             *edct_table = edct_table_20;
      86         392 :             break;
      87      121539 :         case 800:
      88      121539 :             *edct_table = edct_table_400;
      89      121539 :             break;
      90    12358048 :         case 512:
      91    12358048 :             *edct_table = edct_table_256;
      92    12358048 :             break;
      93      717636 :         case 480:
      94      717636 :             *edct_table = edct_table_240;
      95      717636 :             break;
      96      442368 :         case 400:
      97      442368 :             *edct_table = edct_table_200;
      98      442368 :             break;
      99      722713 :         case 128:
     100      722713 :             *edct_table = edct_table_64;
     101      722713 :             break;
     102      391713 :         case 80:
     103      391713 :             *edct_table = edct_table_40;
     104      391713 :             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   112600617 :     return error;
     112             : }
     113             : 
     114             : 
     115             : /*-----------------------------------------------------------------*
     116             :  * edct()
     117             :  *
     118             :  * DCT-IV transform
     119             :  *-----------------------------------------------------------------*/
     120             : 
     121   100449245 : 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   100449245 :     const float *edct_table = 0;
     132             :     float local;
     133             : 
     134   100449245 :     get_edct_table( &edct_table, length );
     135             : 
     136             :     /* Twiddling and Pre-rotate */
     137 30998250601 :     for ( i = 0; i < length / 2; i++ )
     138             :     {
     139 30897801356 :         re[i] = x[2 * i] * edct_table[i] + x[length - 1 - 2 * i] * edct_table[length / 2 - 1 - i];
     140 30897801356 :         im[i] = x[length - 1 - 2 * i] * edct_table[i] - x[2 * i] * edct_table[length / 2 - 1 - i];
     141             :     }
     142             : 
     143   100449245 :     if ( element_mode == EVS_MONO )
     144             :     {
     145      934519 :         DoFFT( re, im, length / 2 );
     146             :     }
     147             :     else
     148             :     {
     149    99514726 :         fft( re, im, length / 2, 1 );
     150             :     }
     151             : 
     152   100449245 :     local = ( 0.75f * EVS_PI ) / length;
     153             : 
     154 30998250601 :     for ( i = 0; i < length / 2; i++ )
     155             :     {
     156             :         float tmp;
     157 30897801356 :         tmp = re[i] - im[i] * local; /* 3*pi/(4*length) is a constant */
     158 30897801356 :         im[i] = im[i] + re[i] * local;
     159 30897801356 :         re[i] = tmp;
     160             :     }
     161             : 
     162             :     /* Post-rotate and obtain the output data */
     163 30998250601 :     for ( i = 0; i < length / 2; i++ )
     164             :     {
     165 30897801356 :         y[2 * i] = re[i] * edct_table[i] + im[i] * edct_table[length / 2 - 1 - i];
     166 30897801356 :         y[length - 1 - 2 * i] = re[i] * edct_table[length / 2 - 1 - i] - im[i] * edct_table[i];
     167             :     }
     168             : 
     169   100449245 :     return;
     170             : }
     171             : 
     172             : 
     173             : /*-------------------------------------------------------------------------*
     174             :  * edst()
     175             :  *
     176             :  * DST-IV transform
     177             :  *-------------------------------------------------------------------------*/
     178             : 
     179    12151372 : 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    12151372 :     const float *edct_table = 0;
     190             :     float local;
     191             : 
     192    12151372 :     get_edct_table( &edct_table, length );
     193             : 
     194             :     /* Twiddling and Pre-rotate */
     195  4971860076 :     for ( i = 0; i < length / 2; i++ )
     196             :     {
     197  4959708704 :         re[i] = x[length - 1 - 2 * i] * edct_table[i] + x[2 * i] * edct_table[length / 2 - 1 - i];
     198  4959708704 :         im[i] = x[2 * i] * edct_table[i] - x[length - 1 - 2 * i] * edct_table[length / 2 - 1 - i];
     199             :     }
     200             : 
     201    12151372 :     if ( element_mode == EVS_MONO )
     202             :     {
     203      203085 :         DoFFT( re, im, length / 2 );
     204             :     }
     205             :     else
     206             :     {
     207    11948287 :         fft( re, im, length / 2, 1 );
     208             :     }
     209             : 
     210    12151372 :     local = ( 0.75f * EVS_PI ) / length;
     211             : 
     212  4971860076 :     for ( i = 0; i < length / 2; i++ )
     213             :     {
     214             :         float tmp;
     215  4959708704 :         tmp = re[i] - im[i] * local; /* 3*pi/(4*length) is a constant */
     216  4959708704 :         im[i] = im[i] + re[i] * local;
     217  4959708704 :         re[i] = tmp;
     218             :     }
     219             : 
     220             :     /* Post-rotate and obtain the output data */
     221  4971860076 :     for ( i = 0; i < length / 2; i++ )
     222             :     {
     223  4959708704 :         y[2 * i] = re[i] * edct_table[i] + im[i] * edct_table[length / 2 - 1 - i];
     224  4959708704 :         y[length - 1 - 2 * i] = im[i] * edct_table[i] - re[i] * edct_table[length / 2 - 1 - i];
     225             :     }
     226             : 
     227    12151372 :     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       24962 : 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       24962 :     const float pi_len = EVS_PI / length;
     246             :     int16_t k;
     247             : 
     248       24962 :     if ( kernelType == MDST_II || kernelType == MDCT_II )
     249       24962 :     {
     250       24962 :         const int16_t Nm1 = length - 1;
     251       24962 :         const float xSign = 2.f * ( kernelType >> 1 ) - 1.f;
     252       24962 :         const float scale = 0.5f * pi_len;
     253             :         float re[L_FRAME_PLUS];
     254             :         float im[L_FRAME_PLUS];
     255             : 
     256       24962 :         if ( !synthesis )
     257             :         {
     258     1082732 :             for ( k = Nm1 >> 1; k >= 0; k-- ) /* pre-modulation of audio input */
     259             :             {
     260     1079160 :                 re[k] = x[2 * k];
     261     1079160 :                 re[Nm1 - k] = x[2 * k + 1] * xSign;
     262     1079160 :                 im[k] = im[Nm1 - k] = 0.f;
     263             :             }
     264             : 
     265        3572 :             if ( length == 512 )
     266             :             {
     267           0 :                 DoRTFTn( re, im, 512 );
     268             :             }
     269             :             else /* fft() doesn't support 512 */
     270             :             {
     271        3572 :                 fft( re, im, length, 1 );
     272             :             }
     273             : 
     274        3572 :             if ( kernelType >> 1 )
     275             :             {
     276      538160 :                 for ( k = Nm1 >> 1; k > 0; k-- )
     277             :                 {
     278      536382 :                     volatile float angle_tmp = scale * k;
     279      536382 :                     const float wRe = cosf( angle_tmp );
     280      536382 :                     const float wIm = sinf( angle_tmp );
     281             : 
     282      536382 :                     y[k] /*pt 1*/ = wRe * re[k] + wIm * im[k];
     283      536382 :                     y[length - k] = wIm * re[k] - wRe * im[k];
     284             :                 }
     285        1778 :                 y[length >> 1] = re[length >> 1] * sqrtf( 0.5f );
     286             :             }
     287             :             else /* forw. DST-II */
     288             :             {
     289      541000 :                 for ( k = Nm1 >> 1; k > 0; k-- )
     290             :                 {
     291      539206 :                     volatile float angle_tmp = scale * k;
     292      539206 :                     const float wRe = cosf( angle_tmp );
     293      539206 :                     const float wIm = sinf( angle_tmp );
     294             : 
     295      539206 :                     y[Nm1 - k] = wRe * re[k] + wIm * im[k];
     296      539206 :                     y[k - 1] = wIm * re[k] - wRe * im[k];
     297             :                 }
     298        1794 :                 y[Nm1 >> 1] = re[length >> 1] * sqrtf( 0.5f );
     299             :             }
     300             : 
     301        3572 :             y[Nm1 - Nm1 * ( kernelType >> 1 )] = re[0] * 0.5f;
     302             :         }
     303             :         else /* inverse II = III */
     304             :         {
     305       21390 :             if ( kernelType >> 1 )
     306             :             {
     307     2698440 :                 for ( k = Nm1 >> 1; k > 0; k-- )
     308             :                 {
     309     2687784 :                     volatile float angle_tmp = scale * k;
     310     2687784 :                     const float wRe = cosf( angle_tmp ) * 0.5f;
     311     2687784 :                     const float wIm = sinf( angle_tmp ) * 0.5f;
     312             : 
     313     2687784 :                     re[k] = wRe * x[k] + wIm * x[length - k];
     314     2687784 :                     im[k] = wRe * x[length - k] - wIm * x[k];
     315             :                 }
     316       10656 :                 re[length >> 1] = x[length >> 1] * sqrtf( 0.5f );
     317             :             }
     318             :             else /* DST type III */
     319             :             {
     320     2701608 :                 for ( k = Nm1 >> 1; k > 0; k-- )
     321             :                 {
     322     2690874 :                     volatile float angle_tmp = scale * k;
     323     2690874 :                     const float wRe = cosf( angle_tmp ) * 0.5f;
     324     2690874 :                     const float wIm = sinf( angle_tmp ) * 0.5f;
     325             : 
     326     2690874 :                     re[k] = wRe * x[Nm1 - k] + wIm * x[k - 1];
     327     2690874 :                     im[k] = wRe * x[k - 1] - wIm * x[Nm1 - k];
     328             :                 }
     329       10734 :                 re[length >> 1] = x[Nm1 >> 1] * sqrtf( 0.5f );
     330             :             }
     331             : 
     332       21390 :             re[0] = x[Nm1 - Nm1 * ( kernelType >> 1 )];
     333       21390 :             im[0] = im[length >> 1] = 0.f;
     334     5400048 :             for ( k = Nm1 >> 1; k > 0; k-- )
     335             :             {
     336     5378658 :                 re[length - k] = re[k];
     337     5378658 :                 im[length - k] = -im[k];
     338             :             }
     339             : 
     340       21390 :             if ( length == 512 )
     341             :             {
     342        5202 :                 DoRTFTn( re, im, 512 );
     343             :             }
     344             :             else /* fft() doesn't support 512 */
     345             :             {
     346       16188 :                 fft( re, im, length, 1 );
     347             :             }
     348             : 
     349     5421438 :             for ( k = Nm1 >> 1; k >= 0; k-- ) /* post-modulation of FFT output */
     350             :             {
     351     5400048 :                 y[2 * k] = re[k];
     352     5400048 :                 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       24962 :     v_multc( y, ( kernelType == MDCT_II ? -1.f : 1.f ) * sqrtf( 2.f / length ), y, length );
     362             : 
     363       24962 :     return;
     364             : }
     365             : 
     366             : /*-----------------------------------------------------------------*
     367             :  * iedct_short()
     368             :  *
     369             :  * Inverse EDCT for short frames
     370             :  *-----------------------------------------------------------------*/
     371             : 
     372       74904 : 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       74904 :     edct( in, alias, segment_length / 2, element_mode );
     383             : 
     384     5324584 :     for ( i = 0; i < segment_length / 4; i++ )
     385             :     {
     386     5249680 :         out[i] = alias[segment_length / 4 + i];
     387     5249680 :         out[segment_length / 4 + i] = -alias[segment_length / 2 - 1 - i];
     388     5249680 :         out[segment_length / 2 + i] = -alias[segment_length / 4 - 1 - i];
     389     5249680 :         out[3 * segment_length / 4 + i] = -alias[i];
     390             :     }
     391             : 
     392       74904 :     return;
     393             : }

Generated by: LCOV version 1.14