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

Generated by: LCOV version 1.14