LCOV - code coverage report
Current view: top level - lib_lc3plus - dct4.c (source / functions) Hit Total Coverage
Test: Coverage on main -- merged total coverage @ 9b04ec3cb36f5e8dc438cf854fa3e349998fa1e9 Lines: 51 51 100.0 %
Date: 2025-10-31 05:45:46 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             : *                        ETSI TS 103 634 V1.5.1                               *
       3             : *              Low Complexity Communication Codec Plus (LC3plus)              *
       4             : *                                                                             *
       5             : * Copyright licence is solely granted through ETSI Intellectual Property      *
       6             : * Rights Policy, 3rd April 2019. No patent licence is granted by implication, *
       7             : * estoppel or otherwise.                                                      *
       8             : ******************************************************************************/
       9             : 
      10             : #include "options.h"
      11             : #include "wmc_auto.h"
      12             : #include "functions.h"
      13             : 
      14        5830 : void dct2_init(Dct2* dct, int length)
      15             : {
      16        5830 :     assert(length <= MAX_LEN);
      17        5830 :     dct->length = length;
      18        5830 :     fft_init(&dct->fft, length);
      19        5830 : }
      20             : 
      21        5830 : void dct2_free(Dct2* dct)
      22             : {
      23        5830 :     if (dct) {
      24        5830 :         fft_free(&dct->fft);
      25        5830 :         memset(dct, 0, sizeof(*dct));
      26             :     }
      27        5830 : }
      28             : 
      29     1779817 : void dct2_apply(Dct2* dct, const LC3_FLOAT* input, LC3_FLOAT* output)
      30             : {
      31             :     Complex   tmp1[MAX_LEN];
      32             :     Complex   tmp2[MAX_LEN];
      33             :     int       i;
      34     1779817 :     assert(input != output);
      35             : 
      36    16018353 :     for (i = 0; i < 8; i++) {
      37    14238536 :         tmp1[i]           = cmplx(input[i * 2], 0);
      38    14238536 :         tmp1[16 - i - 1]  = cmplx(input[i * 2 + 1], 0);
      39             :     }
      40             : 
      41     1779817 :     fft_apply(&dct->fft, tmp1, tmp2);
      42             : 
      43    30256889 :     for (i = 0; i < 16; i++) {
      44    28477072 :         output[i] = cmul(tmp2[i], dct2_16[i]).r;
      45             :     }
      46     1779817 :     output[0] /= (LC3_FLOAT)1.414213562373095; /* SQRT(2) */
      47     1779817 : }
      48             : 
      49             : 
      50       11657 : void dct4_init(Dct4* dct, int length)
      51             : {
      52             :     int i;
      53       11657 :     assert(length <= MAX_LEN);
      54       11657 :     dct->length = length;
      55       11657 :     dct->twid1  = calloc(sizeof(*dct->twid1), length / 2);
      56       11657 :     dct->twid2  = calloc(sizeof(*dct->twid2), length / 2);
      57     2166617 :     for (i = 0; i < length / 2; i++) {
      58     2154960 :         dct->twid1[i] = cexpi(-(LC3_FLOAT)M_PI_LC3PLUS * (i + (LC3_FLOAT)0.25) / length);
      59     2154960 :         dct->twid2[i] = cexpi(-(LC3_FLOAT)M_PI_LC3PLUS * i / length);
      60             :     }
      61       11657 :     fft_init(&dct->fft, length / 2);
      62       11657 : }
      63             : 
      64       11657 : void dct4_free(Dct4* dct)
      65             : {
      66       11657 :     if (dct) {
      67       11657 :         free(dct->twid1);
      68       11657 :         free(dct->twid2);
      69       11657 :         fft_free(&dct->fft);
      70       11657 :         memset(dct, 0, sizeof(*dct));
      71             :     }
      72       11657 : }
      73             : 
      74     3549940 : void dct4_apply(Dct4* dct, const LC3_FLOAT* input, LC3_FLOAT* output)
      75             : {
      76             :     Complex     tmp2[MAX_LEN / 2];
      77     3549940 :     int         i    = 0;
      78     3549940 :     Complex*    tmp1 = (Complex*)output;
      79     3549940 :     const int   len  = dct->length;
      80     3549940 :     const LC3_FLOAT norm = (LC3_FLOAT)1.0 / LC3_SQRT((LC3_FLOAT)(len >> 1));
      81     3549940 :     assert(input != output);
      82             : 
      83   449254420 :     for (i = 0; i < len >> 1; i++) {
      84   445704480 :         tmp1[i] = cmul(cmplx(input[i * 2], input[len - i * 2 - 1]), dct->twid1[i]);
      85             :     }
      86             : 
      87     3549940 :     fft_apply(&dct->fft, tmp1, tmp2);
      88             : 
      89   449254420 :     for (i = 0; i < len >> 1; i++) {
      90   445704480 :         Complex t               = cmul(tmp2[i], dct->twid2[i]);
      91   445704480 :         output[i * 2]           = t.r * norm;
      92   445704480 :         output[len - i * 2 - 1] = -t.i * norm;
      93             :     }
      94     3549940 : }

Generated by: LCOV version 1.14