Commit 1670c2bf authored by Sandesh Venkatesh's avatar Sandesh Venkatesh
Browse files

Merge branch 'ivas_core_coder_funcs_fxd' into 'main'

Core coder functions integration/conversion to fixed point

See merge request !593
parents d670bf4f 539e1718
Loading
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -74,3 +74,20 @@ Word16 update_mixed_context( Word16 ctx, Word16 a )
    }
    return add( shl( s_and( ctx, 0xf ), 4 ), add( t, 13 ) );
}

#ifdef IVAS_FLOAT_FIXED
Word32 update_mixed_context_ivas_fx( Word32 ctx, Word16 a )
{
    Word32 t32;

    t32 = L_mac0( 1 - 13, s_and( a, ~1 ), add( shr( a, 2 ), 1 ) );

    a = shr( a, 3 );

    IF( t32 > 0 )
    {
        t32 = L_min( a, 2 );
    }
    return L_add( L_shl( L_and( ctx, 0xf ), 4 ), L_add( t32, 13 ) );
}
#endif
+2 −1
Original line number Diff line number Diff line
@@ -185,7 +185,8 @@ Word32 BASOP_Util_Log10( Word32 x, Word16 e )
        }
    }
    Word32 res = BASOP_Util_Log2( x );
    res = L_add( Mpy_32_32( res, 646456993 /* log10(2) in Q31 */ ), Mpy_32_32( L_shl( e, 25 ), 646456993 /* log10(2) in Q31 */ ) ); // Adjusting for the exponent mismatch: multiplying first so as to avoid saturation
    res = L_add( Mpy_32_32( res, 646456993 /* log10(2) in Q31 */ ), Mpy_32_32( L_shl( e, 24 ), 1292913986 /* log10(2) in Q32 */ ) ); // Adjusting for the exponent mismatch: multiplying first so as to avoid saturation
    /* log10(2) is used in Q32 to support exponent till 127 in  Mpy_32_32( L_shl( e, 24 ), 1292913986 )*/
    return res;
}

+10 −0
Original line number Diff line number Diff line
@@ -48,7 +48,9 @@

static int16_t BITS_ALLOC_adjust_acelp_fixed_cdk( const int16_t bits_frame, int16_t *fixed_cdk_index, const int16_t nb_subfr );

#ifndef IVAS_FLOAT_FIXED
static int16_t allocate_unused( const int32_t core_brate, const int16_t coder_type, const int16_t unused_bits, const int16_t nb_prm, const int16_t subfr, const int16_t prm_type, int16_t *prm_bit_mode );
#endif

typedef enum
{
@@ -356,6 +358,7 @@ static int16_t BITS_ALLOC_adjust_acelp_fixed_cdk(
 * Selection of fixed innovation codebook bitbudget table
 *--------------------------------------------------------------------*/

#ifndef IVAS_FLOAT_FIXED
static int16_t fcb_table(
    const int16_t n,
    const int16_t L_subfr )
@@ -370,6 +373,7 @@ static int16_t fcb_table(

    return ( out );
}
#endif

/*-------------------------------------------------------------------*
 * acelp_FCB_allocator()
@@ -377,6 +381,7 @@ static int16_t fcb_table(
 * Routine to allocate fixed innovation codebook bit-budget
 *--------------------------------------------------------------------*/

#ifndef IVAS_FLOAT_FIXED
static ivas_error acelp_FCB_allocator(
    int16_t *nBits,            /* i/o: available bit-budget    */
    int16_t fixed_cdk_index[], /* o  : codebook index          */
@@ -507,6 +512,7 @@ static ivas_error acelp_FCB_allocator(

    return error;
}
#endif


/*-------------------------------------------------------------------*
@@ -517,6 +523,7 @@ static ivas_error acelp_FCB_allocator(
 *   - per channel bitrate minimum is 13250 kbps for ACELP@16kHz
 *--------------------------------------------------------------------*/

#ifndef IVAS_FLOAT_FIXED
ivas_error config_acelp1_IVAS(
    const int16_t enc_dec,              /* i  : encoder/decoder flag            */
    const int32_t total_brate,          /* i  : total bitrate                   */
@@ -1334,6 +1341,7 @@ ivas_error config_acelp1_IVAS(

    return error;
}
#endif

/*-------------------------------------------------------------------*
 * allocate_unused()
@@ -1341,6 +1349,7 @@ ivas_error config_acelp1_IVAS(
 * Allocate unused bits
 *--------------------------------------------------------------------*/

#ifndef IVAS_FLOAT_FIXED
static int16_t allocate_unused(
    const int32_t core_brate,
    const int16_t coder_type,
@@ -1417,6 +1426,7 @@ static int16_t allocate_unused(

    return bit_added + max_bit_per_pos;
}
#endif


/*-------------------------------------------------------------------*
+1076 −0

File changed.

Preview size limit exceeded, changes collapsed.

+81 −1
Original line number Diff line number Diff line
@@ -1727,7 +1727,7 @@ ivas_error push_next_indice(
 * push_next_bits()
 * Push a bit buffer into the buffer at the next position
 *-------------------------------------------------------------------*/

#ifndef IVAS_FLOAT_FIXED
ivas_error push_next_bits(
    BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                     */
    const uint16_t bits[], /* i  : bit buffer to pack, sequence of single bits  */
@@ -1793,7 +1793,87 @@ ivas_error push_next_bits(

    return error;
}
#else
ivas_error push_next_bits(
    BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle                     */
    const UWord16 bits[],  /* i  : bit buffer to pack, sequence of single bits  */
    const Word16 nb_bits   /* i  : number of bits to pack                       */
)
{
    UWord16 code;
    Word16 i, nb_bits_m15;
    Indice *ptr;
    Word16 prev_id;
    ivas_error error;

    error = IVAS_ERR_OK;
    move32();

    ptr = &hBstr->ind_list[hBstr->nb_ind_tot];

    /* get the id of the previous indice -> will be re-used */
    IF( hBstr->nb_ind_tot > 0 )
    {
        prev_id = hBstr->ind_list[hBstr->nb_ind_tot - 1].id;
        move16();
    }
    ELSE
    {
        prev_id = 0;
        move16();
    }
    nb_bits_m15 = sub( nb_bits, 15 );

    FOR( i = 0; i < nb_bits_m15; i += 16 )
    {
        code = (UWord16) L_or( L_shl( bits[i], 15 ), L_or( L_shl( bits[i + 1], 14 ), L_or( L_shl( bits[i + 2], 13 ), L_or( L_shl( bits[i + 3], 12 ), L_or( L_shl( bits[i + 4], 11 ), L_or( L_shl( bits[i + 5], 10 ), L_or( L_shl( bits[i + 6], 9 ), L_or( L_shl( bits[i + 7], 8 ), L_or( L_shl( bits[i + 8], 7 ), L_or( L_shl( bits[i + 9], 6 ), L_or( L_shl( bits[i + 10], 5 ), L_or( L_shl( bits[i + 11], 4 ), L_or( L_shl( bits[i + 12], 3 ), L_or( L_shl( bits[i + 13], 2 ), L_or( L_shl( bits[i + 14], 1 ), bits[i + 15] ) ) ) ) ) ) ) ) ) ) ) ) ) ) );

        /* check the limits of the list of indices */
        IF( NE_32( ( error = check_ind_list_limits( hBstr ) ), IVAS_ERR_OK ) )
        {
            return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices (frame %d) !\n" );
        }
        ptr = &hBstr->ind_list[hBstr->nb_ind_tot];

        ptr->value = code;
        ptr->nb_bits = 16;
        ptr->id = prev_id;
        hBstr->nb_ind_tot = add( hBstr->nb_ind_tot, 1 );
        move16();
        move16();
        move16();
        move16();

        ++ptr;
    }

    FOR( ; i < nb_bits; ++i )
    {
        /* check the limits of the list of indices */
        IF( NE_32( ( error = check_ind_list_limits( hBstr ) ), IVAS_ERR_OK ) )
        {
            return IVAS_ERROR( error, "Error occured in push_next_bits() while re-allocating the list of indices (frame %d) !\n" );
        }
        ptr = &hBstr->ind_list[hBstr->nb_ind_tot];

        ptr->value = bits[i];
        ptr->nb_bits = 1;
        ptr->id = prev_id;
        hBstr->nb_ind_tot = add( hBstr->nb_ind_tot, 1 );
        move16();
        move16();
        move16();
        move16();

        ++ptr;
    }

    hBstr->nb_bits_tot = add( hBstr->nb_bits_tot, nb_bits );
    move16();

    return error;
}
#endif

/*-------------------------------------------------------------------*
 * find_indice()
Loading