Commit cf1893bd authored by Jan Kiene's avatar Jan Kiene
Browse files

fix infinite CNG in ISM decoder when going to silence

parent 01917fc5
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1163,6 +1163,13 @@ void ivas_get_ism_sid_quan_bitbudget(
    int16_t *nBits_sce_id                                       /* o  : number of Q bits for sce_id_dtx             */
);

#ifdef FIX_ISM_DTX_INFINITE_CNG_ON_TRAILING_SILENCE
void ivas_ism_dtx_limit_noise_energy_for_near_silence(
    SCE_DEC_HANDLE hSCE[],
    const int16_t sce_id_dtx,
    const int16_t nchan_transport
);
#endif

/*----------------------------------------------------------------------------------*
 * DFT Stereo prototypes
+1 −1
Original line number Diff line number Diff line
@@ -209,6 +209,7 @@
#define FIX_615_UBSAN_SPAR_TO_DIRAC                     /*Dlb : Fix for UBSAN issue 615*/
#define FIX_626_VARIABLE_TYPE_MDCT_CONC                 /* FhG: trivial fix to fix USAN error */
#define FIX_616_DIV_ZERO_MCT                            /*FhG : Fix UBSAN division by zero error of issue 616*/
#define FIX_ISM_DTX_INFINITE_CNG_ON_TRAILING_SILENCE    /* FhG: fix for cng in ISM DTX on sudden silence periods */

/* ################## End BE DEVELOPMENT switches ######################### */

@@ -220,7 +221,6 @@

/* ##################### End NON-BE CR switches ########################### */


/* ################## End DEVELOPMENT switches ######################### */

/* clang-format on */
+21 −0
Original line number Diff line number Diff line
@@ -180,6 +180,16 @@ ivas_error ivas_dec(
            {
                return error;
            }
#ifdef FIX_ISM_DTX_INFINITE_CNG_ON_TRAILING_SILENCE

            /* decode dominant object first so we can limit the noise energy of the other objects */
            if ( ( error = ivas_sce_dec( st_ivas, st_ivas->hISMDTX.sce_id_dtx, &output[st_ivas->hISMDTX.sce_id_dtx], output_frame, nb_bits_metadata[st_ivas->hISMDTX.sce_id_dtx] ) ) )
            {
                return error;
            }

            ivas_ism_dtx_limit_noise_energy_for_near_silence( st_ivas->hSCE, st_ivas->hISMDTX.sce_id_dtx, st_ivas->nchan_transport );
#endif
        }
        else if ( st_ivas->ism_mode == ISM_MODE_PARAM )
        {
@@ -198,10 +208,21 @@ ivas_error ivas_dec(

        for ( n = 0; n < st_ivas->nchan_transport; n++ )
        {
#ifdef FIX_ISM_DTX_INFINITE_CNG_ON_TRAILING_SILENCE
            /* for DTX frames, dominant object has already been decoded before */
            if ( !( ( ivas_total_brate == IVAS_SID_5k2 || ivas_total_brate == FRAME_NO_DATA ) && n == st_ivas->hISMDTX.sce_id_dtx ) )
            {
                if ( ( error = ivas_sce_dec( st_ivas, n, &output[n], output_frame, nb_bits_metadata[n] ) ) != IVAS_ERR_OK )
                {
                    return error;
                }
            }
#else
            if ( ( error = ivas_sce_dec( st_ivas, n, &output[n], output_frame, nb_bits_metadata[n] ) ) != IVAS_ERR_OK )
            {
                return error;
            }
#endif

            /* HP filtering */
            hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs );
+51 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
*******************************************************************************************************/

#include <stdint.h>
#include <math.h>
#include "options.h"
#include "ivas_prot.h"
#include "prot.h"
@@ -156,3 +157,53 @@ ivas_error ivas_ism_dtx_dec(

    return IVAS_ERR_OK;
}

#ifdef FIX_ISM_DTX_INFINITE_CNG_ON_TRAILING_SILENCE
/*-------------------------------------------------------------------*
 * ivs_ism_dtx_limit_noise_energy_for_near_silence
 *
 * for DTX frames where the energy of the sent noise estimate of the dominant object
 * is near silence, limit the other objects CNG energies to the same level
 *
 *-------------------------------------------------------------------*/
void ivas_ism_dtx_limit_noise_energy_for_near_silence(
    SCE_DEC_HANDLE hSCE[],
    const int16_t sce_id_dtx,
    const int16_t nchan_transport )
{
    float cng_noise_nrg_dominant;
    int16_t cng_noise_level_len;
    HANDLE_FD_CNG_COM hFdCngCom;

    hFdCngCom = hSCE[sce_id_dtx]->hCoreCoder[0]->hFdCngDec->hFdCngCom;
    cng_noise_level_len = hFdCngCom->stopFFTbin - hFdCngCom->startBand;
    cng_noise_nrg_dominant = dotp( hFdCngCom->cngNoiseLevel, hFdCngCom->cngNoiseLevel, cng_noise_level_len );

    if ( cng_noise_nrg_dominant < 1.f )
    {
        for ( int16_t n = 0; n < nchan_transport; n++ )
        {
            float cng_noise_nrg_obj;

            if ( n == sce_id_dtx )
            {
                continue;
            }

            hFdCngCom = hSCE[n]->hCoreCoder[0]->hFdCngDec->hFdCngCom;
            cng_noise_level_len = hFdCngCom->stopFFTbin - hFdCngCom->startBand;
            cng_noise_nrg_obj = dotp( hFdCngCom->cngNoiseLevel, hFdCngCom->cngNoiseLevel, cng_noise_level_len );

            if ( cng_noise_nrg_obj > cng_noise_nrg_dominant )
            {
                float fac;

                fac = sqrtf( cng_noise_nrg_dominant / cng_noise_nrg_obj );
                v_multc( hFdCngCom->cngNoiseLevel, fac, hFdCngCom->cngNoiseLevel, cng_noise_level_len );
            }
        }
    }

    return;
}
#endif
+0 −1
Original line number Diff line number Diff line
@@ -312,7 +312,6 @@ void ivas_ism_get_sce_id_dtx(
    SCE_ENC_HANDLE hSCE[MAX_SCE],  /* i/o: SCE encoder structure            */
    const int16_t nchan_transport, /* i  : number of transport channels     */
    const int16_t input_frame      /* i  : input frame length per channel   */

)
{
    float tmp_energy[MAX_NUM_OBJECTS];