LCOV - code coverage report
Current view: top level - lib_dec - voiced_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 20 108 18.5 %
Date: 2025-05-23 08:37:30 Functions: 1 2 50.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             : #include <math.h>
      40             : #include "prot.h"
      41             : #include "cnst.h"
      42             : #include "rom_com.h"
      43             : #include "wmc_auto.h"
      44             : 
      45             : /*-------------------------------------------------------------------*
      46             :  * ppp_voiced_decoder()
      47             :  *
      48             :  * Voiced decoder for SC-VBR
      49             :  *-------------------------------------------------------------------*/
      50             : 
      51           0 : ivas_error ppp_voiced_decoder(
      52             :     Decoder_State *st, /* i/o: state structure                          */
      53             :     float *out,        /* o  : residual signal                          */
      54             :     const float *lpc2, /* i  : current frame LPC                        */
      55             :     float *exc,        /* i  : previous frame excitation                */
      56             :     float *pitch,      /* o  : floating pitch values for each subframe  */
      57             :     const int16_t bfi  /* i  : BFI flag                                 */
      58             : )
      59             : {
      60           0 :     int16_t k, delta_lag_D = 0;
      61             :     SC_VBR_DEC_HANDLE hSC_VBR;
      62           0 :     float upper_cut_off_freq_of_interest = 0, upper_cut_off_freq = 0;
      63             :     int16_t pl, l;
      64             :     float interp_delay[3], temp_l, temp_pl, diff;
      65             :     DTFS_STRUCTURE *TMPDTFS;
      66             :     DTFS_STRUCTURE *CURRP_Q_D;
      67             :     DTFS_STRUCTURE *dtfs_temp;
      68             :     ivas_error error;
      69             : 
      70           0 :     error = IVAS_ERR_OK;
      71             : 
      72           0 :     if ( ( error = DTFS_new( &TMPDTFS ) ) != IVAS_ERR_OK )
      73             :     {
      74           0 :         IVAS_ERROR( error, "Error creating DTFS structure" );
      75             :     }
      76           0 :     if ( ( error = DTFS_new( &CURRP_Q_D ) ) != IVAS_ERR_OK )
      77             :     {
      78           0 :         IVAS_ERROR( error, "Error creating DTFS structure" );
      79             :     }
      80           0 :     if ( ( error = DTFS_new( &dtfs_temp ) ) != IVAS_ERR_OK )
      81             :     {
      82           0 :         IVAS_ERROR( error, "Error creating DTFS structure" );
      83             :     }
      84             : 
      85           0 :     hSC_VBR = st->hSC_VBR;
      86             : 
      87           0 :     if ( st->bwidth == NB )
      88             :     {
      89           0 :         upper_cut_off_freq_of_interest = 3300.0;
      90           0 :         upper_cut_off_freq = 4000.0;
      91             :     }
      92           0 :     else if ( st->bwidth == WB )
      93             :     {
      94           0 :         upper_cut_off_freq_of_interest = 4000.0;
      95           0 :         upper_cut_off_freq = 6400.0;
      96             :     }
      97             : 
      98             :     /* Initialization */
      99           0 :     if ( hSC_VBR->firstTime_voiceddec )
     100             :     {
     101           0 :         hSC_VBR->firstTime_voiceddec = 0;
     102             : 
     103           0 :         hSC_VBR->dtfs_dec_lag = 0;
     104           0 :         hSC_VBR->dtfs_dec_nH = 0;
     105           0 :         hSC_VBR->dtfs_dec_nH_4kHz = 0;
     106           0 :         hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest = 3300.0;
     107           0 :         hSC_VBR->dtfs_dec_upper_cut_off_freq = 4000.0;
     108             : 
     109           0 :         for ( k = 0; k < MAXLAG_WI; k++ )
     110             :         {
     111           0 :             hSC_VBR->dtfs_dec_a[k] = 0.0;
     112           0 :             hSC_VBR->dtfs_dec_b[k] = 0.0;
     113             :         }
     114             :     }
     115           0 :     pl = (int16_t) min( rint_new( st->old_pitch_buf[( 2 * NB_SUBFR ) - 1] ), MAX_LAG_PIT );
     116           0 :     delta_lag_D = get_next_indice( st, 5 );
     117             : 
     118           0 :     l = min( MAX_LAG_PIT, pl + delta_lag_D - 11 );
     119             : 
     120           0 :     temp_pl = (float) pl;
     121           0 :     temp_l = (float) l;
     122             : 
     123           0 :     if ( temp_pl != temp_l )
     124             :     {
     125           0 :         for ( k = 0; k < NB_SUBFR; k++ )
     126             :         {
     127             :             /* do the linear pitch interp to drive the nb_post_filt */
     128           0 :             Interpol_delay( interp_delay, &( temp_pl ), &( temp_l ), k, frac_4sf );
     129           0 :             pitch[k] = min( MAX_LAG_PIT, max( 19, interp_delay[0] ) );
     130             :         }
     131             :     }
     132             :     else
     133             :     {
     134           0 :         set_f( pitch, min( MAX_LAG_PIT, max( 19, temp_l ) ), NB_SUBFR );
     135             :     }
     136             : 
     137           0 :     if ( st->last_coder_type == UNVOICED )
     138             :     {
     139           0 :         pl = l; /* if prev frame was sil/uv*/
     140             :     }
     141             : 
     142           0 :     if ( pl > (int16_t) anint( 1.85 * l ) )
     143             :     {
     144           0 :         pl /= 2;
     145             :     }
     146             : 
     147           0 :     if ( pl * 2 <= PIT_MAX && pl <= (int16_t) anint( 0.54 * l ) )
     148             :     {
     149           0 :         pl *= 2;
     150             :     }
     151             : 
     152             :     /* Restoring PPP memories when the last frame is non-PPP or full-rate PPP */
     153           0 :     if ( st->last_ppp_mode_dec != 1 )
     154             :     {
     155           0 :         DTFS_to_fs( exc - pl, pl, dtfs_temp, st->bwidth == WB ? (int16_t) 16000 : (int16_t) 8000, 0 );
     156             : 
     157           0 :         hSC_VBR->ph_offset_D = 0.0;
     158             : 
     159             :         /* Copy over PREV_CW_D into TMPDTFS */
     160           0 :         DTFS_copy( TMPDTFS, *dtfs_temp );
     161             : 
     162           0 :         DTFS_car2pol( TMPDTFS );
     163             : 
     164           0 :         hSC_VBR->lastLgainD = (float) log10( TMPDTFS->lag * DTFS_setEngyHarm( 92.0, 1104.5, 0.0, 1104.5, 1.0, TMPDTFS ) );
     165           0 :         hSC_VBR->lastHgainD = (float) log10( TMPDTFS->lag * DTFS_setEngyHarm( 1104.5, upper_cut_off_freq_of_interest, 1104.5, upper_cut_off_freq, 1.0, TMPDTFS ) );
     166             : 
     167           0 :         DTFS_to_erb( *TMPDTFS, hSC_VBR->lasterbD );
     168             :     }
     169             :     else
     170             :     {
     171             :         /* Copy DTFS related parameters from 'st' to 'dtfs_temp' structure */
     172           0 :         dtfs_temp->lag = hSC_VBR->dtfs_dec_lag;
     173           0 :         dtfs_temp->nH = hSC_VBR->dtfs_dec_nH;
     174           0 :         dtfs_temp->nH_4kHz = hSC_VBR->dtfs_dec_nH_4kHz;
     175           0 :         dtfs_temp->upper_cut_off_freq_of_interest = hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest;
     176           0 :         dtfs_temp->upper_cut_off_freq = hSC_VBR->dtfs_dec_upper_cut_off_freq;
     177             : 
     178           0 :         mvr2r( hSC_VBR->dtfs_dec_a, dtfs_temp->a, MAXLAG_WI );
     179           0 :         mvr2r( hSC_VBR->dtfs_dec_b, dtfs_temp->b, MAXLAG_WI );
     180             :     }
     181             : 
     182           0 :     CURRP_Q_D->lag = l;
     183             : 
     184             :     /* safety check in case of bit errors */
     185           0 :     if ( CURRP_Q_D->lag <= 0 )
     186             :     {
     187           0 :         CURRP_Q_D->lag = 1;
     188           0 :         st->BER_detect = 1;
     189             :     }
     190             : 
     191             :     /* compute nH for lag */
     192           0 :     CURRP_Q_D->nH = (int16_t) floor( upper_cut_off_freq / ( ( (float) INT_FS_12k8 ) / CURRP_Q_D->lag ) );
     193           0 :     diff = ( (float) INT_FS_12k8 ) / CURRP_Q_D->lag;
     194             : 
     195           0 :     if ( upper_cut_off_freq - ( diff * CURRP_Q_D->nH ) >= diff )
     196             :     {
     197           0 :         CURRP_Q_D->nH++;
     198             :     }
     199             : 
     200           0 :     CURRP_Q_D->nH_4kHz = (int16_t) floor( 4000.0 / ( INT_FS_12k8 / CURRP_Q_D->lag ) );
     201             : 
     202           0 :     if ( 4000.0 - ( diff * CURRP_Q_D->nH_4kHz ) >= diff )
     203             :     {
     204           0 :         CURRP_Q_D->nH_4kHz++;
     205             :     }
     206             : 
     207           0 :     CURRP_Q_D->upper_cut_off_freq = dtfs_temp->upper_cut_off_freq;
     208           0 :     CURRP_Q_D->upper_cut_off_freq_of_interest = dtfs_temp->upper_cut_off_freq_of_interest;
     209             : 
     210           0 :     if ( bfi == 0 )
     211             :     {
     212           0 :         if ( ( error = ppp_quarter_decoder( st, CURRP_Q_D, dtfs_temp->lag, &( hSC_VBR->lastLgainD ), &( hSC_VBR->lastHgainD ), &( hSC_VBR->lasterbD[0] ), bfi, *dtfs_temp ) ) != IVAS_ERR_OK )
     213             :         {
     214           0 :             return error;
     215             :         }
     216             :     }
     217             : 
     218           0 :     if ( ( error = WIsyn( *dtfs_temp, CURRP_Q_D, lpc2, &( hSC_VBR->ph_offset_D ), out, (int16_t) L_FRAME, 0 ) ) != IVAS_ERR_OK )
     219             :     {
     220           0 :         return error;
     221             :     }
     222             : 
     223             : 
     224           0 :     DTFS_copy( dtfs_temp, *CURRP_Q_D );
     225             : 
     226             :     /* Copy DTFS related parameters from 'dtfs_temp' to 'st' structure */
     227           0 :     hSC_VBR->dtfs_dec_lag = dtfs_temp->lag;
     228           0 :     hSC_VBR->dtfs_dec_nH = dtfs_temp->nH;
     229           0 :     hSC_VBR->dtfs_dec_nH_4kHz = dtfs_temp->nH_4kHz;
     230           0 :     hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest = dtfs_temp->upper_cut_off_freq_of_interest;
     231           0 :     hSC_VBR->dtfs_dec_upper_cut_off_freq = dtfs_temp->upper_cut_off_freq;
     232             : 
     233           0 :     mvr2r( dtfs_temp->a, hSC_VBR->dtfs_dec_a, MAXLAG_WI );
     234           0 :     mvr2r( dtfs_temp->b, hSC_VBR->dtfs_dec_b, MAXLAG_WI );
     235             : 
     236           0 :     free( TMPDTFS );
     237           0 :     free( CURRP_Q_D );
     238           0 :     free( dtfs_temp );
     239             : 
     240           0 :     return error;
     241             : }
     242             : 
     243             : 
     244             : /*---------------------------------------------------------------------*
     245             :  * sc_vbr_dec_init()
     246             :  *
     247             :  * Initialize SC-VBR decoder
     248             :  *---------------------------------------------------------------------*/
     249             : 
     250           9 : void sc_vbr_dec_init(
     251             :     SC_VBR_DEC_HANDLE hSC_VBR /* i/o: SC-VBR decoder handle    */
     252             : )
     253             : {
     254           9 :     hSC_VBR->nelp_dec_seed = 0;
     255           9 :     hSC_VBR->firstTime_voiceddec = 1;
     256             : 
     257             :     /* DTFS variables */
     258           9 :     set_f( hSC_VBR->dtfs_dec_a, 0, MAXLAG_WI );
     259           9 :     set_f( hSC_VBR->dtfs_dec_b, 0, MAXLAG_WI );
     260           9 :     hSC_VBR->dtfs_dec_lag = 0;
     261           9 :     hSC_VBR->dtfs_dec_nH = 0;
     262           9 :     hSC_VBR->dtfs_dec_nH_4kHz = 0;
     263           9 :     hSC_VBR->dtfs_dec_upper_cut_off_freq_of_interest = 0;
     264           9 :     hSC_VBR->dtfs_dec_upper_cut_off_freq = 0;
     265           9 :     hSC_VBR->ph_offset_D = 0;
     266           9 :     hSC_VBR->lastLgainD = 0;
     267           9 :     hSC_VBR->lastHgainD = 0;
     268           9 :     set_f( hSC_VBR->lasterbD, 0, NUM_ERB_WB );
     269             : 
     270             :     /* NELP decoder variables */
     271           9 :     set_f( hSC_VBR->bp1_filt_mem_nb_dec, 0, 14 );
     272           9 :     set_f( hSC_VBR->bp1_filt_mem_wb_dec, 0, 8 );
     273           9 :     set_f( hSC_VBR->shape1_filt_mem_dec, 0, 20 );
     274           9 :     set_f( hSC_VBR->shape2_filt_mem_dec, 0, 20 );
     275           9 :     set_f( hSC_VBR->shape3_filt_mem_dec, 0, 20 );
     276             : 
     277           9 :     return;
     278             : }

Generated by: LCOV version 1.14