LCOV - code coverage report
Current view: top level - lib_com - isf_dec_amr_wb.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 6baab0c613aa6c7100498ed7b93676aa8198a493 Lines: 83 83 100.0 %
Date: 2025-05-29 08:28:55 Functions: 4 4 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             : 
      47             : /*---------------------------------------------------------------------*
      48             :  * isf_dec_amr_wb()
      49             :  *
      50             :  * Decoding of ISF parameters in AMR-WB IO mode
      51             :  *---------------------------------------------------------------------*/
      52             : 
      53        6039 : void isf_dec_amr_wb(
      54             :     Decoder_State *st, /* i/o: State structure                             */
      55             :     float *Aq,         /* o  : quantized A(z) for 4 subframes              */
      56             :     float *isf_new,    /* o  : de-quantized ISF vector                     */
      57             :     float *isp_new     /* o  : de-quantized ISP vector                     */
      58             : )
      59             : {
      60             :     int16_t i;
      61             :     int16_t indice[7];
      62             : 
      63        6039 :     set_s( indice, -1, 7 );
      64             : 
      65             :     /*---------------------------------*
      66             :      * ISF de-quantization of SID frames
      67             :      *---------------------------------*/
      68             : 
      69        6039 :     if ( st->core_brate == SID_1k75 )
      70             :     {
      71         104 :         indice[0] = get_next_indice( st, 6 );
      72         104 :         indice[1] = get_next_indice( st, 6 );
      73         104 :         indice[2] = get_next_indice( st, 6 );
      74         104 :         indice[3] = get_next_indice( st, 5 );
      75         104 :         indice[4] = get_next_indice( st, 5 );
      76             : 
      77         104 :         disf_ns_28b( indice, isf_new );
      78             : 
      79         104 :         reorder_isf( isf_new, ISF_GAP, M, INT_FS_12k8 );
      80             : 
      81         104 :         isf2isp( isf_new, isp_new, M, INT_FS_12k8 );
      82             : 
      83             :         /* return if SID frame (conversion to A(z) done in the calling function) */
      84         104 :         return;
      85             :     }
      86             : 
      87             :     /*-----------------------------------------------------------------*
      88             :      * ISF de-quantization of all other frames
      89             :      *-----------------------------------------------------------------*/
      90             : 
      91        5935 :     if ( st->core_brate == ACELP_6k60 )
      92             :     {
      93         562 :         indice[0] = get_next_indice( st, 8 );
      94         562 :         indice[1] = get_next_indice( st, 8 );
      95         562 :         indice[2] = get_next_indice( st, 7 );
      96         562 :         indice[3] = get_next_indice( st, 7 );
      97         562 :         indice[4] = get_next_indice( st, 6 );
      98             : 
      99         562 :         disf_2s_36b( indice, isf_new, st->mem_AR, st->mem_MA );
     100             :     }
     101             :     else
     102             :     {
     103        5373 :         indice[0] = get_next_indice( st, 8 );
     104        5373 :         indice[1] = get_next_indice( st, 8 );
     105        5373 :         indice[2] = get_next_indice( st, 6 );
     106        5373 :         indice[3] = get_next_indice( st, 7 );
     107        5373 :         indice[4] = get_next_indice( st, 7 );
     108        5373 :         indice[5] = get_next_indice( st, 5 );
     109        5373 :         indice[6] = get_next_indice( st, 5 );
     110             : 
     111        5373 :         disf_2s_46b( indice, isf_new, st->mem_AR, st->mem_MA );
     112             :     }
     113             : 
     114        5935 :     reorder_isf( isf_new, ISF_GAP, M, INT_FS_12k8 );
     115             : 
     116             :     /* convert quantized ISFs to ISPs */
     117        5935 :     isf2isp( isf_new, isp_new, M, INT_FS_12k8 );
     118             : 
     119             :     /*-------------------------------------------------------------------------------------*
     120             :      * FEC - update adaptive mean ISF vector
     121             :      *-------------------------------------------------------------------------------------*/
     122             : 
     123      100895 :     for ( i = 0; i < M; i++ )
     124             :     {
     125       94960 :         st->lsf_adaptive_mean[i] = ( st->lsfoldbfi1[i] + st->lsfoldbfi0[i] + isf_new[i] ) / 3;
     126             :     }
     127             : 
     128             :     /*-------------------------------------------------------------------------------------*
     129             :      * ISP interpolation
     130             :      * A(z) calculation
     131             :      *-------------------------------------------------------------------------------------*/
     132             : 
     133        5935 :     if ( st->rate_switching_reset )
     134             :     {
     135             :         /*extrapolation instead of interpolation*/
     136           1 :         mvr2r( isp_new, st->lsp_old, M );
     137           1 :         mvr2r( isf_new, st->lsf_old, M );
     138             :     }
     139             : 
     140             :     /* ISP interpolation and A(z) calculation */
     141        5935 :     int_lsp( L_FRAME, st->lsp_old, isp_new, Aq, M, interpol_isp_amr_wb, 1 );
     142             : 
     143             :     /*------------------------------------------------------------------*
     144             :      * Check ISF stability : distance between old ISF and current ISF
     145             :      *------------------------------------------------------------------*/
     146             : 
     147        5935 :     st->stab_fac = lsf_stab( isf_new, st->lsf_old, 1, st->L_frame );
     148             : 
     149        5935 :     return;
     150             : }
     151             : 
     152             : /*-------------------------------------------------------------------*
     153             :  * disf_ns_28b()
     154             :  *
     155             :  * ISF de-quantizer for SID_1k75 frames (only for AMR-WB IO mode)
     156             :  *-------------------------------------------------------------------*/
     157             : 
     158         211 : void disf_ns_28b( int16_t *indice, /* i  : quantized indices (use indice[0] = -1 in the decoder) */
     159             :                   float *isf_q     /* o  : ISF in the frequency domain (0..6400) */
     160             : )
     161             : {
     162             :     int16_t i;
     163             : 
     164         633 :     for ( i = 0; i < 2; i++ )
     165             :     {
     166         422 :         isf_q[i] = dico1_ns_28b[indice[0] * 2 + i];
     167             :     }
     168             : 
     169         844 :     for ( i = 0; i < 3; i++ )
     170             :     {
     171         633 :         isf_q[i + 2] = dico2_ns_28b[indice[1] * 3 + i];
     172         633 :         isf_q[i + 5] = dico3_ns_28b[indice[2] * 3 + i];
     173             :     }
     174             : 
     175        1055 :     for ( i = 0; i < 4; i++ )
     176             :     {
     177         844 :         isf_q[i + 8] = dico4_ns_28b[indice[3] * 4 + i];
     178         844 :         isf_q[i + 12] = dico5_ns_28b[indice[4] * 4 + i];
     179             :     }
     180             : 
     181        3587 :     for ( i = 0; i < M; i++ )
     182             :     {
     183        3376 :         isf_q[i] += mean_isf_noise_amr_wb[i];
     184             :     }
     185             : 
     186         211 :     return;
     187             : }
     188             : 
     189             : /*-------------------------------------------------------------------*
     190             :  * disf_2s_46b()
     191             :  *
     192             :  * ISF de-quantizer for 46b. codebooks (only for AMR-WB IO mode)
     193             :  *-------------------------------------------------------------------*/
     194             : 
     195        9405 : void disf_2s_46b(
     196             :     int16_t *indice, /* i  : quantized indices (use indice[0] = -1 in the decoder) */
     197             :     float *isf_q,    /* o  : quantized ISFs in the cosine domain */
     198             :     float *mem_AR,   /* o  : quantizer memory for AR model       */
     199             :     float *mem_MA    /* i/o: quantizer memory for MA model       */
     200             : )
     201             : {
     202             :     int16_t i;
     203             : 
     204       94050 :     for ( i = 0; i < 9; i++ )
     205             :     {
     206       84645 :         isf_q[i] = dico1_isf[indice[0] * 9 + i];
     207             :     }
     208             : 
     209       75240 :     for ( i = 0; i < 7; i++ )
     210             :     {
     211       65835 :         isf_q[i + 9] = dico2_isf[indice[1] * 7 + i];
     212             :     }
     213             : 
     214       37620 :     for ( i = 0; i < 3; i++ )
     215             :     {
     216       28215 :         isf_q[i] += dico21_isf_46b[indice[2] * 3 + i];
     217       28215 :         isf_q[i + 3] += dico22_isf_46b[indice[3] * 3 + i];
     218       28215 :         isf_q[i + 6] += dico23_isf_46b[indice[4] * 3 + i];
     219       28215 :         isf_q[i + 9] += dico24_isf_46b[indice[5] * 3 + i];
     220             :     }
     221             : 
     222       47025 :     for ( i = 0; i < 4; i++ )
     223             :     {
     224       37620 :         isf_q[i + 12] += dico25_isf_46b[indice[6] * 4 + i];
     225             :     }
     226             : 
     227      159885 :     for ( i = 0; i < M; i++ )
     228             :     {
     229      150480 :         mem_AR[i] = (float) ( isf_q[i] + MU_MA * mem_MA[i] ); /* Update with quantized ISF vector for AR model */
     230      150480 :         mem_MA[i] = isf_q[i];                                 /* Update with quantized prediction error for MA model */
     231      150480 :         isf_q[i] = mem_AR[i] + mean_isf_amr_wb[i];            /* Quantized ISFs */
     232             :     }
     233             : 
     234        9405 :     return;
     235             : }
     236             : 
     237             : 
     238             : /*-------------------------------------------------------------------*
     239             :  * disf_2s_36b()
     240             :  *
     241             :  * ISF de-quantizer for 36b. codebooks (only for AMR-WB IO mode)
     242             :  *-------------------------------------------------------------------*/
     243             : 
     244         932 : void disf_2s_36b(
     245             :     int16_t *indice, /* i  : quantized indices (use indice[0] = -1 in the decoder) */
     246             :     float *isf_q,    /* o  : quantized ISFs in the cosine domain */
     247             :     float *mem_AR,   /* i/o: quantizer memory for AR model       */
     248             :     float *mem_MA    /* i/o: quantizer memory for MA model       */
     249             : )
     250             : {
     251             :     int16_t i;
     252             :     const float *pt_dico1;
     253             : 
     254         932 :     pt_dico1 = dico1_isf; /* Pointer of the 1st stage, 1st plit */
     255             : 
     256        9320 :     for ( i = 0; i < 9; i++ )
     257             :     {
     258        8388 :         isf_q[i] = pt_dico1[indice[0] * 9 + i];
     259             :     }
     260             : 
     261        7456 :     for ( i = 0; i < 7; i++ )
     262             :     {
     263        6524 :         isf_q[i + 9] = dico2_isf[indice[1] * 7 + i];
     264             :     }
     265             : 
     266        5592 :     for ( i = 0; i < 5; i++ )
     267             :     {
     268        4660 :         isf_q[i] += dico21_isf_36b[indice[2] * 5 + i];
     269             :     }
     270             : 
     271        4660 :     for ( i = 0; i < 4; i++ )
     272             :     {
     273        3728 :         isf_q[i + 5] += dico22_isf_36b[indice[3] * 4 + i];
     274             :     }
     275             : 
     276        7456 :     for ( i = 0; i < 7; i++ )
     277             :     {
     278        6524 :         isf_q[i + 9] += dico23_isf_36b[indice[4] * 7 + i];
     279             :     }
     280             : 
     281       15844 :     for ( i = 0; i < M; i++ )
     282             :     {
     283       14912 :         mem_AR[i] = (float) ( isf_q[i] + MU_MA * mem_MA[i] ); /* Update with quantized ISF vector for AR model */
     284       14912 :         mem_MA[i] = isf_q[i];                                 /* Update with quantized prediction error for MA model */
     285       14912 :         isf_q[i] = mem_AR[i] + mean_isf_amr_wb[i];            /* Quantized ISFs */
     286             :     }
     287             : 
     288         932 :     return;
     289             : }

Generated by: LCOV version 1.14