Commit bd125776 authored by JÜRGEN Gerstacker's avatar JÜRGEN Gerstacker
Browse files

replaced EVS arith decoder functions with IVAS versions

parent 387619a8
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -127,6 +127,8 @@
#define FIX_BASOP_2545_FIX_LTV_REGRESSION_2529          /* Nokia: BASOP issue 2545: Fix LTV regression caused by issue 2529 fix */
#define FIX_FLOAT_1573_POSITION_UPDATE                  /* Eri: Float issue 1573: For static orientation and listener movement, the PoseUpdated flag is cleared and prevents 5 ms update rate. */
#define FIX_BASOP_2521_DIRAC_STEREO_STEFFI_NRGS         /* FhG: BASOP issue 2521: Fix wrong porting for determination of first subframe length in ivas_sba_dirac_stereo_compute_td_stefi_nrgs() */
//#define FIX_2402_SIMPLIFY_ARI_CODEC                     /* FhG: basop issue 2402: simplify processing in arithmetic decoding, symbol table lookup, all BE */
//#define FIX_2402_INLINE_FCT_ARI_CODEC                   /* FhG: basop issue 2402: simplify processing in arithmetic decoding, inline mul_sbc_14bits, all BE */

/* ##################### End NON-BE switches ########################### */

lib_com/options2.h

0 → 100644
+26 −0
Original line number Diff line number Diff line
//#define FIX_2402_REPL_EVS_ARI_CODEC_DEC                 /* FhG: basop issue 2402: replace EVS arith decoder with IVAS arith decoder */

/*
lib_dec/ari_dec_fx.c
   void ari_start_decoding_14bits_fx( Decoder_State *st, Tastat *s )

lib_dec/ari_dec_fx.c
   Word16 ari_start_decoding_14bits_prm_ivas_fx( const Word16 *ptr, Word16 bp, Tastat *s )
lib_com/ivas_arith_fx.c:
  void ivas_ari_start_decoding_14bits_ext_1_lfe( Decoder_State *st, Tastat *s, Word16 *extra_bits_read )

lib_dec/ari_dec_fx.c
Word16 ari_decode_14bits_s17_ext_fx( Decoder_State *st, Tastat *s, UWord16 const *cum_freq )
ari_decode_14bits_ext_fx
lib_com/ivas_arith_fx.c
UWord16 ivas_ari_decode_14bits_bit_ext_1_lfe( Decoder_State *st, Tastat *s, const UWord16 *cum_freq, Word16 *extra_bits_read )


*/
/*

#2 extra_bits_read
./testv/bitstreams/swb/stv32c_13200_32kHz.COD
Output synthesis file:  ./output/decoded/stv32c_13200_32kHz.OUT
*/
//#define DEBUGGING_2402
+33 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
#include <stdint.h>
#include <assert.h>
#include "options.h"
#include "options2.h"
#include "rom_com.h"
#include "rom_dec.h"
#include "basop_util.h"
@@ -13,6 +14,9 @@
#include "ivas_prot_fx.h"
#include "ivas_rom_com.h"

#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
#include "ivas_prot_fx.h"
#endif

/*-------------------------------------------------------------------*
 * ACcontextMapping_decode2_no_mem_s17_LC()
@@ -133,7 +137,18 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
    }

    /* Start Decoding */
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
    Word16 extra_bits_read = 0;
    ivas_ari_start_decoding_14bits_ext_1_lfe( st, &as,  &extra_bits_read );
#ifdef DEBUGGING_2402
    printf("ivas_ari_start\n");
#endif
#else
    ari_start_decoding_14bits_fx( st, &as );
#ifdef DEBUGGING_2402
    printf("ari_start\n");
#endif
#endif

    overflow_bit_pos = st->next_bit_pos;
    move16();
@@ -182,8 +197,18 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
            assert( tmp >= 0 && tmp < 4096 );
            pki = ari_lookup_s17_LC[tmp];
            move16();
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
            r = ivas_ari_decode_14bits_bit_ext_1_lfe( st, &as, ari_pk_s17_LC_ext[pki], &extra_bits_read );
#ifdef DEBUGGING_2402
            printf("r=%d, nbp=%d, ebr=%d\n", r, st->next_bit_pos, extra_bits_read);
#endif
#else
            r = ari_decode_14bits_s17_ext_fx( st, &as, ari_pk_s17_LC_ext[pki] );

#ifdef DEBUGGING_2402
            printf("r=%d, nbp=%d, ebr=0\n", r, st->next_bit_pos );
#endif
#endif
            IF( LT_16( r, VAL_ESC ) )
            {
                BREAK;
@@ -280,8 +305,13 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
        }
    }

#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
    ivas_ari_done_decoding_14bits_ext_1_lfe( st, extra_bits_read );
#endif
    /* Total number of decoded AC bits */
#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
    get_next_indice_tmp_fx( st, -( cbitsnew - 2 ) );
#endif

    /*detect overflow*/
    IF( NE_16( k, lastnz ) )
@@ -290,6 +320,9 @@ Word16 ACcontextMapping_decode2_no_mem_s17_LC(
        /* Set bitstream position to (start_bit_pos+nbbits-rest_bits) */
        get_next_indice_tmp_fx( st, sub( ( sub( add( start_bit_pos, nbbits ), rest_bits ) ), st->next_bit_pos ) );
    }
#ifdef DEBUGGING_2402
    printf("loop exit, nbp=%d\n", st->next_bit_pos );
#endif

    /*Decode signs*/
    if ( hm_cfg )
+20 −3
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
#include <stdint.h>
#include "assert.h"
#include "options.h"
#include "options2.h"
#include "cnst.h"
#include "rom_com.h"
#include "prot_fx.h"
@@ -24,6 +25,7 @@ Word32 ari_decode_overflow_fx( Tastat *s )
 * \param[i/o] st
 * \param[o] s
 */
#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
void ari_start_decoding_14bits_fx(
    Decoder_State *st,
    Tastat *s )
@@ -39,6 +41,7 @@ void ari_start_decoding_14bits_fx(
    s->value = val;
    move32();
}
#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */

Word16 ari_start_decoding_14bits_prm_fx(
    const Word16 *ptr, /* Q0 */
@@ -50,19 +53,19 @@ Word16 ari_start_decoding_14bits_prm_fx(
    const Word16 *p;

    val = L_deposit_l( 0 );
    s->low = val;
    move32();

    p = ptr + bp; /* Q0 */

    FOR( i = 0; i < cbitsnew; i++ )
    {
        val = L_shl( val, 1 );
        IF( *( p + i ) )
        if( *( p + i ) != 0 )
        {
            val = L_add( val, 1 );
        }
    }
    s->low = L_deposit_l( 0 );
    move32();
    s->high = L_add( ari_q4new, 1 );
    move32();
    s->value = val;
@@ -71,6 +74,7 @@ Word16 ari_start_decoding_14bits_prm_fx(
    return add( bp, i );
}

#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
static Word16 ari_lookup_s17_fx(
    Word32 cum,
    Word32 range,
@@ -128,7 +132,9 @@ static Word16 ari_lookup_s17_fx(
    L_shr( 0, 0 ); /* pointer subtraction */
    return extract_l( p - cum_freq );
}
#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */

#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
static Word16 ari_lookup_s27_fx(
    Word32 cum,
    Word32 range,
@@ -227,7 +233,9 @@ static Word16 ari_lookup_s27_fx(

    return il;
}
#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */

#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
static Word16 ari_lookup_bit_fx(
    Word32 cum,
    Word32 range,
@@ -255,7 +263,9 @@ static Word16 ari_lookup_bit_fx(

    return symbol;
}
#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */

#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
static Word16 ari_decode_14bits_ext_fx(
    Decoder_State *st,
    Tastat *s,
@@ -321,28 +331,34 @@ static Word16 ari_decode_14bits_ext_fx(

    return symbol;
}
#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */


/**
 * \brief Only for 17 symbols with new extended Tables
 */
#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
Word16 ari_decode_14bits_s17_ext_fx( Decoder_State *st, Tastat *s, UWord16 const *cum_freq )
{
    return ari_decode_14bits_ext_fx( st, s, cum_freq, ari_lookup_s17_fx );
}
#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */

/**
 * \brief Only for 27 symbols with new extended Tables
 */
#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
Word16 ari_decode_14bits_s27_ext_fx( Decoder_State *st, Tastat *s, UWord16 const *cum_freq )
{
    return ari_decode_14bits_ext_fx( st, s, cum_freq, ari_lookup_s27_fx );
}
#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */

/**
 * \brief Only for decoding one bit with uniform probability:
 * the equivalent cum_freq table used is {16384, 8192, 0}
 */
#ifndef FIX_2402_REPL_EVS_ARI_CODEC_DEC
Word16 ari_decode_14bits_bit_ext_fx( Decoder_State *st, Tastat *s )
{
    static const UWord16 cum_freq[3] = { 16384, 8192, 0 };
@@ -351,6 +367,7 @@ Word16 ari_decode_14bits_bit_ext_fx( Decoder_State *st, Tastat *s )
    move16();
    return ari_decode_14bits_ext_fx( st, s, cum_freq, ari_lookup_bit_fx );
}
#endif /* FIX_2402_REPL_EVS_ARI_CODEC_DEC */

static Word16 ari_lookup_pow_fx( Tastat *s, Word16 base )
{
+128 −11
Original line number Diff line number Diff line
@@ -7,10 +7,18 @@
#include <stdlib.h>
#include <memory.h>
#include "options.h"
#include "options2.h"
#include "stl.h"
#include "prot_fx.h"
#include "stat_dec.h"
#include "basop_util.h"
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
    #define FIX_2402_REPL_EVS_ARI_CODEC_DEC2
    #include "ivas_prot_fx.h"
#endif
#ifdef DEBUGGING_2402
    #define FIX_2402_REPL_EVS_ARI_CODEC_DEC2
#endif

/**********************************************************************/ /**
initialization of an instance of this module
@@ -66,6 +74,9 @@ static Word16 arith_decode_bits_fx(
    IGFSCFDEC_INSTANCE_HANDLE hPrivateData, /* i/o: instance handle */
    Decoder_State *st,                      /* i/o: pointer to bitstream decoder state */
    Word16 nBits                            /* i  : number of bits to decode */
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
    , Word16 *extra_bits_read
#endif
)
{
    Word16 i;
@@ -79,7 +90,15 @@ static Word16 arith_decode_bits_fx(
    {
        x = lshl( x, 1 );
        /* decode one bit using the new raw AC function */
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
        static const UWord16 cum_freq[3] = { 16384, 8192, 0 };
        bit = ivas_ari_decode_14bits_bit_ext_1_lfe( st, &hPrivateData->acState, cum_freq, extra_bits_read );
#else
        bit = ari_decode_14bits_bit_ext_fx( st, &hPrivateData->acState );
#endif
#ifdef DEBUGGING_2402
    printf("decode %d: nbp=%d ebr=%d\n", __LINE__, st->next_bit_pos, *extra_bits_read );
#endif
        if ( bit != 0 )
        {
            x = s_or( x, 1 );
@@ -94,6 +113,9 @@ static Word16 arith_decode_residual_fx(
    Decoder_State *st,                       /* i/o: pointer to decoder state */
    const UWord16 *cumulativeFrequencyTable, /* i  : cumulative frequency table to be used Q0 */
    Word16 tableOffset                       /* i  : offset used to align the table */
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
    , Word16 *extra_bits_read
#endif
)
{
    Word16 val;
@@ -102,7 +124,14 @@ static Word16 arith_decode_residual_fx(
    move16();

    /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
    val = ivas_ari_decode_14bits_bit_ext_1_lfe( st, &hPrivateData->acState, cumulativeFrequencyTable, extra_bits_read ); // Q0
#else
    val = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, cumulativeFrequencyTable ); // Q0
#endif
#ifdef DEBUGGING_2402
    printf("decode %d: nbp=%d ebr=%d\n", __LINE__, st->next_bit_pos, *extra_bits_read );
#endif

    /* meaning of the values of val: */
    /* esc_{0} IGF_MIN_ENC_SEPARATE ... IGF_MAX_ENC_SEPARATE esc_{IGF_SYMBOLS_IN_TABLE - 1} */
@@ -119,15 +148,34 @@ static Word16 arith_decode_residual_fx(

    /* decode one of the tails of the distribution */
    /* decode extra with 4 bits */
    extra = arith_decode_bits_fx( hPrivateData, st, 4 ); // Q0
    extra = arith_decode_bits_fx( hPrivateData, st, 4
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
        , extra_bits_read
#endif
    ); // Q0
#ifdef DEBUGGING_2402
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
    printf("extra=%d, extra_bits_read=%d\n", extra, *extra_bits_read);
#else
    printf("extra=%d, extra_bits_read=%d\n", extra, 0);
#endif
#endif
    IF( EQ_16( extra, 15 ) )                             /* escape code 15 to indicate extra >= 15 */
    {
        /* decode addtional extra with 6 bits */
        extra = arith_decode_bits_fx( hPrivateData, st, 6 ); // Q0
        extra = arith_decode_bits_fx( hPrivateData, st, 6
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
           , extra_bits_read
#endif
        ); // Q0
        IF( EQ_16( extra, 63 ) )                             /* escape code 63 to indicate extra >= 63 */
        {
            /* decode safety extra with 7 bits */
            extra = arith_decode_bits_fx( hPrivateData, st, 7 ); // Q0
            extra = arith_decode_bits_fx( hPrivateData, st, 7
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
               , extra_bits_read
#endif
        ); // Q0
            extra = add( 63, extra );
        }
        extra = add( 15, extra ); // Q0
@@ -151,9 +199,19 @@ static Word16 arith_decode_residual_fx(

static void arith_decode_flush_fx(
    Decoder_State *st /* i/o: pointer to decoder state */
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
    , Word16 *extra_bits_read
#endif
)
{
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
    ivas_ari_done_decoding_14bits_ext_1_lfe( st, *extra_bits_read );
#else
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
    (void) extra_bits_read; /* remove warning */
#endif
    get_next_indice_tmp_fx( st, -14 ); /* return back the least significant 14 bits to the bitstream */
#endif

    return;
}
@@ -165,6 +223,9 @@ static void decode_sfe_vector_fx(
    Word16 *prev_x,                         /* i  : previous vector */
    Word16 *x,                              /* o  : current vector to decode */
    Word16 length                           /* i  : number of elements to decode */
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
    , Word16 *extra_bits_read
#endif
)
{
    /*
@@ -193,9 +254,17 @@ static void decode_sfe_vector_fx(
                /* (t == 0) && (f == 0) */
                /* decode one of the IGF_SYMBOLS_IN_TABLE == 27 alphabet symbols using the new raw AC function */
                /* NOTE: the float equivalent uses a tmp variable + explicit cast here to avoid undefined behaviour here. This BASOP version does not need it as it already uses signed Word16 return value here. */
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
                res = ivas_ari_decode_14bits_bit_ext_1_lfe( st, &hPrivateData->acState, (const UWord16 *) hPrivateData->cf_se00, extra_bits_read ); // Q0
#else
                res = ari_decode_14bits_s27_ext_fx( st, &hPrivateData->acState, (const UWord16 *) hPrivateData->cf_se00 );
#endif

                pred = arith_decode_bits_fx( hPrivateData, st, 2 ); /* LSBs as 2 bit raw */
                pred = arith_decode_bits_fx( hPrivateData, st, 2
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
                   , extra_bits_read
#endif
 ); /* LSBs as 2 bit raw */
                x[f] = add( shl( res, 2 ), pred );                  // Q0
                move16();
            }
@@ -205,7 +274,11 @@ static void decode_sfe_vector_fx(
                res = arith_decode_residual_fx( hPrivateData,
                                                st,
                                                hPrivateData->cf_se01,
                                                hPrivateData->cf_off_se01 );
                                                hPrivateData->cf_off_se01
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
                                                , extra_bits_read
#endif
 );
                x[f] = add( x[0], res ); // Q0
                move16();                /* f - increment is 0, pred = b */
            }
@@ -221,7 +294,11 @@ static void decode_sfe_vector_fx(
                res = arith_decode_residual_fx( hPrivateData,
                                                st,
                                                hPrivateData->cf_se02 + index1,
                                                hPrivateData->cf_off_se02[index2] );
                                                hPrivateData->cf_off_se02[index2]
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
                                                , extra_bits_read
#endif
 );
                x[f] = add( x[prev_offset], res ); // Q0
                move16();                          /* pred = b */
            }
@@ -235,7 +312,11 @@ static void decode_sfe_vector_fx(
                res = arith_decode_residual_fx( hPrivateData,
                                                st,
                                                hPrivateData->cf_se10,
                                                hPrivateData->cf_off_se10 );
                                                hPrivateData->cf_off_se10
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
                                                , extra_bits_read
#endif
 );
                x[f] = add( prev_x[f], res ); // Q0
                move16();                     /* pred = a */
            }
@@ -259,7 +340,11 @@ static void decode_sfe_vector_fx(
                res = arith_decode_residual_fx( hPrivateData,
                                                st,
                                                hPrivateData->cf_se11 + index1,
                                                hPrivateData->cf_off_se11[index2] );
                                                hPrivateData->cf_off_se11[index2]
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
                                                , extra_bits_read
#endif
 );
                x[f] = add( pred, res ); // Q0
                move16();
            }
@@ -317,7 +402,25 @@ void IGFSCFDecoderDecode(
    /* insert data */
    hPublicData->bitsRead = st->next_bit_pos;
    move16();
#ifdef DEBUGGING_2402
    static Word16 cnt123 = 0;
#endif
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
    Word16 extra_bits_read = 0;
#endif
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC
    ivas_ari_start_decoding_14bits_ext_1_lfe( st, &hPublicData->acState,  &extra_bits_read );
#ifdef DEBUGGING_2402
    printf("ivas_ari_start\n");
    printf("start %d\n", ++cnt123);
#endif
#else
    ari_start_decoding_14bits_fx( st, &hPublicData->acState ); /* start AC decoding */
#ifdef DEBUGGING_2402
    printf("ari_start\n");
    printf("start %d\n", ++cnt123);
#endif
#endif

    /* check if coder needs a reset and do it if necessary */
    IF( indepFlag != 0 )
@@ -326,9 +429,23 @@ void IGFSCFDecoderDecode(
        IGFSCFDecoderReset( hPublicData );
    }

    decode_sfe_vector_fx( hPublicData, st, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx] );

    arith_decode_flush_fx( st ); /* finish AC decoding */
    decode_sfe_vector_fx( hPublicData, st, hPublicData->t, hPublicData->prev, sfe, hPublicData->scfCountLongBlock[igfGridIdx]
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
        , &extra_bits_read
#endif
 );

#ifdef DEBUGGING_2402
    printf("finish nbp=%d ebr=%d\n", st->next_bit_pos, extra_bits_read );
#endif
    arith_decode_flush_fx( st
#ifdef FIX_2402_REPL_EVS_ARI_CODEC_DEC2
    , &extra_bits_read
#endif
 ); /* finish AC decoding */
#ifdef DEBUGGING_2402
    printf("finish2 nbp=%d ebr=%d\n", st->next_bit_pos, extra_bits_read );
#endif

    /* advance history */
    Copy( sfe, hPublicData->prev, hPublicData->scfCountLongBlock[igfGridIdx] );