Commit 29fe1f6c authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'msan_issue_ltv_crash_fixes' into 'main'

MSAN error fixed, LTV crash fixes and Q-info update for decoder files

See merge request !671
parents 1a1e5374 41ed0d3e
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -8162,8 +8162,8 @@ void decod_amr_wb_fx(
// rst_dec_fx.c
void CNG_reset_dec_fx(
    Decoder_State *st_fx, /* i/o: decoder state structure            */
    Word16 *pitch_buf,    /* o  : floating pitch for each subframe   */
    Word16 *voice_factors /* o  : voicing factors                    */
    Word16 *pitch_buf,    /* o  : floating pitch for each subframe   Q6*/
    Word16 *voice_factors /* o  : voicing factors                    Q15*/
);
// voiced_dec_fx.c
+2 −0
Original line number Diff line number Diff line
@@ -93,6 +93,8 @@ Word16 float_to_fix16( float number, Word16 Q )
    return 0;
    if ( number == 1.0f && Q == Q15 )
        return MAX16B;
    if ( number == -1.0f && Q == Q15 )
        return MIN16B;
    assert( fabs( number ) < pow( 2, 15 - Q ) );
    Word16 ret = (Word16) ( number * ( (UWord16) 1 << Q ) );
    return ret;
+16 −17
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
#ifdef IVAS_FLOAT_FIXED
Word16 ACcontextMapping_decode2_no_mem_s17_LC(
    Decoder_State *st,        /* i/o: decoder state */
    Word16 *x,                /* o: decoded spectrum */
    Word16 *x,                /* o: decoded spectrum Q0*/
    Word16 nt,                /* i: size of spectrum */
    Word16 nbbits,            /* i: bit budget */
    Word16 resQMaxBits,       /* i: residual coding maximum bits*/
@@ -40,6 +40,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
    Word16 resQBits;
    Word16 rest_bits, rest_bits_overflow;
    Word16 tmp = 0; /* initialize just to avoid compiler warning */
    move16();
    Word16 nt_half;
    Word16 c[2], *ctx;
    Word16 p1, p2;
@@ -59,7 +60,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
    /* Rate flag */
    rateFlag = 0;
    move16();
    IF( GT_16( nbbits, 400 ) )
    if ( GT_16( nbbits, 400 ) )
    {
        rateFlag = 2 << NBITS_CONTEXT;
        move16();
@@ -86,7 +87,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
    move16();

    lastnz = shl( n, 1 );

    test();
    IF( GT_16( lastnz, nt ) || st->BER_detect )
    {
        st->BER_detect = 1;
@@ -118,7 +119,6 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
        move16();

        get_next_coeff = get_next_coeff_mapped;
        move16();
    }
    ELSE /* unmapped domain */
    {
@@ -130,7 +130,6 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
        move16();

        get_next_coeff = get_next_coeff_unmapped;
        move16();
    }

    /* Start Decoding */
@@ -174,10 +173,10 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
        La = L_deposit_l( 0 );
        Lb = L_deposit_l( 0 );
        /* MSBs decoding */
        test();

        FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; lev++ )
        {
            test();

            esc_nb = s_min( lev, 3 );
            tmp = add( t, Tab_esc_nb[esc_nb] );
            assert( tmp >= 0 && tmp < 4096 );
@@ -217,11 +216,11 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
        /*lsbs bits sign bits*/
        rest_bits = add( rest_bits, shl( lev, 1 ) );

        IF( a > 0 )
        if ( a > 0 )
        {
            rest_bits = add( rest_bits, 1 );
        }
        IF( b > 0 )
        if ( b > 0 )
        {
            rest_bits = add( rest_bits, 1 );
        }
@@ -293,12 +292,12 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
    }

    /*Decode signs*/
    IF( hm_cfg )
    if ( hm_cfg )
    {
        tmp = nt;
        move16();
    }
    IF( !hm_cfg )
    if ( !hm_cfg )
    {
        tmp = lastnz;
        move16();
@@ -344,7 +343,7 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
/*! r: resQBits */
Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx(
    Decoder_State *st,        /* i/o: decoder state                             */
    Word16 *x,                /* o  : decoded spectrum                          */
    Word16 *x,                /* o  : decoded spectrum                        Q0*/
    const Word16 nt,          /* i  : size of spectrum                          */
    const Word16 nbbits,      /* i  : bit budget                                */
    const Word16 resQMaxBits, /* i  : residual coding maximum bits              */
@@ -376,7 +375,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx(
    k = 1;
    move16();
    nt_half = shr( nt, 1 );
    WHILE( LT_16( k, nt_half ) )
    WHILE( k < nt_half )
    {
        n = add( n, 1 );
        k = shl( k, 1 );
@@ -390,7 +389,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx(
    move16();
    lastnz = shl( n, 1 );

    if ( GT_16( lastnz, nt ) )
    IF( GT_16( lastnz, nt ) )
    {
        st->BER_detect = 1;
        move16();
@@ -463,7 +462,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx(
            t = add( *ctx, rateFlag );
            IF( LT_16( nt_half, idx ) )
            {
                t = add( t, shl( 1, NBITS_CONTEXT ) );
                t = add( t, ( 1 << NBITS_CONTEXT ) );
            }

            esc_nb = 0;
@@ -486,7 +485,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx(
            FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev )
            {
                esc_nb = s_min( lev, 3 );
                pki = ari_lookup_s17_LC[add( t, Tab_esc_nb[esc_nb] )];
                pki = ari_lookup_s17_LC[t + Tab_esc_nb[esc_nb]];
                move16();
                r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14 ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */
                                                                                                                                             /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1}  */
@@ -645,7 +644,7 @@ Word16 RCcontextMapping_decode2_no_mem_s17_LCS_fx(
            FOR( lev = 0; lev < 15 && lsbs_bit_pos > 0; ++lev )
            {
                esc_nb = s_min( lev, 3 );
                pki = ari_lookup_s17_LC[add( t, add( shl( ( rateQ ), NBITS_CONTEXT ), Tab_esc_nb[esc_nb] ) )];
                pki = ari_lookup_s17_LC[t + ( ( rateQ << NBITS_CONTEXT ) + Tab_esc_nb[esc_nb] )];
                move16();
                r = rc_uni_dec_read_symbol_fastS_fx( &rc_st_dec, cum_freq_ari_pk_s17_LC_ext[pki], sym_freq_ari_pk_s17_LC_ext[pki], 17, 14 ); /*Alphabet size = 17 (2^4 = 16 MSB symbols + 1 ESC symbol) */
                                                                                                                                             /* r is the symbol read, the possible values are {0,1,....alphabet_size - 1}  */
+110 −107

File changed.

Preview size limit exceeded, changes collapsed.

+37 −33
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ ivas_error acelp_core_switch_dec_fx(
    Word16 *tmp_synth_bwe,            /* o  : synthesized ACELP subframe BWE Q_syn*/
    const Word16 output_frame,        /* i  : input frame length                  */
    const Word16 core_switching_flag, /* i  : core switching flag                 */
    Word16 *mem_synth,                /* o  : synthesis to overlap                */
    Word16 *mem_synth,                /* o  : synthesis to overlap               Q0 */
    Word16 *Q_syn )
{
    Word16 i, delta, L_frame_for_cs, decode_bwe, tmp;
@@ -58,9 +58,7 @@ ivas_error acelp_core_switch_dec_fx(
        set32_fx( realBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
        set32_fx( imagBufferTmp[i], 0, CLDFB_NO_CHANNELS_MAX );
        realBuffer[i] = realBufferTmp[i];
        move32();
        imagBuffer[i] = imagBufferTmp[i];
        move32();
    }

    /* initializations */
@@ -69,8 +67,8 @@ ivas_error acelp_core_switch_dec_fx(
    gain = 0;
    move16();

    Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 );
    Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 );
    Copy( st_fx->old_Aq_12_8_fx, Aq, M + 1 );             // Q12
    Copy( st_fx->old_Aq_12_8_fx, Aq + ( M + 1 ), M + 1 ); // Q12

    set16_fx( mem_synth, 0, NS2SA( 16000, DELAY_CLDFB_NS ) + 2 );
    set16_fx( synth_subfr_out, 0, SWITCH_MAX_GAP ); /* avoid valgrind complaining about uninitialized memory in core_switching_OLA_fx() */
@@ -93,14 +91,15 @@ ivas_error acelp_core_switch_dec_fx(
    IF( core_switching_flag && EQ_16( st_fx->last_L_frame, st_fx->last_L_frame_ori ) && ( ( ( st_fx->last_core == ACELP_CORE ) ) || ( EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) )
    {
        exc = old_exc + L_EXC_MEM_DEC;
        Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); /*scaling of exc from previous frame*/
        Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); /*scaling of exc from previous frame  Q_exc*/

        IF( EQ_16( st_fx->last_L_frame, L_FRAME ) )
        {
            cbrate = L_add( st_fx->core_brate, 0 );
            IF( GT_32( cbrate, ACELP_24k40 ) )
            if ( GT_32( cbrate, ACELP_24k40 ) )
            {
                cbrate = L_add( ACELP_24k40, 0 );
                cbrate = ACELP_24k40;
                move32();
            }

            L_frame_for_cs = L_FRAME;
@@ -110,11 +109,13 @@ ivas_error acelp_core_switch_dec_fx(
        {
            IF( LE_32( st_fx->core_brate, ACELP_8k00 ) )
            {
                cbrate = L_add( ACELP_8k00, 0 );
                cbrate = ACELP_8k00;
                move32();
            }
            ELSE IF( LE_32( st_fx->core_brate, ACELP_14k80 ) )
            {
                cbrate = L_add( ACELP_14k80, 0 );
                cbrate = ACELP_14k80;
                move32();
            }
            ELSE
            {
@@ -141,10 +142,12 @@ ivas_error acelp_core_switch_dec_fx(

        syn_12k8_fx( 2 * L_SUBFR, Aq, exc, synth_intFreq, st_fx->mem_syn2_fx, 1, st_fx->Q_exc, st_fx->Q_syn );

        IF( st_fx->hPFstat->on && ( EQ_16( st_fx->last_bwidth, NB ) ) )
        test();
        IF( st_fx->hPFstat->on && ( st_fx->last_bwidth == NB ) )
        {
            Word16 tmp_noise, pitch_buf_tmp[2];
            tmp_noise = 0;
            move16();
            FOR( i = 0; i < 2; i++ )
            {
                pitch_buf_tmp[i] = L_SUBFR;
@@ -166,7 +169,7 @@ ivas_error acelp_core_switch_dec_fx(
        Copy( syn_fx_tmp + M, synth_intFreq, 2 * L_SUBFR );

        test();
        IF( st_fx->hPFstat->on && ( NE_16( st_fx->last_bwidth, NB ) ) )
        IF( st_fx->hPFstat->on && ( st_fx->last_bwidth != NB ) )
        {
            Copy( st_fx->hPFstat->mem_pf_in + L_SYN_MEM - M, bpf_error_signal, M );
            Copy( synth_intFreq, bpf_error_signal + M, L_SUBFR );
@@ -177,7 +180,6 @@ ivas_error acelp_core_switch_dec_fx(
            blend_subfr2_fx( bpf_error_signal + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2, synth_intFreq + L_SUBFR / 2 );
        }
        st_fx->hPFstat->on = 0;

        move16();

        IF( st_fx->flag_cna )
@@ -235,7 +237,7 @@ ivas_error acelp_core_switch_dec_fx(
        *Q_syn = 0;
        move16();

        Copy_Scale_sig( synth_intFreq + sub( NS2SA( i_mult( L_frame_for_cs, 50 ), L_sub( SWITCH_GAP_LENGTH_NS, DELAY_CLDFB_NS ) ), 2 ), mem_synth, add( NS2SA( i_mult( L_frame_for_cs, 50 ), DELAY_CLDFB_NS ), 2 ), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */
        Copy_Scale_sig( synth_intFreq + sub( NS2SA( i_mult( L_frame_for_cs, 50 ), ( SWITCH_GAP_LENGTH_NS - DELAY_CLDFB_NS ) ), 2 ), mem_synth, add( NS2SA( i_mult( L_frame_for_cs, 50 ), DELAY_CLDFB_NS ), 2 ), negate( st_fx->Q_syn ) ); /* Copy mem with Q0 */

        /*----------------------------------------------------------------*
         * BWE decoding
@@ -252,7 +254,7 @@ ivas_error acelp_core_switch_dec_fx(
            move16();
            ind1 = (Word16) get_next_indice_fx( st_fx, NOOFGAINBITS1 );
            move16();
            gain = usdequant_fx( ind1, MINVALUEOFFIRSTGAIN_FX, shr( DELTAOFFIRSTGAIN_FX, 3 ) ); /*Q13*/
            gain = usdequant_fx( ind1, MINVALUEOFFIRSTGAIN_FX, DELTAOFFIRSTGAIN_FX >> 3 ); /*Q13*/
            decode_bwe = 1;
            move16();
        }
@@ -416,7 +418,7 @@ ivas_error acelp_core_switch_dec_bfi_fx(
    tmp_noise = 0;
    move16();

    Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC );
    Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); // Q_exc
    exc = old_exc + L_EXC_MEM_DEC;
    IF( st_fx->hWIDec != NULL )
    {
@@ -429,7 +431,7 @@ ivas_error acelp_core_switch_dec_bfi_fx(
    exc2 = old_exc2 + L_EXC_MEM;
    IF( st_fx->hBWE_TD != NULL )
    {
        Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 );
        Copy( st_fx->hBWE_TD->old_bwe_exc_fx, old_bwe_exc, PIT16k_MAX * 2 ); // Q_exc
        bwe_exc = old_bwe_exc + PIT16k_MAX * 2;
    }
    ELSE
@@ -469,7 +471,7 @@ ivas_error acelp_core_switch_dec_bfi_fx(
    IF( EQ_16( st_fx->nelp_mode_dec, 1 ) )
    {
        Word16 gain_buf[NB_SUBFR16k];
        Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc );
        Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0
        st_fx->Q_exc = 0;
        move16();
        /* SC-VBR */
@@ -592,7 +594,7 @@ ivas_error acelp_core_switch_dec_bfi_fx(
                             negate( st_fx->Q_syn ), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer );

    /* output to Q0 */
    Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) );
    Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) ); // Q0

    cldfb_restore_memory( st_fx->cldfbSyn );

@@ -663,7 +665,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx(
    tmp_noise = 0;
    move16();

    Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC );
    Copy( st_fx->old_exc_fx, old_exc, L_EXC_MEM_DEC ); // Q_exc
    exc = old_exc + L_EXC_MEM_DEC;
    IF( st_fx->hWIDec != NULL )
    {
@@ -716,7 +718,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx(
    IF( EQ_16( st_fx->nelp_mode_dec, 1 ) )
    {
        Word16 gain_buf[NB_SUBFR16k];
        Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, -st_fx->Q_exc );
        Scale_sig( exc - L_EXC_MEM, L_EXC_MEM, negate( st_fx->Q_exc ) ); // Q0
        st_fx->Q_exc = 0;
        move16();
        /* SC-VBR */
@@ -771,7 +773,7 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx(
    Rescale_mem( Q_exc, &st_fx->prev_Q_syn, &st_fx->Q_syn, st_fx->mem_syn2_fx, st_fx->mem_syn_clas_estim_fx, 4, &st_fx->mem_deemph_fx,
                 hBPF->pst_old_syn_fx, &hBPF->pst_mem_deemp_err_fx, &st_fx->agc_mem_fx[1], st_fx->hPFstat, 1, 0, NULL );
#ifdef FIX_907_MEM_UPDATE_ISSUE
    Scale_sig( st_fx->mem_syn_r, L_SYN_MEM, sub( st_fx->Q_syn, Prev_Q_syn_r ) );
    Scale_sig( st_fx->mem_syn_r, L_SYN_MEM, sub( st_fx->Q_syn, Prev_Q_syn_r ) ); // Q_syn
#endif
    Copy( st_fx->mem_syn2_fx, tmp1, M );
    syn_12k8_fx( st_fx->L_frame, Aq, exc2, syn, tmp1, 1, Q_exc, st_fx->Q_syn );
@@ -820,12 +822,13 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx(
    Copy( tmp5, hBPF->Track_on_hist, L_TRACK_HIST );
    Copy( tmp6, hBPF->vibrato_hist, L_TRACK_HIST );
    hBPF->psf_att_fx = tmp7;
    move16();
    /*----------------------------------------------------------------*
     * Resamping to the output sampling frequency
     *----------------------------------------------------------------*/
    /* CLDFB analysis of the synthesis at internal sampling rate */
    Qtmp = sub( 11, st_fx->Q_syn );
    Copy_Scale_sig_16_32( syn, syn32, L_FRAME16k, Qtmp );
    Copy_Scale_sig_16_32( syn, syn32, L_FRAME16k, Qtmp ); // Q(11)
    IF( NE_32( ( error = cldfb_save_memory_ivas_fx( st_fx->cldfbAna ) ), IVAS_ERR_OK ) )
    {
        return error;
@@ -842,16 +845,17 @@ ivas_error acelp_core_switch_dec_bfi_ivas_fx(
    }
    /*cldfbSynthesisFiltering( st_fx->cldfbSyn, realBuffer, imagBuffer, &scaleFactor, synth_out,
                             negate(st_fx->Q_syn), CLDFB_NO_COL_MAX_SWITCH_BFI, workBuffer );*/
    Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, 1 );
    Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, 1 ); // Q_cldfb_state+1
    st_fx->cldfbSyn->Q_cldfb_state = add( st_fx->cldfbSyn->Q_cldfb_state, 1 );
    move16();
    Copy_Scale_sig_16_32( synth_out, synth32, L_FRAME48k, 5 ); /*11-5-1*/

    // cldfbSynthesis_ivas_fx(realBuffer, imagBuffer, synth_out, (int16_t)(st_fx->output_Fs * 0.01f), st_fx->cldfbSyn);
    cldfbSynthesis_ivas_fx( realBuffer, imagBuffer, synth32, extract_l( Mpy_32_16_1( st_fx->output_Fs, 328 ) ), st_fx->cldfbSyn );
    Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, -1 );
    Scale_sig32( st_fx->cldfbSyn->cldfb_state_fx, st_fx->cldfbSyn->cldfb_state_length, -1 ); // Q_cldfb_state-1
    st_fx->cldfbSyn->Q_cldfb_state = sub( st_fx->cldfbSyn->Q_cldfb_state, 1 );
    Copy_Scale_sig_32_16( synth32, synth_out, L_FRAME48k, -5 );
    move16();
    Copy_Scale_sig_32_16( synth32, synth_out, L_FRAME48k, -5 ); // 11-5-1 -> 11

    // Scale_sig( synth_out, L_FRAME48k, negate( st_fx->Q_syn ) );

@@ -871,19 +875,19 @@ static void decod_gen_voic_core_switch_fx(
    Decoder_State *st_fx,    /* i/o: decoder static memory       */
    const Word16 L_frame,    /* i  : length of the frame         */
    const Word16 sharpFlag,  /* i  : flag for formant sharpening */
    const Word16 *Aq,        /* i  : LP filter coefficient       */
    Word16 *exc,             /* i/o: adapt. excitation exc       */
    const Word16 *Aq,        /* i  : LP filter coefficient      Q_12 */
    Word16 *exc,             /* i/o: adapt. excitation exc      Q_exc */
    const Word32 core_brate, /* i  : switching frame bit-rate    */
    Word16 *Q_exc )
{
    Word16 T0, T0_frac, T0_min, T0_max; /* integer pitch variables                          */
    Word16 gain_pit, gain_code16;       /* pitch gain                                           */
    Word32 gain_code, L_tmp;            /* gain/normalized gain of the algebraic excitation     */
    Word32 norm_gain_code;              /* normalized gain of the algebraic excitation          */
    Word16 gain_inov;                   /* Innovation gain                                      */
    Word16 voice_fac;                   /* voicing factor                                       */
    Word16 code[L_SUBFR];               /* algebraic codevector                                 */
    Word16 pitch;                       /* pointer to floating pitch                            */
    Word32 norm_gain_code;              /* normalized gain of the algebraic excitation         Q16 */
    Word16 gain_inov;                   /* Innovation gain                                     Q12 */
    Word16 voice_fac;                   /* voicing factor                                       Q15*/
    Word16 code[L_SUBFR];               /* algebraic codevector                                 Q9*/
    Word16 pitch;                       /* pointer to floating pitch                            Q6*/
    Word16 i;                           /* tmp variables                                        */
    Word16 pitch_limit_flag;
    Word16 *pt1;
Loading