Commit 64b02dab authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Fix for LTV crashes, Q fix for noise_est, find_tilt related buffers

parent 69c59140
Loading
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -1652,9 +1652,9 @@ void InternalTCXDecoder(

void stereo_mdct_core_enc_fx(
    CPE_ENC_HANDLE hCPE,                                        /* i/o: CPE encoder structure                   */
    Word16 new_samples[CPE_CHANNELS][L_INP],                     /* i  : new samples                             */
    Word16 old_wsp[CPE_CHANNELS][L_WSP],                         /* i  : 12.8kHz weighted speech (for LTP        */
    Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]                  /* o  : floating pitch for each subframe        */
    Word16 new_samples[CPE_CHANNELS][L_INP],                     /* i  : new samples                             Q0*/
    Word16 old_wsp[CPE_CHANNELS][L_WSP],                         /* i  : 12.8kHz weighted speech (for LTP        Qx*/
    Word16 pitch_buf_fx[CPE_CHANNELS][NB_SUBFR16k]                  /* o  : floating pitch for each subframe     Q6*/
);

void initMdctStereoEncData(
@@ -1931,12 +1931,12 @@ void splitAvailableBits(
    int16_t *bits_ch1                                           /* o  : bits for channel 1                      */
);

int16_t write_stereo_to_bitstream
Word16 write_stereo_to_bitstream_fx
(
    STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct,                    /* i/o: Stereo MDCT encoder structure           */
    Encoder_State **sts,                                        /* i/o: Encoder state structure                 */
    int16_t ms_mask[NB_DIV][MAX_SFB],                           /* i  : bandwise MS mask                        */
    const int16_t mct_on,                                       /* i  : flag mct block (1) or stereo (0)        */
    Word16 ms_mask[NB_DIV][MAX_SFB],                           /* i  : bandwise MS mask                         Q0*/
    const Word16 mct_on,                                       /* i  : flag mct block (1) or stereo (0)         Q0*/
    BSTR_ENC_HANDLE hBstr                                       /* i/o: bitstream handle                        */
);

+2 −2
Original line number Diff line number Diff line
@@ -3799,7 +3799,7 @@ void QuantizeTCXSpectrum_fx(
            }

            /* Quantize original spectrum */
            sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e );
            sqGain_fx = SQ_gain_ivas_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e );

            tcx_scalar_quantization_ivas_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, sqGain_fx, sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, st->tcxonly );

@@ -3887,7 +3887,7 @@ void QuantizeTCXSpectrum_fx(
            }
            ELSE
            {
                sqGain_fx = SQ_gain_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e );
                sqGain_fx = SQ_gain_ivas_fx( spectrum_fx, *spectrum_e, shl( mult( hTcxEnc->tcx_target_bits_fac, sqTargetBits ), 1 ), L_spec, &sqGain_e );
            }
            /* Quantize spectrum */
            tcx_scalar_quantization_ivas_fx( spectrum_fx, *spectrum_e, sqQ, L_spec, sqGain_fx, sqGain_e, st->hTcxCfg->sq_rounding, hTcxEnc->memQuantZeros, st->tcxonly );
+2 −2
Original line number Diff line number Diff line
@@ -514,7 +514,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ
        test();
#ifdef BASOP_NOGLOB
        if ( ( ( LT_16( add_o( mean_voi3, corr_shift, &Overflow ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low  */
               ( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) &&               /* normalized correlation low on look-ahead - onset detection */
               /*( LT_16( add_o( st_fx->voicing_fx[2], corr_shift, &Overflow ), 25887 ) ) && */          /* normalized correlation low on look-ahead - onset detection */
               ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) &&                              /* energy concentrated in high frequencies provided that some energy is present in HF...  */
               ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) &&                              /* ... biased towards look-ahead to detect onsets  */
               ( tmp_offset_flag == 0 ) &&                                                               /* Take care of voiced offsets */
@@ -525,7 +525,7 @@ Word16 find_uv_ivas_fx( /* o : coding typ
             || ( flag_low_relE && ( LE_32( st_fx->old_dE1_fx, 245760 ) ) ) )                            /* low relative frame energy (only for SC-VBR) */
#else
        if ( ( ( LT_16( add( mean_voi3, corr_shift ), add( 22774, mean_voi3_offset ) ) ) && /* normalized correlation low  */
               ( LT_16( add( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) &&               /* normalized correlation low on look-ahead - onset detection */
               /* ( LT_16( add( st_fx->voicing_fx[2], corr_shift ), 25887 ) ) && */         /* normalized correlation low on look-ahead - onset detection */
               ( LT_32( ee[0], 397 ) ) && ( GT_32( hp_E[0], E_min_th ) ) &&                 /* energy concentrated in high frequencies provided that some energy is present in HF...  */
               ( LT_32( ee[1], 397 ) ) && ( GT_32( hp_E[1], E_min_th ) ) &&                 /* ... biased towards look-ahead to detect onsets  */
               ( tmp_offset_flag == 0 ) &&                                                  /* Take care of voiced offsets */
+60 −58
Original line number Diff line number Diff line
@@ -1289,22 +1289,6 @@ ivas_error pre_proc_front_ivas_fx(
    st->old_pitch_la = st->pitch[2];
    move16();

    test();
    IF( lr_vad_enabled && st->idchan == 0 )
    {
        FOR( i = 0; i < 2; i++ )
        {
            shift = getScaleFactor32( tmpN_LR_fx[i], NB_BANDS );
            scale_sig32( tmpN_LR_fx[i], NB_BANDS, shift );
            q_tmpN_LR[i] = add( q_tmpN_LR[i], shift );
            move16();

            shift = getScaleFactor32( tmpE_LR_fx[i], NB_BANDS );
            scale_sig32( tmpE_LR_fx[i], NB_BANDS, shift );
            q_tmpE_LR[i] = add( q_tmpE_LR[i], shift );
            move16();
        }
    }
    shift = getScaleFactor32( tmpN_fx, NB_BANDS );
    scale_sig32( tmpN_fx, NB_BANDS, shift );
    q_tmpN = add( q_tmpN, shift );
@@ -1320,6 +1304,66 @@ ivas_error pre_proc_front_ivas_fx(
    Scale_sig( old_wsp_fx, L_WSP, shift );
    *q_old_wsp = add( *q_old_wsp, shift );
    move16();

    /*Scaling to avoid 0 values*/
    shift = L_norm_arr( fr_bands_fx, 2 * NB_BANDS );
    scale_sig32( fr_bands_fx, 2 * NB_BANDS, shift );
    fr_bands_fx_q = add( fr_bands_fx_q, shift );
    shift = s_min( L_norm_arr( st->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->fr_bands2_fx, NB_BANDS ) );
    scale_sig32( st->hNoiseEst->fr_bands1_fx, NB_BANDS, shift );
    scale_sig32( st->hNoiseEst->fr_bands2_fx, NB_BANDS, shift );
    st->hNoiseEst->fr_bands_fx_q = add( st->hNoiseEst->fr_bands_fx_q, shift );
    move16();
    shift = s_min( L_norm_arr( st->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->ave_enr2_fx, NB_BANDS ) );
    scale_sig32( st->hNoiseEst->ave_enr_fx, NB_BANDS, shift );
    scale_sig32( st->hNoiseEst->ave_enr2_fx, NB_BANDS, shift );
    st->hNoiseEst->ave_enr_q = add( st->hNoiseEst->ave_enr_q, shift );
    move16();
    shift = L_norm_arr( st->hNoiseEst->bckr_fx, NB_BANDS );
    scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, shift );
    st->hNoiseEst->q_bckr = add( st->hNoiseEst->q_bckr, shift );
    move16();
    shift = L_norm_arr( st->hNoiseEst->enrO_fx, NB_BANDS );
    scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, shift );
    st->hNoiseEst->q_enrO = add( st->hNoiseEst->q_enrO, shift );
    move16();

    test();
    IF( lr_vad_enabled && st->idchan == 0 )
    {
        /*Scaling to avoid 0 values*/
        FOR( Word16 j = 0; j < 2; j++ )
        {
            shift = getScaleFactor32( tmpN_LR_fx[j], NB_BANDS );
            scale_sig32( tmpN_LR_fx[j], NB_BANDS, shift );
            q_tmpN_LR[j] = add( q_tmpN_LR[j], shift );
            move16();

            shift = getScaleFactor32( tmpE_LR_fx[j], NB_BANDS );
            scale_sig32( tmpE_LR_fx[j], NB_BANDS, shift );
            q_tmpE_LR[j] = add( q_tmpE_LR[j], shift );
            move16();

            shift = s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS ) );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS, shift );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS, shift );
            hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q = add( hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q, shift );
            shift = s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS ) );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS, shift );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS, shift );
            hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q = add( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q, shift );

            shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS, shift );
            hCPE->hFrontVad[j]->hNoiseEst->q_bckr = add( hCPE->hFrontVad[j]->hNoiseEst->q_bckr, shift );
            move16();
            shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS, shift );
            hCPE->hFrontVad[j]->hNoiseEst->q_enrO = add( hCPE->hFrontVad[j]->hNoiseEst->q_enrO, shift );
            move16();
        }
    }

    Q_wsp = *q_old_wsp;
    move16();
    Word16 q_fr_bands = Q30;
@@ -1434,26 +1478,6 @@ ivas_error pre_proc_front_ivas_fx(
    noise_est_ivas_fx( st, old_pitch1, tmpN_fx, epsP_h, epsP_l, Etot_fx, *relE_fx, corr_shift_fx, tmpE_fx, fr_bands_fx, cor_map_sum_fx, &ncharX_fx, &sp_div_fx, &q_sp_div,
                       &non_staX_fx, loc_harm, lf_E_fx, &st->hNoiseEst->harm_cor_cnt, st->hNoiseEst->Etot_l_lp_fx, st->hNoiseEst->Etot_v_h2_fx, &st->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_fx, hStereoClassif, NULL, st->ini_frame );

    /*Scaling to avoid 0 values*/
    shift = s_min( L_norm_arr( st->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->fr_bands2_fx, NB_BANDS ) );
    scale_sig32( st->hNoiseEst->fr_bands1_fx, NB_BANDS, shift );
    scale_sig32( st->hNoiseEst->fr_bands2_fx, NB_BANDS, shift );
    st->hNoiseEst->fr_bands_fx_q = add( st->hNoiseEst->fr_bands_fx_q, shift );
    move16();
    shift = s_min( L_norm_arr( st->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( st->hNoiseEst->ave_enr2_fx, NB_BANDS ) );
    scale_sig32( st->hNoiseEst->ave_enr_fx, NB_BANDS, shift );
    scale_sig32( st->hNoiseEst->ave_enr2_fx, NB_BANDS, shift );
    st->hNoiseEst->ave_enr_q = add( st->hNoiseEst->ave_enr_q, shift );
    move16();
    shift = L_norm_arr( st->hNoiseEst->bckr_fx, NB_BANDS );
    scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, shift );
    st->hNoiseEst->q_bckr = add( st->hNoiseEst->q_bckr, shift );
    move16();
    shift = L_norm_arr( st->hNoiseEst->enrO_fx, NB_BANDS );
    scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, shift );
    st->hNoiseEst->q_enrO = add( st->hNoiseEst->q_enrO, shift );
    move16();

    test();
    IF( lr_vad_enabled && st->idchan == 0 )
    {
@@ -1470,14 +1494,6 @@ ivas_error pre_proc_front_ivas_fx(
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS, sub( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ) );
            hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q = q_fr_bands;
            move16();
            shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->bckr_fx, NB_BANDS, shift );
            hCPE->hFrontVad[j]->hNoiseEst->q_bckr = add( hCPE->hFrontVad[j]->hNoiseEst->q_bckr, shift );
            move16();
            shift = L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->enrO_fx, NB_BANDS, shift );
            hCPE->hFrontVad[j]->hNoiseEst->q_enrO = add( hCPE->hFrontVad[j]->hNoiseEst->q_enrO, shift );
            move16();

            FOR( Word16 k = 0; k < NB_BANDS; k++ )
            {
@@ -1496,20 +1512,6 @@ ivas_error pre_proc_front_ivas_fx(
        /* Note: the index [0] in the last argument is intended, the ini_frame counter is only maintained in the zero-th channel's VAD handle */
        noise_est_ivas_fx( st, old_pitch1, tmpN_LR_fx[1], epsP_h, epsP_l, Etot_LR_fx[1], sub( Etot_LR_fx[1], hCPE->hFrontVad[1]->lp_speech_fx ), corr_shiftR_fx, tmpE_LR_fx[1], fr_bands_LR_fx[1], &cor_map_sum_LR_fx[1], &ncharX_LR_fx, &sp_div_LR_fx, &q_sp_div_LR,
                           &non_staX_LR_fx, loc_harmLR_fx, lf_E_LR_fx[1], &hCPE->hFrontVad[1]->hNoiseEst->harm_cor_cnt, hCPE->hFrontVad[1]->hNoiseEst->Etot_l_lp_fx, hCPE->hFrontVad[1]->hNoiseEst->Etot_v_h2_fx, &hCPE->hFrontVad[1]->hNoiseEst->bg_cnt, st->lgBin_E_fx, sub( q_fr_bands, QSCALE ), L_shl( E_MIN_IVAS_FX, sub( q_fr_bands, Q19 ) ), &dummy_fx, S_map_LR_fx, NULL, hCPE->hFrontVad[1], hCPE->hFrontVad[0]->ini_frame );


        /*Scaling to avoid 0 values*/
        FOR( Word16 j = 0; j < 2; j++ )
        {
            shift = s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS ) );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands1_fx, NB_BANDS, shift );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->fr_bands2_fx, NB_BANDS, shift );
            hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q = add( hCPE->hFrontVad[j]->hNoiseEst->fr_bands_fx_q, shift );
            shift = s_min( L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS ), L_norm_arr( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS ) );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_fx, NB_BANDS, shift );
            scale_sig32( hCPE->hFrontVad[j]->hNoiseEst->ave_enr2_fx, NB_BANDS, shift );
            hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q = add( hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q, shift );
        }
    }

    /*------------------------------------------------------------------*
+4 −4
Original line number Diff line number Diff line
@@ -496,13 +496,13 @@ void ivas_mct_core_enc_fx(

                FOR( i = 1; i < L_subframeTCX - 1; i++ )
                {
                    mdst_fx = L_sub( L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i + 1], 1 ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i - 1], 1 ) ); /* An MDST estimate */
                    mdst_fx = L_sub( L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i + 1], 1 ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i - 1], 1 ) ); /* An MDST estimate, Q = q_spec - 1 */

                    W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i], 1 ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i], 1 ) );
                    W_tmp = W_mac_32_32( W_mult_32_32( mdst_fx, mdst_fx ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i], 1 ), L_shr( sts[ch]->hTcxEnc->spectrum_fx[n][i], 1 ) ); // Q = 2 * (q_spec - 1) + 1
                    tmp_s = W_norm( W_tmp );
                    W_tmp = W_shl( W_tmp, tmp_s );
                    powerSpec_fx[ch][add( i, imult1616( n, L_subframeTCX ) )] = W_extract_h( W_tmp );
                    tmp_q_powSpec[add( i, imult1616( n, L_subframeTCX ) )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 31 ); // Q = 2 * q_spec + 1 + tmp_s - 32
                    powerSpec_fx[ch][i + ( n * L_subframeTCX )] = W_extract_h( W_tmp );
                    tmp_q_powSpec[i + ( n * L_subframeTCX )] = sub( add( imult1616( q_spec, 2 ), tmp_s ), 33 ); // Q = 2 * (q_spec - 1) + 1 + tmp_s - 32
                    move32();
                    move16();
                }
Loading