Commit 94e4e1b7 authored by multrus's avatar multrus
Browse files

Merge branch 'basop-2402-simplification-of-arithmetic-codec-subfunctions-mul' into 'main'

Simplification of Artithmetic Coder functions (Decoder)

See merge request !3089
parents f54a74e1 18473b95
Loading
Loading
Loading
Loading
+82 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ static UWord16 ivas_ari_get_symbol(
 *
 *-------------------------------------------------------------*/

#ifndef FIX_2402_SIGNED_VERSION
UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe(
    Decoder_State *st,
    Tastat *s,
@@ -180,6 +181,87 @@ UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe(

    return symbol;
}
#else /* FIX_2402_SIGNED_VERSION */
Word16 ivas_ari_decode_14bits_bit_ext_1_lfe(
    Decoder_State *st,
    Tastat *s,
    const UWord16 *cum_freq,
    Word16 *extra_bits_read )
{
    Word16 symbol;
    Word32 low, high, range, value;
    Word32 cum;

    /* read s->low,high,value sequentially */
    low = s->low;
    high = s->high;
    value = s->value;

    move32();
    move32();
    move32();

    range = L_add( L_sub( high, low ), 1 );
    cum = L_sub( L_lshl( ( L_add( L_sub( value, low ), 1 ) ), stat_bitsnew ), 1 );

    symbol = ivas_ari_get_symbol( cum_freq, range, cum );

    high = L_sub( L_add( low, mul_sbc_14bits( range, cum_freq[symbol] ) ), 1 );
    low = L_add( low, mul_sbc_14bits( range, cum_freq[symbol + 1] ) );

    FOR( ;; )
    {
        IF( GE_32( high, ari_q2new ) )
        {
            IF( GE_32( low, ari_q2new ) )
            {
                value = L_sub( value, ari_q2new );
                low = L_sub( low, ari_q2new );
                high = L_sub( high, ari_q2new );
            }
            ELSE
            {
                test();
                IF( GE_32( low, ari_q1new ) && LT_32( high, ari_q3new ) )
                {
                    value = L_sub( value, ari_q1new );
                    low = L_sub( low, ari_q1new );
                    high = L_sub( high, ari_q1new );
                }
                ELSE
                {
                    BREAK;
                }
            }
        }

        low = L_add( low, low );
        high = L_add( high, UL_addNsD( high, 1 ) );

        IF( GE_16( st->next_bit_pos, st->bits_frame ) )
        {
            value = L_lshl( value, 1 );
            *extra_bits_read = add( *extra_bits_read, 1 );
            move16();
        }
        ELSE
        {
            value = L_or( L_lshl( value, 1 ), get_next_indice_1_fx( st ) );
        }
    }

    s->low = low;
    s->high = high;
    s->value = value;

    move32();
    move32();
    move32();

    return symbol;
}

#endif /* FIX_2402_SIGNED_VERSION */

/*---------------------------------------------------------------
 * Function ivas_ari_done_decoding_14bits_ext_1_lfe()
+9 −0
Original line number Diff line number Diff line
@@ -5298,12 +5298,21 @@ void ivas_ari_start_decoding_14bits_ext_1_lfe(
    Word16 *extra_bits_read 
);

#ifndef FIX_2402_SIGNED_VERSION
UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe(
    Decoder_State *st,
    Tastat *s,
    const UWord16 *cum_freq,
    Word16 *extra_bits_read 
);
#else
Word16 ivas_ari_decode_14bits_bit_ext_1_lfe(
    Decoder_State *st,
    Tastat *s,
    const UWord16 *cum_freq,
    Word16 *extra_bits_read 
);
#endif

void ivas_ari_done_decoding_14bits_ext_1_lfe(
    Decoder_State *st,
+2 −0
Original line number Diff line number Diff line
@@ -90,6 +90,8 @@
#define FIX_BASOP_2650_DEC_PRM_TCX                      /* FhG: Simplify calculation of st->bits_frame_core in dec_prm_tcx(), align function name to float */
#define FIX_2648_IVAS_ISM_DEC_DIGEST_TC                 /* FhG: improvements on ivas_ism_dec_digest_tc_fx() */
#define BE_FIX_BASOP_2543_MISMATCH_REND_OPEN_FX_FL      /* FhG: Aligns implementation of split rendering init loops in IVAS_REND_Open between float and BASOP */
#define FIX_2402_REPL_EVS_ARI_CODEC_DEC                 /* FhG: basop issue 2402: replace EVS arith decoder with IVAS arith decoder, except functions in igf_scf_dec_fx.c */
#define FIX_2402_SIGNED_VERSION                         /* FhG: basop issue 2402: use signed operator instead of unsigned, better match for hardware */

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

+6 −0
Original line number Diff line number Diff line
@@ -9211,10 +9211,12 @@ void getTCXWindowing_ivas_fx(
    Decoder_State *st0         /* i  : bitstream                           */
);

#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
Word16 ari_start_decoding_14bits_prm_ivas_fx(
    const Word16 *ptr,
    Word16 bp,
    Tastat *s );
#endif

void generate_masking_noise_ivas_fx(
    Word32 *timeDomainBuffer,         /* i/o: time-domain signal */
@@ -9390,6 +9392,7 @@ void hq_generic_hf_encoding_fx(
    Word16 *hq_generic_exc_clas,    /* o  : bwe excitation class                     */
    Word16 length );

#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
Word16 ari_decode_14bits_pow_ivas(
    Word16 *ptr,
    Word16 bp,
@@ -9397,13 +9400,16 @@ Word16 ari_decode_14bits_pow_ivas(
    Word16 *res,
    Tastat *s,
    UWord16 base );
#endif

#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
Word16 ari_decode_14bits_sign_ivas(
    Word16 *ptr,
    Word16 bp,
    Word16 bits,
    Word16 *res,
    Tastat *s );
#endif

ivas_error config_acelp1_fx(
    const Word16 enc_dec,                  /* i  : encoder/decoder flag            */
+54 −2
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ void ari_start_decoding_14bits_fx(
    move32();
}

#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
Word16 ari_start_decoding_14bits_prm_fx(
    const Word16 *ptr, /* Q0 */
    Word16 bp,
@@ -58,19 +59,29 @@ Word16 ari_start_decoding_14bits_prm_fx(
    const Word16 *p;

    val = L_deposit_l( 0 );
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
    s->low = val;
    move32();
#endif

    p = ptr + bp; /* Q0 */

    FOR( i = 0; i < cbitsnew; i++ )
    {
        val = L_shl( val, 1 );
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
        if ( *( p + i ) != 0 )
#else
        IF( *( p + i ) )
#endif
        {
            val = L_add( val, 1 );
        }
    }
#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
    s->low = L_deposit_l( 0 );
    move32();
#endif
    s->high = L_add( ari_q4new, 1 );
    move32();
    s->value = val;
@@ -78,6 +89,7 @@ Word16 ari_start_decoding_14bits_prm_fx(

    return add( bp, i );
}
#endif

static Word16 ari_lookup_s17_fx(
    Word32 cum,
@@ -277,6 +289,7 @@ Word16 ari_decode_14bits_bit_ext_fx( Decoder_State *st, Tastat *s )
    return ari_decode_14bits_ext_fx( st, s, cum_freq, ari_lookup_bit_fx );
}

#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base )
{
    Word32 cum, range;
@@ -474,15 +487,26 @@ Word16 ari_decode_14bits_sign_fx( Word16 *ptr, Word16 bp, Word16 bits, Word16 *r
{
    return ari_decode_14bits_notbl_fx( ptr, bp, bits, res, s, 0, ari_lookup_sign_fx );
}
#endif

#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
/*---------------------------------------------------------------
 * ari_start_decoding_14bits_ivas()
 * ari_start_decoding_14bits()
 *
 * Start ArCo decoding
 *-------------------------------------------------------------*/


Word16 ari_start_decoding_14bits_prm_ivas_fx(
#else
/*---------------------------------------------------------------
 * ari_start_decoding_14bits_prm()
 *
 * Start ArCo decoding
 *-------------------------------------------------------------*/

Word16 ari_start_decoding_14bits_prm_fx(
#endif
    const Word16 *ptr,
    Word16 bp,
    Tastat *s )
@@ -509,7 +533,25 @@ Word16 ari_start_decoding_14bits_prm_ivas_fx(
    return add( bp, i );
}


#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
/*------------------------------------------------------------------------
 * Function: ari_decode_14bits_pow_fx
 *
 * Decode a symbol which follows the exponential distribution. That is,
 * symbols are in the following intervals
 *
 * p(x = 0) = 1 - exp(- 0.5 * base * 2)
 * p(x = q>0) = exp(- (q-0.5)*base* 2) - exp(- (q+0.5)*base*2 )
 *
 *-------------------------------------------------------------------------*/
Word16 ari_decode_14bits_pow_fx(
    Word16 *ptr,
    Word16 bp,
    Word16 bits,
    Word16 *res,
    Tastat *s,
    Word16 base )
#else
Word16 ari_decode_14bits_pow_ivas(
    Word16 *ptr,
    Word16 bp,
@@ -517,6 +559,7 @@ Word16 ari_decode_14bits_pow_ivas(
    Word16 *res,
    Tastat *s,
    UWord16 base )
#endif
{
    UWord16 symbol;
    Word32 low, high;
@@ -662,7 +705,16 @@ Word16 ari_decode_14bits_pow_ivas(
    return bp;
}

#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
/*------------------------------------------------------------------------
 * Function: ari_decode_14bits_sign_fx
 *
 * Decode a sign with equal probabilities.
 *-------------------------------------------------------------------------*/
Word16 ari_decode_14bits_sign_fx(
#else
Word16 ari_decode_14bits_sign_ivas(
#endif
    Word16 *ptr,
    Word16 bp,
    Word16 bits,
Loading