Commit 077e7b2c authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'swb_tbe_bwe_dec_fxd' into 'main'

wb_tbe_dec and wb_bwe_dec converted to fixed point.

See merge request !193
parents b0f4b839 65ea09c7
Loading
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -1529,4 +1529,48 @@ void synchonize_channels_mdct_sid_fx(
    Decoder_State *sts[CPE_CHANNELS],                           /* i/o: decoder state structure                 */
    const Word16 n                                             /* i  : channel number                          */
);

void ivas_interpolate_3_over_1_allpass_fx(
    const Word16 *input_fx,         /* i  : input signal            */ /* Q_input */
    const Word16 len,               /* i  : number of input samples */
    Word16 *out_fx,                 /* o  : output signal           */ /* Q_input */
    Word16 *mem_fx                  /* i/o: memory                  */ /* Q_input */
);

void ivas_wb_tbe_dec_fx(
    Decoder_State *st_fx,     /* i/o: decoder state structure         */
    const Word16 coder_type,  /* i  : coding type                     */
    Word32 *bwe_exc_extended, /* i  : bandwidth extended exciatation 2*Q_exc*/
    const Word16 Q_exc,
    const Word16 voice_factors[], /* i  : voicing factors                 */
    Word16 *synth,                /* o  : WB synthesis/final synthesis    */
    Word16 *Q_synth );

void ivas_GenShapedWBExcitation_fx(
    Word16 *excSHB,                   /* o : synthesized shaped shb exctiation Q_bwe_exc*/
    const Word16 *lpc_shb,            /* i : lpc coefficients Q12*/
    Word16 *exc4kWhtnd,               /* o : whitened synthesized shb excitation Q_bwe_exc*/
    Word32 *mem_csfilt,               /* i/o : memory Q_bwe_exc+16*/
    Word16 *mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/
    Word16 *mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/
    Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/
    Word16 *state_lpc_syn,            /* i/o : memory Q_bwe_exc*/
    const Word16 coder_type,          /* i : coding type */
    const Word16 *bwe_exc_extended,   /* i : bwidth extended exciatation Q_bwe_exc*/
    const Word16 Q_bwe_exc,
    Word16 bwe_seed[],            /* i/o : random number generator seed */
    const Word16 voice_factors[], /* i : voicing factor Q15*/
    const Word16 uv_flag,         /* i : unvoiced flag */
    const Word16 igf_flag );

Word16 ivas_wb_bwe_dec_fx(
    Decoder_State *st_fx,           /* i/o: decoder state structure                 */
    const Word16 output[],          /* i  : suntehsis @ internal Fs */
    Word16 *synth_fx,               /* i/o: ACELP core synthesis/final synthesis    */
    Word16 *hb_synth_fx,            /* o  : SHB synthesis/final synthesis           */
    const Word16 use_cldfb_for_dft, /* i  : flag to use of CLDFB for DFT Stereo     */
    const Word16 output_frame,      /* i  : frame length                            */
    Word16 *voice_factors_fx,       /* i  : voicing factors                         */
    const Word16 pitch_buf_fx[],    /* i  : pitch buffer                            */
    Word16 *Qpost );
#endif
+94 −0
Original line number Diff line number Diff line
@@ -1111,6 +1111,100 @@ void interpolate_3_over_2_allpass_fx(
  * Interpolate 3/1 using allpass iir polyphase filter. Delay 4 samples @48k
  *-------------------------------------------------------------------*/

#ifdef IVAS_FLOAT_FIXED
void ivas_interpolate_3_over_1_allpass_fx(
    const Word16 *input_fx,         /* i  : input signal            */ /* Q_input */
    const Word16 len,               /* i  : number of input samples */
    Word16 *out_fx,                 /* o  : output signal           */ /* Q_input */
    Word16 *mem_fx                  /* i/o: memory                  */ /* Q_input */
)
{
    /* mem of current frame would be stored in Qinput, so the next call to this function shoulf have Q_mem parameter set to prev_Q_input */
    Word16 i;
    Word16 Vu[2], Vm[2], Vl[2]; /* Outputs of three cascaded allpass stages (upper, middle, and lower) */
    Word16 *out1;
    Word16 mem_temp;
    const Word16 *filt_coeff_fx = allpass_poles_3_ov_2;

    out1 = &out_fx[0];

    FOR( i = 0; i < len; i++ )
    {
        /* Upper branch */
        /*Vu[0] = mem[0] + filt_coeff[0] * ( input_fx_temp[i] - mem[1] );
        Vu[1] = mem[1] + filt_coeff[1] * ( Vu[0] - mem[2] );
        mem[3] = mem[2] + filt_coeff[2] * ( Vu[1] - mem[3] );*/

        Vu[0] = add_sat( mem_fx[0], mult_r( filt_coeff_fx[0], sub_sat( input_fx[i], mem_fx[1] ) ) );
        move16(); /* all Vu's in : Q_current*/
        Vu[1] = add_sat( mem_fx[1], mult_r( filt_coeff_fx[1], sub_sat( Vu[0], mem_fx[2] ) ) );
        move16();
        mem_fx[3] = add_sat( mem_fx[2], mult_r( filt_coeff_fx[2], sub_sat( Vu[1], mem_fx[3] ) ) );
        move16();


        mem_fx[1] = Vu[0];
        move16();
        mem_fx[2] = Vu[1];
        move16();
        *out1++ = mem_fx[3];
        move16();

        /* Middle branch */
        /* Vm[0] = mem[0] + filt_coeff[3] * (input[i]-mem[4]);
        Vm[1] = mem[4] + filt_coeff[4] * (Vm[0]-mem[5]);
        mem[6] = mem[5] + filt_coeff[5] * (Vm[1]-mem[6]); */
        Vm[0] = add_sat( mem_fx[0], mult_r( filt_coeff_fx[3], sub_sat( input_fx[i], mem_fx[4] ) ) );
        move16();
        Vm[1] = add_sat( mem_fx[4], mult_r( filt_coeff_fx[4], sub_sat( Vm[0], mem_fx[5] ) ) );
        move16();
        mem_fx[6] = add_sat( mem_fx[5], mult_r( filt_coeff_fx[5], sub_sat( Vm[1], mem_fx[6] ) ) );
        move16();

        mem_fx[4] = Vm[0];
        move16();
        mem_fx[5] = Vm[1];
        move16();
        *out1++ = mem_fx[6];
        move16();

        /* Lower branch */
        /* Vl[0] = mem[0] + filt_coeff[6] * (input[i]-mem[7]);
        Vl[1] = mem[7] + filt_coeff[7] * (Vl[0]-mem[8]);
        mem[9] = mem[8] + filt_coeff[8] * (Vl[1]-mem[9]); */
        Vl[0] = add_sat( mem_fx[0], mult_r( filt_coeff_fx[6], sub_sat( input_fx[i], mem_fx[7] ) ) );
        move16();
        Vl[1] = add_sat( mem_fx[7], mult_r( filt_coeff_fx[7], sub_sat( Vl[0], mem_fx[8] ) ) );
        move16();
        mem_fx[9] = add_sat( mem_fx[8], mult_r( filt_coeff_fx[8], sub_sat( Vl[1], mem_fx[9] ) ) );
        move16();

        mem_fx[0] = input_fx[i];
        move16();
        mem_fx[7] = Vl[0];
        move16();
        mem_fx[8] = Vl[1];
        move16();
        *out1++ = mem_fx[9];
        move16();
    }
    /*LPF*/
    FOR( i = 0; i < len * 3; i++ )
    {
        mem_temp = out_fx[i];
        move16();
        out_fx[i] = sub_sat( mult_r( 18768 /*0.57276865021499168f Q15*/, add_sat( mem_fx[12], mem_fx[11] ) ), mult_r( 2425 /*0.074004974641176793f Q15*/, add_sat( mem_temp, mem_fx[10] ) ) );
        mem_fx[10] = mem_fx[11];
        move16();
        mem_fx[11] = mem_fx[12];
        move16();
        mem_fx[12] = mem_temp;
        move16();
    }
    return;
}
#endif

void interpolate_3_over_1_allpass_fx(
    const Word16 *input_fx,         /* i  : input signal            */ /* Q_input */
    const Word16 len,               /* i  : number of input samples */
+289 −0
Original line number Diff line number Diff line
@@ -915,6 +915,295 @@ void flip_spectrum_and_decimby4_fx(
/*--------------------------------------------------------------------------*/
/* CALLED FROM : */
/*==========================================================================*/
#ifdef IVAS_FLOAT_FIXED
void ivas_GenShapedWBExcitation_fx(
    Word16 *excSHB,                   /* o : synthesized shaped shb exctiation Q_bwe_exc*/
    const Word16 *lpc_shb,            /* i : lpc coefficients Q12*/
    Word16 *exc4kWhtnd,               /* o : whitened synthesized shb excitation Q_bwe_exc*/
    Word32 *mem_csfilt,               /* i/o : memory Q_bwe_exc+16*/
    Word16 *mem_genSHBexc_filt_down1, /* i/o : memory Q_bwe_exc*/
    Word16 *mem_genSHBexc_filt_down2, /* i/o : memory Q_bwe_exc*/
    Word16 *mem_genSHBexc_filt_down3, /* i/o : memory Q_bwe_exc*/
    Word16 *state_lpc_syn,            /* i/o : memory Q_bwe_exc*/
    const Word16 coder_type,          /* i : coding type */
    const Word16 *bwe_exc_extended,   /* i : bwidth extended exciatation Q_bwe_exc*/
    const Word16 Q_bwe_exc,
    Word16 bwe_seed[],            /* i/o : random number generator seed */
    const Word16 voice_factors[], /* i : voicing factor Q15*/
    const Word16 uv_flag,         /* i : unvoiced flag */
    const Word16 igf_flag )
{
    Word16 i, j, k;
    Word16 wht_fil_mem[LPC_WHTN_ORDER_WB];
    Word16 lpc_whtn[LPC_WHTN_ORDER_WB + 1];
    Word16 R_h[LPC_WHTN_ORDER_WB + 2], R_l[LPC_WHTN_ORDER_WB + 2];
    Word16 Q_R;
    Word16 excTmp[L_FRAME16k];
    Word16 excTmp2[L_FRAME16k / 4];
    Word16 excTmp2_frac[L_FRAME16k / 4];
    Word16 exc4k[L_FRAME16k / 4];
    Word16 exc4k_frac[L_FRAME16k / 4];
    Word32 exc4k_32[L_FRAME16k / 4];
    Word32 pow1, pow22;
    Word16 scale;
    Word32 excNoisyEnv[L_FRAME16k / 4];
    Word16 csfilt_num2[1] = { 1638 };              /* Q15*/
    Word16 neg_csfilt_den2[2] = { -32768, 31457 }; /* Q15 */
    Word32 L_tmp, Ltemp1, Ltemp2;
    Word16 temp1, temp2, exp;
    Word32 Lmax;
    Word16 max_val, n1, n2, sc;
    Word32 LepsP[LPC_WHTN_ORDER_WB + 1];
    Word16 tmp_vfac;
    Word16 avg_voice_fac;
#ifdef BASOP_NOGLOB_DECLARE_LOCAL
    Flag Overflow = 0;
#endif

    /*0.25f*sum_f(voice_factors, NB_SUBFR)*/
    L_tmp = L_mult( voice_factors[0], 8192 );
    FOR( i = 1; i < NB_SUBFR; i++ )
    {
        L_tmp = L_mac( L_tmp, voice_factors[i], 8192 );
    }
    avg_voice_fac = round_fx( L_tmp );

    test();
    test();
    test();
    test();
    IF( igf_flag != 0 && ( EQ_16( coder_type, VOICED ) || GT_16( avg_voice_fac, 11469 ) ) ) /*Q15 -> 0.35f*/
    {
        csfilt_num2[0] = 6554;
        move16(); /*Q15 -> 0.2f*/
        neg_csfilt_den2[1] = 26214;
        move16(); /*Q15 -> 0.8f*/
    }
    ELSE IF( igf_flag != 0 && ( EQ_16( coder_type, UNVOICED ) || LT_16( avg_voice_fac, 6654 ) ) ) /*Q15 -> 0.2f*/
    {
        csfilt_num2[0] = 328;
        move16(); /*Q15 -> 0.01f*/
        neg_csfilt_den2[1] = 32440;
        move16(); /*Q15 -> 0.99f*/
    }
    set16_fx( wht_fil_mem, 0, LPC_WHTN_ORDER_WB );
    Decimate_allpass_steep_fx( bwe_exc_extended, mem_genSHBexc_filt_down1, L_FRAME32k, excTmp );
    flip_spectrum_and_decimby4_fx( excTmp, exc4k, L_FRAME16k, mem_genSHBexc_filt_down2, mem_genSHBexc_filt_down3, 0 );

    IF( uv_flag )
    {
        create_random_vector_fx( exc4kWhtnd, L_FRAME16k / 4, bwe_seed );
        IF( LT_16( Q_bwe_exc, 5 ) )
        {

            FOR( i = 0; i < L_FRAME16k / 4; i++ )
            {
                exc4kWhtnd[i] = shl_r( exc4kWhtnd[i], sub( Q_bwe_exc, 5 ) ); /*Q(Q_bwe_exc)/Q5(if Q_bwe_exc > 5) */
            }
        }
    }
    ELSE
    {
        autocorr_fx( exc4k, LPC_WHTN_ORDER_WB + 1, R_h, R_l, &Q_R,
                     L_FRAME16k / 4, win_flatten_4k_fx, 0, 1 );

        /* Ensure R[0] isn't zero when entering Levinson Durbin */
        R_l[0] = s_max( R_l[0], 1 );
        move16();
        FOR( i = 1; i <= LPC_WHTN_ORDER_WB; i++ )
        {
            L_tmp = Mpy_32( R_h[i], R_l[i], wac_h[i - 1], wac_l[i - 1] );
            L_Extract( L_tmp, &R_h[i], &R_l[i] );
        }

        E_LPC_lev_dur( R_h, R_l, lpc_whtn, LepsP, LPC_WHTN_ORDER_WB, NULL );

        Copy_Scale_sig( lpc_whtn, lpc_whtn, LPC_WHTN_ORDER_WB + 1, sub( norm_s( lpc_whtn[0] ), 2 ) );

        fir_fx( exc4k, lpc_whtn, exc4kWhtnd, wht_fil_mem, L_FRAME16k / 4,
                LPC_WHTN_ORDER_WB, 0, 3 );

        /* Ensure pow1 is greater than zero when computing normalization */
        max_val = 0;
        FOR( i = 0; i < L_FRAME16k / 4; i++ )
        {
            excTmp2[i] = abs_s( exc4kWhtnd[i] );
            move16(); /* Q_bwe_exc */
            max_val = s_max( max_val, excTmp2[i] );
            move16();
        }

        IF( max_val == 0 )
        {
            pow1 = 1;
            move16();
            n1 = 0;
            move16();
        }
        ELSE
        {
            n1 = norm_s( max_val );
            FOR( i = 0; i < L_FRAME16k / 4; i++ )
            {
#ifdef BASOP_NOGLOB
                excTmp2_frac[i] = shl_o( excTmp2[i], n1, &Overflow ); // Q_bwe_exc + n1
#else
                excTmp2_frac[i] = shl( excTmp2[i], n1 );
#endif
                move16(); /* Q14 */
            }
            n1 = sub( sub( 14, n1 ), Q_bwe_exc );
            pow1 = 1;
            FOR( i = 0; i < L_FRAME16k / 4; i++ )
            {
#ifdef BASOP_NOGLOB
                L_tmp = L_mult_o( excTmp2_frac[i], excTmp2_frac[i], &Overflow ); /* Q29 */
                pow1 = L_add_o( pow1, L_shr( L_tmp, 10 ), &Overflow ); /* Q22 */
#else
                L_tmp = L_mult( excTmp2_frac[i], excTmp2_frac[i] ); /* Q29 */
                pow1 = L_add( pow1, L_shr( L_tmp, 7 ) );            /* Q22 */
#endif
            }
        }

        FOR( i = 0; i < L_FRAME16k / 4; i++ )
        {
#ifdef BASOP_NOGLOB
            excNoisyEnv[i] = L_add_o( *mem_csfilt, L_mult_o( csfilt_num2[0], excTmp2[i], &Overflow ), &Overflow );
#else
            excNoisyEnv[i] = L_add( *mem_csfilt, L_mult( csfilt_num2[0], excTmp2[i] ) );
#endif
            move32(); /* Q_bwe_exc+16  */
            *mem_csfilt = Mult_32_16( excNoisyEnv[i], neg_csfilt_den2[1] );
            move32(); /* Q_bwe_exc+16 */
        }

        create_random_vector_fx( exc4k, L_FRAME16k / 4, bwe_seed );

        /* Ensure pow22 is greater than zero when computing normalization */
        Lmax = 0;
        FOR( i = 0; i < L_FRAME16k / 4; i++ )
        {
            exc4k_32[i] = Mult_32_16( excNoisyEnv[i], exc4k[i] );
            move32(); /* Q_bwe_exc+6 */
            Lmax = L_max( Lmax, L_abs( exc4k_32[i] ) );
        }

        IF( Lmax == 0 )
        {
            pow22 = 1;
            move16();
            n2 = 0;
            move16();
            set16_fx( exc4k_frac, 0, L_FRAME16k / 4 );
        }
        ELSE
        {
            n2 = norm_l( Lmax );
            FOR( i = 0; i < L_FRAME16k / 4; i++ )
            {
#ifdef BASOP_NOGLOB
                exc4k_frac[i] = extract_h( L_shl_o( exc4k_32[i], n2, &Overflow ) ); /* Q(14-n2) */
#else
                exc4k_frac[i] = extract_h( L_shl( exc4k_32[i], n2 ) );                   /* Q(14-n2) */
#endif
            }
            n2 = 30 - n2 - ( Q_bwe_exc + 6 );
            pow22 = 1;
            FOR( i = 0; i < L_FRAME16k / 4; i++ )
            {
#ifdef BASOP_NOGLOB
                L_tmp = L_mult_o( exc4k_frac[i], exc4k_frac[i], &Overflow ); /* Q29 */
                pow22 = L_add_o( pow22, L_shr( L_tmp, 10 ), &Overflow );     /* Q22     */
#else
                L_tmp = L_mult( exc4k_frac[i], exc4k_frac[i] );                          /* Q29 */
                pow22 = L_add( pow22, L_shr( L_tmp, 7 ) );                               /* Q22     */
#endif
            }
        }

        test();
        test();
        IF( EQ_16( coder_type, UNVOICED ) || ( igf_flag != 0 && LT_16( avg_voice_fac, 6654 ) ) )
        {
            L_tmp = root_a_over_b_fx( pow1, sub( 19, shl( n1, 1 ) ), pow22, sub( 19, shl( n2, 1 ) ), &exp );
#ifdef BASOP_NOGLOB
            scale = round_fx_o( L_shl_o( L_tmp, exp, &Overflow ), &Overflow ); /*Q15 */
#else
            scale = round_fx( L_shl( L_tmp, exp ) );                                     /*Q15 */
#endif
            sc = sub( add( n2, Q_bwe_exc ), 14 );
            FOR( i = 0; i < L_FRAME16k / 4; i++ )
            {
#ifdef BASOP_NOGLOB
                exc4kWhtnd[i] = round_fx_o( L_shl_o( L_mult_o( exc4k_frac[i], scale, &Overflow ), sc, &Overflow ), &Overflow ); /*  Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */
#else
                exc4kWhtnd[i] = round_fx( L_shl( L_mult( exc4k_frac[i], scale ), sc ) ); /*  Q_bwe_exc+n2-10+16+ Q_bwe_exc + n2 -14 -16 = //Q_bwe_exc */
#endif
            }
        }
        ELSE
        {
            sc = sub( add( n2, Q_bwe_exc ), 14 ); /* Q_bwe_exc+n2-14*/

            k = 0;
            FOR( i = 0; i < 4; i++ )
            {
                test();
                IF( igf_flag != 0 && EQ_16( coder_type, VOICED ) )
                {
                    /*tmp_vfac = 2*voice_factors[i];
                      tmp_vfac = min(1, tmp_vfac);*/
#ifdef BASOP_NOGLOB
                    tmp_vfac = shl_o( voice_factors[i], 1, &Overflow );
#else
                    BASOP_SATURATE_WARNING_OFF_EVS
                    tmp_vfac = shl( voice_factors[i], 1 );
                    BASOP_SATURATE_WARNING_ON_EVS
#endif
                }
                ELSE
                {
                    tmp_vfac = voice_factors[i];
                    move16();
                }

                Ltemp1 = root_a_fx( L_deposit_h( tmp_vfac ), 31, &exp );
#ifdef BASOP_NOGLOB
                temp1 = round_fx_o( L_shl_o( Ltemp1, exp, &Overflow ), &Overflow ); /* Q15 */
#else
                temp1 = round_fx( L_shl( Ltemp1, exp ) );                                /* Q15 */
#endif
                L_tmp = Mult_32_16( pow1, sub( 32767, tmp_vfac ) ); /* Q22*/
                Ltemp2 = root_a_over_b_fx( L_tmp, sub( 19, shl( n1, 1 ) ), pow22, sub( 19, shl( n2, 1 ) ), &exp );
#ifdef BASOP_NOGLOB
                temp2 = round_fx_o( L_shl_o( Ltemp2, exp, &Overflow ), &Overflow ); /* Q15 */
#else
                temp2 = round_fx( L_shl( Ltemp2, exp ) );                                /* Q15 */
#endif
                FOR( j = 0; j < L_FRAME16k / 16; j++ )
                {
#ifdef BASOP_NOGLOB
                    L_tmp = L_mult_o( temp1, exc4kWhtnd[k], &Overflow );                                                        /* Q(16+Q_bwe_exc) */
                    L_tmp = L_add_o( L_tmp, L_shl_o( L_mult_o( temp2, exc4k_frac[k], &Overflow ), sc, &Overflow ), &Overflow ); /* Q(16+Q_bwe_exc) */
                    exc4kWhtnd[k] = round_fx_o( L_tmp, &Overflow );                                                             /* Q_bwe_exc */
#else
                    L_tmp = L_mult( temp1, exc4kWhtnd[k] );                              /* Q(16+Q_bwe_exc) */
                    L_tmp = L_add( L_tmp, L_shl( L_mult( temp2, exc4k_frac[k] ), sc ) ); /* Q(16+Q_bwe_exc) */
                    exc4kWhtnd[k] = round_fx( L_tmp );                                   /* Q_bwe_exc */
#endif
                    k++;
                }
            }
        }
    }

    Syn_filt_s( 0, lpc_shb, LPC_SHB_ORDER_WB, exc4kWhtnd, excSHB, L_FRAME16k / 4, state_lpc_syn, 1 );

    return;
}
#endif

void GenShapedWBExcitation_fx( 
    Word16* excSHB,  /* o : synthesized shaped shb exctiation Q_bwe_exc*/
    const Word16* lpc_shb,                      /* i : lpc coefficients Q12*/
+12 −0
Original line number Diff line number Diff line
@@ -374,6 +374,13 @@ ivas_error init_decoder(
        }

        td_bwe_dec_init( st->hBWE_TD, st->extl, st->output_Fs );

#ifdef IVAS_FLOAT_FIXED
        st->prev_Q_bwe_exc = 31;
        st->prev_Qx = 0;
        st->prev_ener_fx_Q = 31;
        st->prev_frame_pow_exp = 0;
#endif
    }
    else
    {
@@ -395,6 +402,11 @@ ivas_error init_decoder(
        }

        fd_bwe_dec_init_flt( st->hBWE_FD );
#ifdef IVAS_FLOAT_FIXED
        st->hBWE_FD->old_wtda_swb_fx_exp = 0;
        st->hBWE_FD->mem_imdct_exp_fx = 0;
        st->prev_Q_synth = 0;
#endif
    }
    else
    {
+171 −0

File changed.

Preview size limit exceeded, changes collapsed.

Loading