Commit 7b0f7cb7 authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Integration of fixed point sub-functions - 3

[x] Porting functions in ism path.
[x] acelp_core_dec top down MR (Part 1)
[x] fixed version of masa_decode function included.
[x] bw_switching_pre_proc function included.
parent ae70e60a
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -144,6 +144,7 @@
    <ClCompile Include="..\lib_dec\acelp_core_dec_fx.c">
      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
    </ClCompile>
    <ClCompile Include="..\lib_dec\acelp_core_dec_ivas_fx.c" />
    <ClCompile Include="..\lib_dec\acelp_core_switch_dec.c" />
    <ClCompile Include="..\lib_dec\acelp_core_switch_dec_fx.c" />
    <ClCompile Include="..\lib_dec\amr_wb_dec.c" />
+297 −887

File changed.

Preview size limit exceeded, changes collapsed.

+272 −0
Original line number Diff line number Diff line
@@ -278,6 +278,278 @@ void enhancer_fx(
    }
}


/*======================================================================================*/
/* FUNCTION : enhancer_fx()																*/
/*--------------------------------------------------------------------------------------*/
/* PURPOSE : Enhancement of the excitation signal before synthesis						*/
/*--------------------------------------------------------------------------------------*/
/* INPUT ARGUMENTS :																	*/
/* _ (Word32) core_brate : decoder bitrate												*/
/* _ (Word16) Opt_AMR_WB : flag indicating AMR-WB IO mode								*/
/* _ (Word16) coder_type : coder type													*/
/* _ (Word16) i_subfr : subframe number													*/
/* _ (Word16) voice_fac : subframe voicing estimation  (Q15)							*/
/* _ (Word16) stab_fac : LP filter stablility measure  (Q15)							*/
/* _ (Word32) norm_gain_code : normalised innovative cb. gain  (Q16)					*/
/* _ (Word16) gain_inov : gain of the unscaled innovation (Q12) 						*/
/* _ (Word16) gain_pit_fx : Pitch gain			(Q14)									*/
/* _ (Word16) Q_exc : Q of the excitation												*/
/* _ (Word16) Enc : Encoder  = 1; decoder = 0 											*/
/*--------------------------------------------------------------------------------------*/
/* OUTPUT ARGUMENTS :																	*/
/* _ (Word16*) voice_factors_fx : TBE voicing factor (Q15)								*/
/*--------------------------------------------------------------------------------------*/
/* INPUT/OUTPUT ARGUMENTS :																*/
/* _ (Word32*) gc_threshold : gain code threshold  (Q16)								*/
/* _ (Word16*[]) code : innovation (Q12)												*/
/* _ (Word16*[]) exc2 : adapt. excitation/total exc (Q0)								*/
/* _ (struct dispMem_fx*) dm_fx : phase dispersion algorithm memory						*/
/*								 (a[0]->Q0,a[1]->Q16,a[2-7]->Q14)						*/
/*--------------------------------------------------------------------------------------*/

/* _ None																				*/
/*--------------------------------------------------------------------------------------*/
/* RETURN ARGUMENTS :																	*/
/* _ None																				*/
/*======================================================================================*/
void enhancer_ivas_fx(
    const Word16 codec_mode,   /* i  : flag indicating Codec Mode              */
    const Word32 core_brate,   /* i  : decoder bitrate                          */
    const int16_t cbk_index,    /* i  :                                         */
    const Word16 Opt_AMR_WB,   /* i  : flag indicating AMR-WB IO mode           */
    const Word16 coder_type,   /* i  : coder type                               */
    const Word16 i_subfr,      /* i  : subframe number                          */
    const Word16 L_frame,      /* i  : frame size                               */
    const Word16 voice_fac,    /* i  : subframe voicing estimation         Q15  */
    const Word16 stab_fac,     /* i  : LP filter stablility measure        Q15  */
    Word32 norm_gain_code,  /* i  : normalised innovative cb. gain   Q16  */
    const Word16 gain_inov,    /* i  : gain of the unscaled innovation     Q12  */
    Word32 *gc_threshold,/* i/o: gain code threshold                 Q16  */
    Word16 *code,        /* i/o: innovation                          Q12  */
    Word16 *exc2,        /* i/o: adapt. excitation/total exc.        Q_exc*/
    const Word16 gain_pit,     /* i  : quantized pitch gain                Q14  */
    struct dispMem_fx *dm_fx,  /* i/o: phase dispersion algorithm memory        */
    const Word16 Q_exc         /* i  : Q of the excitation                      */
)
{
    Word16 tmp, fac, *pt_exc2;
    Word16 i;
    Word32 L_tmp;
    Word16 gain_code_hi;
    Word16 pit_sharp, tmp16;
    Word16 excp[L_SUBFR], sc;



    pit_sharp = gain_pit;
    move16();       /* to remove gcc warning */
    pt_exc2 = exc2 + i_subfr;
    move16();

    /*------------------------------------------------------------*
     * Phase dispersion to enhance noise at low bit rate
     *------------------------------------------------------------*/

    i = 2;
    move16(); /* no dispersion */
    IF(Opt_AMR_WB)
    {
        IF(LE_32(core_brate, ACELP_6k60))
        {
            i = 0;
            move16();   /* high dispersion  */
        }
        ELSE if (LE_32(core_brate, ACELP_8k85))
        {
            i = 1;
            move16();    /* low dispersion  */
        }
    }
    ELSE IF( EQ_16(codec_mode, MODE1) && NE_16(coder_type, UNVOICED))

    {
        test();
        test();
        test();
        test();
        IF(LE_32(core_brate, ACELP_7k20))
        {
            i = 0;
            move16(); /* high dispersion  */
        }
        ELSE IF ((EQ_16(coder_type, GENERIC) || EQ_16(coder_type, TRANSITION) || EQ_16(coder_type, AUDIO) || EQ_16(coder_type, INACTIVE)) && LE_32(core_brate, ACELP_9k60))
        {
            i = 1;
            move16();    /* low dispersion  */
        }
    }
    ELSE IF( EQ_16( codec_mode, MODE2 ) )
    {
        IF( ( NE_16( coder_type, VOICED ) && LE_16( cbk_index, 2 ) ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( L_frame, L_FRAME ) && LE_16( cbk_index, 10 ) ) || ( EQ_16( coder_type, UNVOICED ) && EQ_16( L_frame, L_FRAME16k ) && LE_16( cbk_index, 14 ) ) )
        {
            i = 0; /* high dispersion  */
        }
        ELSE IF( NE_16( coder_type, VOICED ) && LE_16( cbk_index, 7 ) )
        {
            i = 1; /* low dispersion  */
        }
    }
    ELSE IF( EQ_16(codec_mode, MODE1) && EQ_16(coder_type, UNVOICED) && cbk_index /*uc_two_stage_flag*/ )
    {
        i = 0; /* high dispersion  */
    }

    phase_dispersion_fx(norm_gain_code, gain_pit, code, i, dm_fx);

    /*------------------------------------------------------------
     * noise enhancer
     *
     * - Enhance excitation on noise. (modify gain of code)
     *   If signal is noisy and LPC filter is stable, move gain
     *   of code 1.5 dB toward gain of code threshold.
     *   This decreases by 3 dB noise energy variation.
     *-----------------------------------------------------------*/

     /* tmp = 0.5f * (1.0f - voice_fac) */
#ifdef BASOP_NOGLOB
    tmp = msu_r_sat(0x40000000, voice_fac, 16384); /*Q15 */ /* 1=unvoiced, 0=voiced */
#else
    tmp = msu_r(0x40000000, voice_fac, 16384); /*Q15 */ /* 1=unvoiced, 0=voiced */
#endif
    /* fac = stab_fac * tmp */
    fac = mult(stab_fac, tmp); /*Q15*/

    IF(LT_32(norm_gain_code, *gc_threshold))
    {
        L_tmp = Madd_32_16(norm_gain_code, norm_gain_code, 6226);/*Q16 */
        L_tmp = L_min(L_tmp, *gc_threshold);/*Q16 */
    }
    ELSE
    {
        L_tmp = Mult_32_16(norm_gain_code, 27536);/*Q16 */
        L_tmp = L_max(L_tmp, *gc_threshold); /*Q16 */
    }
    *gc_threshold = L_tmp;
    move32(); /*Q16 */

    /* gain_code = (fac * tmp) + (1.0 - fac) * gain_code ==> fac * (tmp - gain_code) + gain_code */
    L_tmp = L_sub(L_tmp, norm_gain_code); /*Q16 */
    norm_gain_code = Madd_32_16(norm_gain_code, L_tmp, fac);/*Q16 */

    /* gain_code *= gain_inov - Inverse the normalization */
    L_tmp = Mult_32_16(norm_gain_code, gain_inov); /*Q13*/ /* gain_inov in Q12 */

    sc = 6;
    move16();

    gain_code_hi = round_fx(L_shl(L_tmp, add(Q_exc, 3))); /* in Q_exc */

    /*------------------------------------------------------------*
     * pitch enhancer
     *
     * - Enhance excitation on voiced. (HP filtering of code)
     *   On voiced signal, filtering of code by a smooth fir HP
     *   filter to decrease energy of code at low frequency.
     *------------------------------------------------------------*/
    test();
    IF(!Opt_AMR_WB && EQ_16(coder_type, UNVOICED))
    {
        /* Copy(code, exc2, L_SUBFR) */
        FOR(i = 0; i < L_SUBFR; i++)
        {
            pt_exc2[i] = round_fx(L_shl(L_mult(gain_code_hi, code[i]), sc)); /*Q0 */ /* code in Q12 (Q9 for encoder) */
        }
    }
    ELSE
    {
        test();
        test();
        IF(Opt_AMR_WB && (EQ_32(core_brate,ACELP_8k85) || EQ_32(core_brate,ACELP_6k60)))
        {
#ifdef BASOP_NOGLOB
            pit_sharp = shl_sat(gain_pit, 1); /* saturation can occur here Q14 -> Q15 */
#else
            pit_sharp = shl(gain_pit, 1); /* saturation can occur here Q14 -> Q15 */
#endif
            /* saturation takes care of "if (pit_sharp > 1.0) { pit_sharp=1.0; }" */
            IF(GT_16(pit_sharp, 16384))
            {
                tmp16 = mult(pit_sharp, 8192);
                FOR(i = 0; i < L_SUBFR; i++)
                {
                    /* excp[i] = pt_exc2[i] * pit_sharp * 0.25 */
                    excp[i] = mult_r(pt_exc2[i], tmp16);
                    move16();
                }
            }
        }

        IF(EQ_16(L_frame, L_FRAME16k))
        {
            /* tmp = 0.150 * (1.0 + voice_fac) */
            /* 0.30=voiced, 0=unvoiced */
            tmp = mac_r(0x10000000L, voice_fac, 4915);/*Q15 */
        }
        ELSE
        {
            /* tmp = 0.125 * (1.0 + voice_fac) */
            /* 0.25=voiced, 0=unvoiced */
            tmp = mac_r(0x10000000L, voice_fac, 4096);/*Q15 */
        }

            /*-----------------------------------------------------------------
             * Do a simple noncasual "sharpening": effectively an FIR
             * filter with coefs [-tmp 1.0 -tmp] where tmp=0...0.25.
             * This is applied to code and add_fxed to exc2
             *-----------------------------------------------------------------*/
             /* pt_exc2[0] += code[0] - tmp * code[1] */
             L_tmp = L_deposit_h(code[0]);                   /* if Enc :Q9 * Q15 -> Q25 */
             L_tmp = L_msu(L_tmp, code[1], tmp);             /* Q12 * Q15 -> Q28 */
             L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc);
             pt_exc2[0] = msu_r(L_tmp, -32768, pt_exc2[0]);
             move16();/* in Q_exc */

             FOR(i = 1; i < L_SUBFR - 1; i++)
             {
                 /* pt_exc2[i] += code[i] - tmp * code[i-1] - tmp * code[i+1] */
                 L_tmp = L_msu(-32768, code[i], -32768);
                 L_tmp = L_msu(L_tmp, code[i + 1], tmp);
                 tmp16 = msu_r(L_tmp, code[i - 1], tmp);
                 L_tmp = L_shl(L_mult(gain_code_hi, tmp16), sc);
#ifdef BASOP_NOGLOB
                 pt_exc2[i] = msu_r_sat(L_tmp, -32768, pt_exc2[i]);
#else
                 pt_exc2[i] = msu_r(L_tmp, -32768, pt_exc2[i]);
#endif
                 move16(); /* in Q_exc */
             }

             /* pt_exc2[L_SUBFR-1] += code[L_SUBFR-1] - tmp * code[L_SUBFR-2] */
             L_tmp = L_deposit_h(code[L_SUBFR - 1]);/*Q28 */
             L_tmp = L_msu(L_tmp, code[L_SUBFR - 2], tmp);/*Q28 */
             L_tmp = L_shl(L_mult(gain_code_hi, extract_h(L_tmp)), sc);
             pt_exc2[L_SUBFR - 1] = msu_r(L_tmp, -32768, pt_exc2[L_SUBFR - 1]);
             move16();/* in Q_exc */
             test();
             test();
             IF(Opt_AMR_WB && (EQ_32(core_brate,ACELP_8k85) || EQ_32(core_brate,ACELP_6k60)))
             {
                 IF(GT_16(pit_sharp, 16384))
                 {
                     FOR(i = 0; i < L_SUBFR; i++)
                     {
                         /* excp[i] += pt_exc2[i] */
                         excp[i] = add(excp[i], pt_exc2[i]);
                         move16();
                     }
                     agc2_fx(pt_exc2, excp, L_SUBFR);
                     Copy(excp, pt_exc2, L_SUBFR);
                 }
             }
    }
}

/*---------------------------------------------------------*
 * Enhancement of the excitation signal before synthesis
 *---------------------------------------------------------*/
+0 −2
Original line number Diff line number Diff line
@@ -93,7 +93,6 @@ Word16 est_tilt_fx( /* o : tilt of the code Q15 *
    return tilt_code;
}

#ifdef IVAS_FLOAT_FIXED
/*======================================================================*/
/* FUNCTION : est_tilt_ivas_fx()												*/
/*-----------------------------------------------------------------------*/
@@ -191,7 +190,6 @@ Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15

    return tilt_code;
}
#endif

/*-------------------------------------------------------------------*
 * Est_tilt2:
+0 −1
Original line number Diff line number Diff line
@@ -1321,7 +1321,6 @@ void lpc_from_spectrum_flt(
    return;
}


/*-------------------------------------------------------------------
 * FdCng_exc_flt()
 *
Loading