Commit 3327a86f authored by Fabian Bauer's avatar Fabian Bauer
Browse files

add macro and code for HARMONIZE_2598_tcx_arith_decode_envelope

parent 6dd82350
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -92,6 +92,8 @@
#define NONBE_FIX_ISSUE_2206_AVOID_OVERFLOW_MSVQ_Interpol_Tran_fx /* FhG: Fix saturation crash in MSVQ_Interpol_Tran_fx() */
#define NONBE_FIX_ISSUE_2206_SWB_EXPERIMENT_FIX_2527    /* Fix crash from issue #2527 */
#define FIX_FLOAT_1539_G192_FORMAT_SWITCH               /* VA/Nokia: reintroduce format switching for g192 bitstreams */
#define HARMONIZE_2598_tcx_arith_decode_envelope        /* FhG: harmonize tcx_arith_decode_envelope between EVS and IVAS versions */


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

+24 −2
Original line number Diff line number Diff line
@@ -7997,6 +7997,7 @@ void decoder_tcx_post_fx(
    Word16 *A,
    Word16 bfi );

#ifndef HARMONIZE_2598_tcx_arith_decode_envelope
void tcx_arith_decode_envelope_fx(
    Word32 q_spectrum[],  /* o: quantised MDCT coefficients     Q31-e */
    Word16 *q_spectrum_e, /* o: MDCT exponent                   Q0 */
@@ -8014,6 +8015,7 @@ void tcx_arith_decode_envelope_fx(
    Word16 *nf_seed,        /* o: noise filling seed              Q0 */
    Word16 low_complexity   /* i: low-complexity flag           Q0 */
);
#endif

void tcx_decoder_memory_update(
    Word16 *xn_buf,    /* i/o: mdct output buffer used also as temporary buffer  : Q0 */
@@ -9958,9 +9960,28 @@ void tcx_arith_render_envelope_ivas_fx(
    Word32 env[]              /* o  : shaped signal envelope                     Q16*/
);

#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
void tcx_arith_decode_envelope_fx(
    Decoder_State *st,
    /* i/o: coder state                   */                 /*EVS: move argument 5->1 */
    Word32 q_spectrum[],                                     /* o  : quantised MDCT coefficients Q(31-q_spectrum_e)  */
    Word16 *q_spectrum_e,                                    /* o  : MDCT exponent                 */
    const Word16 L_frame,                                    /* i  : frame or MDCT length          */
    Word16 L_spec,                                           /* i  : length w/o BW limitation      */
    const Word16 A_ind[],                                    /* i  : quantised LPC coefficients    */
    const Word16 target_bits,                                /* i  : number of available bits      */
    Word16 prm[],                                            /* i  : bitstream parameters          */
    const Word16 use_hm,                                     /* i  : use HM in current frame?      */
    Word16 prm_hm[],                                   /* i  : HM parameter area             */
    Word16 tcxltp_pitch,                                     /* i  : TCX LTP pitch in FD, -1 if n/a*/
    Word16 *arith_bits,                                      /* o  : bits used for ari. coding     */
    Word16 *signaling_bits,                                  /* o  : bits used for signaling       */
    Word16 *nf_seed,                                         /* o  : noise filling seed         Q0 */
    const Word16 low_complexity                              /* i  : low-complexity flag           */
#else
void tcx_arith_decode_envelope_ivas_fx(
    Decoder_State *st,          /* i/o: coder state                   */
    Word32 q_spectrum[],        /* o  : quantised MDCT coefficients   */
    Word32 q_spectrum[],        /* o  : quantised MDCT coefficients Q(31-q_spectrum_e)  */
    Word16 *q_spectrum_e,       /* o  : MDCT exponent                 */
    const Word16 L_frame,       /* i  : frame or MDCT length          */
    Word16 L_spec,              /* i  : length w/o BW limitation      */
@@ -9968,11 +9989,12 @@ void tcx_arith_decode_envelope_ivas_fx(
    const Word16 target_bits,   /* i  : number of available bits      */
    Word16 prm[],               /* i  : bitstream parameters          */
    const Word16 use_hm,        /* i  : use HM in current frame?      */
    const Word16 prm_hm[],      /* i  : HM parameter area             */
    Word16 prm_hm[],      /* i  : HM parameter area             */
    Word16 tcxltp_pitch,        /* i  : TCX LTP pitch in FD, -1 if n/a*/
    Word16 *arith_bits,         /* o  : bits used for ari. coding     */
    Word16 *signaling_bits,     /* o  : bits used for signaling       */
    const Word16 low_complexity /* i  : low-complexity flag           */
#endif
);

void UnmapIndex_fx(
+144 −82
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ static Word16 tcx_arith_decode_fx(
    return bp;
}

#ifndef HARMONIZE_2598_tcx_arith_decode_envelope
void tcx_arith_decode_envelope_fx(
    Word32 q_spectrum[],    /* o  : quantised MDCT coefficients     Q31-e */
    Word16 *q_spectrum_e,   /* o  : MDCT exponent                   Q0 */
@@ -209,6 +210,7 @@ void tcx_arith_decode_envelope_fx(

    set32_fx( q_spectrum + L_spec, 0, sub( L_frame, L_spec ) );
}
#endif

/*-------------------------------------------------------*
 * tcx_arith_decode()
@@ -293,6 +295,25 @@ static Word16 tcx_arith_decode_ivas_fx(
 *
 *-------------------------------------------------------*/

#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
void tcx_arith_decode_envelope_fx(
    Decoder_State *st,
    /* i/o: coder state                   */ /*EVS: move argument 5->1 */
    Word32 q_spectrum[],                     /* o  : quantised MDCT coefficients Q(31-q_spectrum_e)  */
    Word16 *q_spectrum_e,                    /* o  : MDCT exponent                 */
    const Word16 L_frame,                    /* i  : frame or MDCT length          */
    Word16 L_spec,                           /* i  : length w/o BW limitation      */
    const Word16 A_ind[],                    /* i  : quantised LPC coefficients    */
    const Word16 target_bits,                /* i  : number of available bits      */
    Word16 prm[],                            /* i  : bitstream parameters          */
    const Word16 use_hm,                     /* i  : use HM in current frame?      */
    Word16 prm_hm[],                   /* i  : HM parameter area             */
    Word16 tcxltp_pitch,                     /* i  : TCX LTP pitch in FD, -1 if n/a*/
    Word16 *arith_bits,                      /* o  : bits used for ari. coding     */
    Word16 *signaling_bits,                  /* o  : bits used for signaling       */
    Word16 *nf_seed,                         /* o  : noise filling seed         Q0 */
    const Word16 low_complexity              /* i  : low-complexity flag           */
#else
void tcx_arith_decode_envelope_ivas_fx(
    Decoder_State *st,          /* i/o: coder state                   */
    Word32 q_spectrum[],        /* o  : quantised MDCT coefficients Q(31-q_spectrum_e)  */
@@ -308,6 +329,7 @@ void tcx_arith_decode_envelope_ivas_fx(
    Word16 *arith_bits,         /* o  : bits used for ari. coding     */
    Word16 *signaling_bits,     /* o  : bits used for signaling       */
    const Word16 low_complexity /* i  : low-complexity flag           */
#endif
)
    {
        Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */
@@ -326,7 +348,7 @@ void tcx_arith_decode_envelope_ivas_fx(
        test();
        test();
        test();
    IF( GT_16( L_spec, N_MAX_ARI ) || ( ( st->element_mode == EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) ||
        IF( GT_16( L_spec, N_MAX_ARI ) || ( EQ_16( st->element_mode, EVS_MONO ) && GT_16( target_bits, ( ACELP_13k20 / FRAMES_PER_SEC ) ) ) ||
            ( EQ_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE / FRAMES_PER_SEC ) ) ) ) ||
            ( GT_16( st->element_mode, IVAS_SCE ) && ( GT_16( st->bits_frame_nominal, ( LPC_SHAPED_ARI_MAX_RATE_CPE / FRAMES_PER_SEC ) ) ) ) ||
            ( target_bits <= 0 ) )
@@ -355,14 +377,37 @@ void tcx_arith_decode_envelope_ivas_fx(
        move16();
        gamma_uw = st->inv_gamma;
        move16();

#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
        IF( EQ_16( st->element_mode, EVS_MONO ) )
        {
            tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env );
        }
        ELSE
        {
#endif
            tcx_arith_render_envelope( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env );
#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
        }
#endif
        tcx_arith_render_envelope_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env );


        IF( use_hm != 0 )
        {
            IF( prm_hm[0] != 0 )
            {
#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
                IF( EQ_16( st->element_mode, EVS_MONO ) )
                {
                    tcx_hm_decode( L_spec, env, target_bits, hTcxCfg->coder_type, prm_hm, tcxltp_pitch, &hm_bits );
                }
                ELSE
                {
#endif
                    tcx_hm_decode( L_spec, env, target_bits, st->coder_type, prm_hm, tcxltp_pitch, &hm_bits );
#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
                }
#endif

                IF( hm_bits < 0 )
                {
@@ -385,6 +430,13 @@ void tcx_arith_decode_envelope_ivas_fx(
            *signaling_bits = add( *signaling_bits, hm_bits );
            move16();
        }
#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
        IF( EQ_16( st->element_mode, EVS_MONO ) && ( use_hm == 0 ) )
        {
            prm_hm[0] = 0; /* just to be sure */
            move16();
        }
#endif

        L_spec_core = L_spec;
        move16();
@@ -395,8 +447,18 @@ void tcx_arith_decode_envelope_ivas_fx(

        envelope = (Word16 *) env;
        tcx_arith_scale_envelope( L_spec, L_spec_core, env, target_bits, low_complexity, envelope, &envelope_e );

#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
        IF( EQ_16( st->element_mode, EVS_MONO ) && ( use_hm == 0 ) )
        {
            *arith_bits = tcx_arith_decode_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e, nf_seed );
        }
        ELSE
        {
#endif
            *arith_bits = tcx_arith_decode_ivas_fx( L_spec, envelope, envelope_e, target_bits, prm, q_spectrum, q_spectrum_e );
#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
        }
#endif
        move16();

        /* safety check in case of bit errors */
+27 −0
Original line number Diff line number Diff line
@@ -356,6 +356,24 @@ void decoder_tcx_fx(
                    move16();
                }

#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
                tcx_arith_decode_envelope_fx(
                    st,
                    x, &x_e,
                    L_frame,
                    L_spec,
                    Aind,
                    *prm_target,
                    prm_sqQ,
                    tmp8,
                    prm_hm, /* HM parameter area */
                    hTcxDec->tcx_hm_LtpPitchLag,
                    &arith_bits,
                    &signaling_bits,
                    &nf_seed,
                    shr( st->bwidth, 1 ) /* equivalent to: (st->bwidth > WB)?1:0 */
                );
#else
                tcx_arith_decode_envelope_fx(
                    x, &x_e,
                    L_frame,
@@ -372,6 +390,7 @@ void decoder_tcx_fx(
                    &nf_seed,
                    shr( st->bwidth, 1 ) /* equivalent to: (st->bwidth > WB)?1:0 */
                );
#endif

                hTcxDec->resQBits[frame_cnt] = sub( *prm_target, arith_bits );
                move16();
@@ -4252,11 +4271,19 @@ void decoder_tcx_invQ_fx(

                IF( GT_32( st->bwidth, WB ) )
                {
#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
                    tcx_arith_decode_envelope_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0, 1 );
#else
                    tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 1 );
#endif
                }
                ELSE
                {
#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
                    tcx_arith_decode_envelope_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0, 0 );
#else
                    tcx_arith_decode_envelope_ivas_fx( st, x, x_e, L_frame, L_spec, Aind, *prm_target, prm_sqQ, (Word16) NE_16( st->last_core_from_bs, ACELP_CORE ), prm_hm, /* HM parameter area */ hTcxDec->tcx_hm_LtpPitchLag, &arith_bits, &signaling_bits, 0 );
#endif
                }

                hTcxDec->resQBits[frame_cnt] = sub( *prm_target, arith_bits );