Commit 14f78288 authored by multrus's avatar multrus
Browse files

Merge branch 'basop-2598-harmonize-tcx_arith_decode_envelope' into 'main'

Resolve "Harmonize tcx_arith_decode_envelope and tcx_arith_encode_envelope"

See merge request !3045
parents c305ac69 e80fbaf2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -101,6 +101,8 @@
#define HARMONIZE_2607_GetFilterParameters              /* FhG: Harmonize GetFilterParameters with its ivas derivate */
#define HAMRONIZE_2606_ENC_PRM                          /* FhG: Harmonize enc_prm_fx(), to match floating-point code */
#define HARMONIZE_2604_decoder_tcx_post                 /* FhG: Harmonize decoder_tcx_post with its ivas derivate */
#define HARMONIZE_2598_tcx_arith_decode_envelope        /* FhG: harmonize tcx_arith_decode_envelope between EVS and IVAS versions */
#define HARMONIZE_2598_tcx_arith_encode_envelope        /* FhG: harmonize tcx_arith_encode_envelope between EVS and IVAS versions */

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

+24 −2
Original line number Diff line number Diff line
@@ -8009,6 +8009,7 @@ void decoder_tcx_post_fx(
    Word16 bfi );
#endif

#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 */
@@ -8026,6 +8027,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 */
@@ -10005,9 +10007,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      */
@@ -10015,11 +10036,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(
+49 −7
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,26 @@ 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 */ /*IVAS: 0*/
    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 +330,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) */
@@ -315,7 +338,6 @@ void tcx_arith_decode_envelope_ivas_fx(
    Word16 envelope_e;
    Word16 L_spec_core;
    TCX_CONFIG_HANDLE hTcxCfg;
    TCX_DEC_HANDLE hTcxDec;
    Word16 gamma_w, gamma_uw;
    Word16 hm_bits;

@@ -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 ) )
@@ -346,17 +368,27 @@ void tcx_arith_decode_envelope_ivas_fx(
    }

    hTcxCfg = st->hTcxCfg;
    hTcxDec = st->hTcxDec;
    *signaling_bits = 0;
    move16();

    assert( hTcxDec->enableTcxLpc );
    assert( st->hTcxDec->enableTcxLpc );
    gamma_w = MAX16B;
    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_ivas_fx( A_ind, L_frame, L_spec, hTcxCfg->preemph_fac, gamma_w, gamma_uw, env );
#ifdef HARMONIZE_2598_tcx_arith_decode_envelope
    }
#endif


    IF( use_hm != 0 )
    {
@@ -395,8 +427,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 ) )
    {
        *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();
@@ -4389,11 +4408,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 );
+49 −2
Original line number Diff line number Diff line
@@ -658,7 +658,7 @@ static Word16 tcx_arith_encode(
 *
 *
 *-------------------------------------------------------------------*/

#ifndef HARMONIZE_2598_tcx_arith_encode_envelope
void tcx_arith_encode_envelope_fx(
    Word32 spectrum[],          /* i/o: MDCT coefficients             Q31-e */
    Word16 *spectrum_e,         /* i/o: MDCT exponent                 Q0 */
@@ -800,8 +800,28 @@ void tcx_arith_encode_envelope_fx(

    return;
}
#endif


#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
void tcx_arith_encode_envelope_fx(
    Word32 spectrum[],          /* i/o: MDCT coefficients             Q31-e */
    Word16 *spectrum_e,         /* i/o: MDCT exponent                 Q0 */
    Word16 signs[],             /* o  : signs (spectrum[.]<0)         Q0 */
    const Word16 L_frame,       /* i  : frame or MDCT length          Q0 */
    const Word16 L_spec,        /* i  : frame or MDCT length          Q0 */
    Encoder_State *st,          /* i/o: coder state                   */
    const Word16 A_ind[],       /* i  : quantised LPC coefficients    Q12 */
    Word16 target_bits,         /* i  : number of available bits      Q0 */
    Word16 prm[],               /* o  : bitstream parameters          Q0 */
    const Word8 use_hm,         /* i  : use HM in current frame?      */
    Word16 prm_hm[],            /* o  : HM parameter area             Q0 */
    const Word16 tcxltp_pitch,  /* i  : TCX LTP pitch in FD, -1 if n/a  Q0*/
    Word16 *arith_bits,         /* o  : bits used for ari. coding     Q0 */
    Word16 *signaling_bits,     /* o  : bits used for signaling       Q0 */
    Word16 *nf_seed,            /* o  : noise filling seed; might be NULL Q0 */
    const Word16 low_complexity /* i  : low-complexity flag           Q0 */
)
#else
void tcx_arith_encode_envelope_ivas_fx(
    Word32 spectrum[],          /* i/o: MDCT coefficients             Q31-e */
    Word16 *spectrum_e,         /* i/o: MDCT exponent                 Q0 */
@@ -819,6 +839,7 @@ void tcx_arith_encode_envelope_ivas_fx(
    Word16 *signaling_bits,     /* o  : bits used for signaling       Q0 */
    const Word16 low_complexity /* i  : low-complexity flag           Q0 */
)
#endif
{
    Word32 env[N_MAX_ARI]; /* unscaled envelope (Q16) */
    Word16 *envelope;      /* scaled envelope (Q15-e) */
@@ -834,6 +855,9 @@ void tcx_arith_encode_envelope_ivas_fx(
    Word16 gamma_w, gamma_uw;
    Word16 hm_bits;
    Word32 L_tmp;
#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
    Word64 W_tmp2;
#endif
    Word16 tmp;
    TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc;

@@ -919,12 +943,26 @@ void tcx_arith_encode_envelope_ivas_fx(
    move16();

    /* Multiply back the signs */
#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
    W_tmp2 = 0;
    move32();
#endif
    FOR( k = 0; k <= kMax; k++ )
    {
#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
        if ( nf_seed != NULL )
        {
            W_tmp2 = W_mac_16_16( W_tmp2, q_spectrum[k], k );
        }
#endif
        if ( signs[k] != 0 )
        {
            L_tmp = L_mult( q_spectrum[k], -( 1 << ( 30 - SPEC_EXP_DEC ) ) );
        }
        if ( signs[k] == 0 )
        {
            L_tmp = L_mult( q_spectrum[k], 1 << ( 30 - SPEC_EXP_DEC ) );
        }
        spectrum[k] = L_tmp;
        move32();
    }
@@ -933,5 +971,14 @@ void tcx_arith_encode_envelope_ivas_fx(
    move16();
    set32_fx( spectrum + k, 0, sub( s_max( L_frame, L_spec ), k ) );

#ifdef HARMONIZE_2598_tcx_arith_encode_envelope
    if ( nf_seed != NULL )
    {
        /* noise filling seed */
        *nf_seed = extract_l( W_extract_l( W_tmp2 ) );
        move16();
    }
#endif

    return;
}
Loading