From 22469e8554131546a060bfb3487fa91819cc9e26 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 9 Aug 2025 17:56:33 +0200 Subject: [PATCH 1/2] port MR --- lib_com/bitstream.c | 1409 ++++++++++++++++++++++++++++--- lib_com/bitstream_fx.c | 1316 ----------------------------- lib_com/ivas_arith_fx.c | 2 +- lib_com/prot_fx.h | 57 +- lib_dec/FEC_clas_estim_fx.c | 2 +- lib_dec/amr_wb_dec_fx.c | 2 +- lib_dec/dec_acelp_tcx_main_fx.c | 10 +- lib_dec/dec_amr_wb_fx.c | 2 +- lib_dec/hq_classifier_dec_fx.c | 4 +- lib_dec/hq_core_dec_fx.c | 2 +- lib_dec/hq_hr_dec_fx.c | 2 +- lib_dec/range_dec_fx.c | 6 +- lib_enc/igf_enc.c | 5 - lib_enc/igf_enc_fx.c | 4 +- lib_util/mime_io.c | 4 +- 15 files changed, 1354 insertions(+), 1473 deletions(-) delete mode 100644 lib_com/bitstream_fx.c diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 5b11e8d26..77ce24079 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -55,8 +55,158 @@ #endif #endif +#ifdef DEBUGGING + +#define FEC_SEED 12558 + +/*-------------------------------------------------------------------* + * Global variables + *--------------------------------------------------------------------*/ + +FILE *FEC_pattern = NULL; /* FEC pattern file (for simulation of FEC) */ +#endif + #define STEP_MAX_NUM_INDICES 100 /* increase the maximum number of allowed indices in the list by this amount */ +/*-------------------------------------------------------------------* + * BRATE2IDX_fx() + * + * Convert Bitrate to Index Value + *-------------------------------------------------------------------*/ + +Word16 BRATE2IDX_fx( + const Word32 brate ) +{ + + Word32 L_temp; + Word32 L_idx; +#define START 9 + extern const Word16 bit_rates_div50[]; + + /* This is a Fast Bit Rate Value to Index Value Binary Search */ + L_temp = L_msu0( brate, bit_rates_div50[START], 50 ); + L_temp = L_min( 6, L_max( -6, L_temp ) ); + L_idx = L_add( L_temp, START ); + L_temp = L_msu0( brate, bit_rates_div50[L_idx], 50 ); + L_temp = L_min( 3, L_max( -3, L_temp ) ); + L_idx = L_add( L_temp, L_idx ); + L_temp = L_msu0( brate, bit_rates_div50[L_idx], 50 ); + L_temp = L_min( 1, L_max( -2, L_temp ) ); + L_idx = L_add( L_temp, L_idx ); + L_temp = L_msu0( brate, bit_rates_div50[L_idx], 50 ); + if ( L_temp != 0 ) + L_idx = L_add( L_idx, 1 ); + + return (Word16) L_idx; +} + + +/*-------------------------------------------------------------------* + * BRATE2IDX16k_fx() + * + * Convert Bitrate to Index Value + *-------------------------------------------------------------------*/ + +Word16 BRATE2IDX16k_fx( + Word32 brate ) +{ + Word32 L_temp, L_idx; +#define START_16K 5 + extern const Word16 bit_rates_16k_div50[]; + + if ( EQ_32( brate, ACELP_16k40 ) ) + { + brate = ACELP_14k80; + move16(); + } + + /* This is a Fast Bit Rate Value to Index Value Binary Search */ + L_temp = L_msu0( brate, bit_rates_16k_div50[START_16K], 50 ); + L_temp = L_min( 3, L_max( -3, L_temp ) ); + L_idx = L_add( L_temp, START_16K ); + L_temp = L_msu0( brate, bit_rates_16k_div50[L_idx], 50 ); + L_temp = L_min( 2, L_max( -2, L_temp ) ); + L_idx = L_add( L_temp, L_idx ); + L_temp = L_msu0( brate, bit_rates_16k_div50[L_idx], 50 ); + L_temp = L_min( 1, L_max( -1, L_temp ) ); + L_idx = L_add( L_temp, L_idx ); + + return (Word16) L_idx; +} + + +/*-------------------------------------------------------------------* + * BIT_ALLOC_IDX_fx() + *-------------------------------------------------------------------*/ + +Word32 BIT_ALLOC_IDX_fx( + const Word32 brate, + Word16 ctype, + const Word16 sfrm, + const Word16 tc ) +{ + Word32 L_temp; + Word16 temp; + + if ( ctype == INACTIVE ) /* no sub(ctype, INACTIVE) because it is '0' */ + ctype = GENERIC; + move16(); + L_temp = L_mac0( -1l * 256, 1 * 256, ctype ); + + temp = BRATE2IDX_fx( brate ); + L_temp = L_mac0( L_temp, 4 * 256, temp ); + IF( tc >= 0 ) + L_temp = L_mac0( L_temp, ( 10 - 4 ) * 256, temp ); + /* So either 'temp' x 4 when 'tc < 0', 'temp' x 10 otherwise */ + + L_temp = L_mac0( L_temp, 1 * 256, s_max( 0, tc ) ); + + L_temp = L_mac0( L_temp, s_max( 0, sfrm ), 1 ); + if ( sfrm < 0 ) + L_temp = L_shr( L_temp, 2 ); + L_temp = L_shr( L_temp, 6 ); + + return L_temp; +} + + +/*-------------------------------------------------------------------* + * BIT_ALLOC_IDX_16KHZ_fx() + *-------------------------------------------------------------------*/ + +Word32 BIT_ALLOC_IDX_16KHZ_fx( + const Word32 brate, + const Word16 ctype, + const Word16 sfrm, + const Word16 tc ) +{ + Word32 L_temp; + Word16 temp; + /* 'ctype' = + TRANSITION => 2 + GENERIC => 1 + ALL Other => 0 + */ + L_temp = L_and( shr( 0x0240l, shl( ctype, 1 ) ), 3 ); + + temp = BRATE2IDX16k_fx( brate ); + L_temp = L_mac0( L_temp, 3, temp ); + IF( tc >= 0 ) + L_temp = L_mac0( L_temp, ( 7 - 3 ), temp ); + /* So either 'temp' x 3 when 'tc < 0', 'temp' x 7 otherwise */ + + L_temp = L_mac0( L_temp, 1, s_max( 0, tc ) ); + + IF( sfrm >= 0 ) + { + /* Mult by 5 */ + L_temp = L_add( L_temp, L_shl( L_temp, 2 ) ); + L_temp = L_mac0( L_temp, shr( sfrm, 6 ), 1 ); + } + + return L_temp; +} + /*-------------------------------------------------------------------* * rate2AMRWB_IOmode() @@ -68,7 +218,7 @@ static Word16 rate2AMRWB_IOmode( Word32 brate /* i : bitrate */ ) { - switch ( brate ) + SWITCH( brate ) { /* EVS AMR-WB IO modes */ case SID_1k75: @@ -98,12 +248,14 @@ static Word16 rate2AMRWB_IOmode( return -1; } + /*-------------------------------------------------------------------* * rate2EVSmode() * * lookup EVS mode *-------------------------------------------------------------------*/ -Word16 rate2EVSmode_float( + +Word16 rate2EVSmode( const Word32 brate, /* i : bitrate */ Word16 *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ ) @@ -111,9 +263,10 @@ Word16 rate2EVSmode_float( if ( is_amr_wb != NULL ) { *is_amr_wb = 0; + move16(); } - switch ( brate ) + SWITCH( brate ) { /* EVS Primary modes */ case FRAME_NO_DATA: @@ -151,11 +304,13 @@ Word16 rate2EVSmode_float( if ( is_amr_wb != NULL ) { *is_amr_wb = 1; + move16(); } return rate2AMRWB_IOmode( brate ); } + /*-------------------------------------------------------------------* * ind_list_realloc() * @@ -789,6 +944,8 @@ Word16 get_ivas_max_num_indices_metadata_fx( return 50; } + + /*-------------------------------------------------------------------* * move_indices() * @@ -803,32 +960,40 @@ void move_indices( { Word16 i; - if ( new_ind_list < old_ind_list ) + IF( new_ind_list < old_ind_list ) { - for ( i = 0; i < nb_indices; i++ ) + FOR( i = 0; i < nb_indices; i++ ) { new_ind_list[i].id = old_ind_list[i].id; new_ind_list[i].value = old_ind_list[i].value; new_ind_list[i].nb_bits = old_ind_list[i].nb_bits; + move16(); + move16(); + move16(); #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS ) strncpy( new_ind_list[i].function_name, old_ind_list[i].function_name, 100 ); #endif old_ind_list[i].nb_bits = -1; + move16(); } } - else if ( new_ind_list > old_ind_list ) + ELSE IF( new_ind_list > old_ind_list ) { - for ( i = nb_indices - 1; i >= 0; i-- ) + FOR( i = nb_indices - 1; i >= 0; i-- ) { new_ind_list[i].id = old_ind_list[i].id; new_ind_list[i].value = old_ind_list[i].value; new_ind_list[i].nb_bits = old_ind_list[i].nb_bits; + move16(); + move16(); + move16(); #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS ) strncpy( new_ind_list[i].function_name, old_ind_list[i].function_name, 100 ); #endif old_ind_list[i].nb_bits = -1; + move16(); #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS ) sprintf( old_ind_list[i].function_name, "RESET in move_indices" ); #endif @@ -2919,10 +3084,12 @@ ivas_error push_next_indice( return error; } + /*-------------------------------------------------------------------* * push_next_bits() * Push a bit buffer into the buffer at the next position *-------------------------------------------------------------------*/ + #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS ) ivas_error push_next_bits_( const char *caller, @@ -3022,6 +3189,7 @@ ivas_error push_next_bits( return error; } + /*-------------------------------------------------------------------* * find_indice() * @@ -3067,20 +3235,24 @@ UWord16 delete_indice( Word16 i, j; j = 0; - for ( i = 0; i < hBstr->nb_ind_tot; i++ ) + FOR( i = 0; i < hBstr->nb_ind_tot; i++ ) { - if ( hBstr->ind_list[i].id == id ) + IF( EQ_16( hBstr->ind_list[i].id, id ) ) { hBstr->nb_bits_tot -= hBstr->ind_list[i].nb_bits; + move16(); continue; } - if ( j < i ) + IF( LT_16( j, i ) ) { /* shift the indice left */ hBstr->ind_list[j].id = hBstr->ind_list[i].id; hBstr->ind_list[j].value = hBstr->ind_list[i].value; hBstr->ind_list[j].nb_bits = hBstr->ind_list[i].nb_bits; + move16(); + move16(); + move16(); #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS ) strncpy( hBstr->ind_list[j].function_name, hBstr->ind_list[i].function_name, 100 ); #endif @@ -3091,10 +3263,11 @@ UWord16 delete_indice( hBstr->nb_ind_tot = j; - for ( ; j < i; j++ ) + FOR( ; j < i; j++ ) { /* reset the shifted indices at the end of the list */ hBstr->ind_list[j].nb_bits = -1; + move16(); #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS ) sprintf( hBstr->ind_list[j].function_name, "RESET in delete_indice" ); #endif @@ -3111,55 +3284,93 @@ UWord16 delete_indice( *-------------------------------------------------------------------*/ /*! r: value of the indice */ -UWord16 get_next_indice( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ +UWord16 get_next_indice_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ) { UWord16 value; Word16 i; - Word32 nbits_total; + Word16 nbits_total; assert( nb_bits <= 16 ); + value = 0; + move16(); + + nbits_total = extract_l( Mpy_32_32( st_fx->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - nbits_total = st->total_brate / FRAMES_PER_SEC; /* detect corrupted bitstream */ - if ( st->next_bit_pos + nb_bits > nbits_total ) + IF( GT_16( add( st_fx->next_bit_pos, nb_bits ), nbits_total ) ) { - st->BER_detect = 1; + st_fx->BER_detect = 1; + move16(); return ( 0 ); } - value = 0; - for ( i = 0; i < nb_bits; i++ ) + FOR( i = 0; i < nb_bits; i++ ) { - value <<= 1; - value += st->bit_stream[st->next_bit_pos + i]; + value = (UWord16) L_shl( value, 1 ); + value = (UWord16) L_add( value, st_fx->bit_stream[add( st_fx->next_bit_pos, i )] ); } /* update the position in the bitstream */ - st->next_bit_pos += nb_bits; + st_fx->next_bit_pos = add( st_fx->next_bit_pos, nb_bits ); + move16(); return value; } + +/*-------------------------------------------------------------------* + * get_next_indice_1() + * + * Get the next 1-bit indice from the buffer + *-------------------------------------------------------------------*/ + +/*! r: value of the indice */ +UWord16 get_next_indice_1_fx( + Decoder_State *st_fx /* i/o: decoder state structure */ +) +{ + Word16 nbits_total; + nbits_total = extract_l( Mpy_32_32( st_fx->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + + /* detect corrupted bitstream */ + test(); + test(); + test(); + IF( ( GT_16( add( st_fx->next_bit_pos, 1 ), nbits_total ) && EQ_16( st_fx->codec_mode, MODE1 ) ) || + ( GT_16( add( st_fx->next_bit_pos, 1 ), add( nbits_total, 2 * 8 ) ) && EQ_16( st_fx->codec_mode, MODE2 ) ) /* add two zero bytes for arithmetic coder flush */ + ) + { + st_fx->BER_detect = 1; + move16(); + return ( 0 ); + } + + return st_fx->bit_stream[st_fx->next_bit_pos++]; +} + + /*-------------------------------------------------------------------* * get_next_indice_tmp() * * update the total number of bits and the position in the bitstream *-------------------------------------------------------------------*/ -void get_next_indice_tmp( - Decoder_State *st, /* o : decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ +void get_next_indice_tmp_fx( + Decoder_State *st_fx, /* o : decoder state structure */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ) { /* update the position in the bitstream */ - st->next_bit_pos += nb_bits; + st_fx->next_bit_pos = add( st_fx->next_bit_pos, nb_bits ); + move16(); return; } + /*-------------------------------------------------------------------* * get_indice() * @@ -3167,10 +3378,10 @@ void get_next_indice_tmp( *-------------------------------------------------------------------*/ /*! r: value of the indice */ -UWord16 get_indice( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 pos, /* i : absolute position in the bitstream (update after the read) */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ +UWord16 get_indice_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 pos, /* i : absolute position in the bitstream (update after the read) */ + Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ) { UWord16 value; @@ -3179,24 +3390,28 @@ UWord16 get_indice( assert( nb_bits <= 16 ); - nbits_total = st->total_brate / FRAMES_PER_SEC; + nbits_total = extract_l( Mpy_32_32( st_fx->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /* detect corrupted bitstream */ - if ( pos + nb_bits > nbits_total ) + IF( GT_32( L_deposit_l( add( pos, nb_bits ) ), nbits_total ) ) { - st->BER_detect = 1; + st_fx->BER_detect = 1; + move16(); return ( 0 ); } value = 0; - for ( i = 0; i < nb_bits; i++ ) + move16(); + FOR( i = 0; i < nb_bits; i++ ) { - value <<= 1; - value += st->bit_stream[pos + i]; + value = lshl( value, 1 ); + value = add( value, st_fx->bit_stream[pos + i] ); } + return value; } + /*-------------------------------------------------------------------* * get_indice_st() * @@ -3234,13 +3449,69 @@ UWord16 get_indice_st( return value; } -#define WMC_TOOL_SKIP + + +/*-------------------------------------------------------------------* + * get_indice_1_fx( ) + * + * Get a 1-bit indice at specific position in the buffer + *-------------------------------------------------------------------*/ + +/*! r: value of the indice */ +UWord16 get_indice_1_fx( + Decoder_State *st_fx, /* i/o: decoder state structure */ + Word16 pos /* i : absolute position in the bitstream (update after the read) */ +) +{ + Word16 nbits_total; + + nbits_total = extract_l( Mpy_32_32( st_fx->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); + + /* detect corrupted bitstream */ + IF( GT_16( add( pos, 1 ), nbits_total ) ) + { + st_fx->BER_detect = 1; + move16(); + return ( 0 ); + } + + return st_fx->bit_stream[pos]; +} + + +/*-------------------------------------------------------------------* + * reset_indices_enc_fx() + * + * Reset the buffer of indices + *-------------------------------------------------------------------*/ + +void reset_indices_enc_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ + const Word16 max_num_indices /* i : max number of indices */ +) +{ + Word16 i; + + hBstr->nb_ind_tot = 0; + move16(); + hBstr->nb_bits_tot = 0; + move16(); + FOR( i = 0; i < max_num_indices; i++ ) + { + hBstr->ind_list[i].nb_bits = -1; + move16(); + } + + return; +} + /*-------------------------------------------------------------------* * reset_indices_dec() * * Reset the buffer of decoder indices *-------------------------------------------------------------------*/ + void reset_indices_dec( Decoder_State *st ) { @@ -3249,11 +3520,14 @@ void reset_indices_dec( return; } + + /*-------------------------------------------------------------------* * write_indices_to_stream() * * writing forward or backward to a serial stream *-------------------------------------------------------------------*/ + static Word16 write_indices_to_stream_fx( Indice *ind_list, UWord16 **pt_stream, @@ -3296,14 +3570,17 @@ static Word16 write_indices_to_stream_fx( } } } + return 0; } + /*-------------------------------------------------------------------* * write_indices_element() * * Bitstream writing function of one element (one SCE or one CPE) *-------------------------------------------------------------------*/ + static ivas_error write_indices_element_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ UWord16 **pt_stream, /* i : pointer to bitstream buffer */ @@ -3515,12 +3792,14 @@ static ivas_error write_indices_element_fx( return error; } + /*-------------------------------------------------------------------* * write_indices_ivas() * * Write the buffer of indices to a serial bitstream buffer, * each bit represented as a uint16_t of value 0 or 1 *-------------------------------------------------------------------*/ + ivas_error write_indices_ivas_fx( Encoder_Struct *st_ivas, /* i/o: encoder state structure */ UWord16 *bit_stream, /* i/o: output bitstream */ @@ -3541,7 +3820,6 @@ ivas_error write_indices_ivas_fx( move16(); } - /*-----------------------------------------------------------------* * Encode Payload *-----------------------------------------------------------------*/ @@ -3562,6 +3840,7 @@ ivas_error write_indices_ivas_fx( return error; } + /*-------------------------------------------------------------------* * decoder_selectCodec() * @@ -3575,69 +3854,85 @@ static void decoder_selectCodec( ) { /* set the AMR-WB IO flag */ - if ( rate2AMRWB_IOmode( total_brate ) != -1 ) + IF( rate2AMRWB_IOmode( total_brate ) != -1 ) { st->Opt_AMR_WB = 1; + move16(); } - else if ( total_brate != FRAME_NO_DATA ) + ELSE IF( total_brate != FRAME_NO_DATA ) { st->Opt_AMR_WB = 0; + move16(); } - if ( st->Opt_AMR_WB ) + IF( st->Opt_AMR_WB ) { st->codec_mode = MODE1; + move16(); } else { st->codec_mode = get_codec_mode( total_brate ); - if ( st->codec_mode == -1 ) + IF( st->codec_mode == -1 ) { - switch ( total_brate ) + SWITCH( total_brate ) { case 0: st->codec_mode = st->last_codec_mode; - break; + move16(); + BREAK; case 2400: st->codec_mode = st->last_codec_mode; - break; + move16(); + BREAK; case 2800: st->codec_mode = MODE1; + move16(); break; default: /* validate that total_brate (derived from RTP packet or a file header) is one of the defined bitrates */ st->codec_mode = st->last_codec_mode; + move16(); st->bfi = 1; + move16(); break; } } } - if ( st->ini_frame == 0 ) + IF( st->ini_frame == 0 ) { if ( st->codec_mode == -1 ) { st->codec_mode = MODE1; + move16(); } st->last_codec_mode = st->codec_mode; + move16(); } /* set SID/CNG type */ - if ( total_brate == SID_2k40 ) + IF( total_brate == SID_2k40 ) { - if ( bit0 == 0 ) + IF( bit0 == 0 ) { st->cng_type = LP_CNG; + move16(); /* force MODE1 when selecting LP_CNG */ st->codec_mode = MODE1; + move16(); } - else if ( bit0 == 1 ) + ELSE IF( bit0 == 1 ) { st->cng_type = FD_CNG; + move16(); + + test(); if ( st->last_codec_mode == MODE2 && st->last_total_brate == ACELP_13k20 ) { st->codec_mode = MODE1; + move16(); } } } @@ -3647,77 +3942,424 @@ static void decoder_selectCodec( /*-------------------------------------------------------------------* - * reset_elements() + * dec_prm_core() + * * - * Simulate packet losses by reading FEC pattern from external file *-------------------------------------------------------------------*/ -Decoder_State **reset_elements( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ -) +static void dec_prm_core( Decoder_State *st ) { - Word16 k, n; - Decoder_State **sts = NULL; /* to avoid compilation warning */ - - FOR( k = 0; k < st_ivas->nSCE; k++ ) - { - sts = st_ivas->hSCE[k]->hCoreCoder; + Word16 n, frame_size_index, num_bits; + UWord16 lsb; + Word32 L_tmp; - sts[0]->bfi = 0; - sts[0]->BER_detect = 0; - sts[0]->mdct_sw_enable = 0; - sts[0]->mdct_sw = 0; + frame_size_index = -1; + move16(); + st->core = -1; + move16(); + IF( st->total_brate == FRAME_NO_DATA ) + { + st->m_frame_type = ZERO_FRAME; move16(); + } + ELSE IF( EQ_32( st->total_brate, SID_2k40 ) ) + { + st->m_frame_type = SID_FRAME; move16(); + } + ELSE + { + st->m_frame_type = ACTIVE_FRAME; move16(); - move16(); + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + assert( num_bits == st->total_brate / 50 ); + FOR( n = 0; n < FRAME_SIZE_NB; ++n ) + { + IF( EQ_16( FrameSizeConfig[n].frame_bits, num_bits ) ) + { + frame_size_index = n; + move16(); + BREAK; + } + } - reset_indices_dec( sts[0] ); - } + /* Get bandwidth mode */ + st->bwidth = get_next_indice_fx( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); + move16(); - FOR( k = 0; k < st_ivas->nCPE; k++ ) - { - sts = st_ivas->hCPE[k]->hCoreCoder; + st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); + move16(); - FOR( n = 0; n < CPE_CHANNELS; n++ ) + IF( GT_16( st->bwidth, FB ) ) { - sts[n]->bfi = 0; - sts[n]->BER_detect = 0; - sts[n]->mdct_sw_enable = 0; - sts[n]->mdct_sw = 0; - + st->bwidth = FB; move16(); + st->BER_detect = 1; move16(); + } + + test(); + IF( GT_16( st->bwidth, SWB ) && LT_32( st->total_brate, ACELP_16k40 ) ) + { + st->bwidth = SWB; move16(); + st->BER_detect = 1; move16(); + } - reset_indices_dec( sts[n] ); + /* Skip reserved bit */ + get_next_indice_tmp_fx( st, FrameSizeConfig[frame_size_index].reserved_bits ); + + IF( get_next_indice_1_fx( st ) != 0 ) /* TCX */ + { + st->core = TCX_20_CORE; + move16(); + if ( get_next_indice_1_fx( st ) != 0 ) + { + st->core = HQ_CORE; + move16(); + } + } + ELSE /* ACELP */ + { + st->core = ACELP_CORE; + move16(); } } - return sts; /* return last decoder state */ + return; } -/*-------------------------------------------------------------------* - * ivas_set_bitstream_pointers() + +/*-----------------------------------------------------------------* + * decision_matrix_core_dec() * - * Set bitstream pointers for every SCE/CPE Core-Decoder - *-------------------------------------------------------------------*/ + * Read core mode signalling bits from the bitstream + * Set st->core, and st->bwidth if signalled together with the core. + *-----------------------------------------------------------------*/ -void ivas_set_bitstream_pointers( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +static void decision_matrix_core_dec( + Decoder_State *st /* i/o: decoder state structure */ ) { - Word16 k, num_bits; - Decoder_State **sts; + Word16 start_idx; + Word32 ind; + Word16 nBits; - num_bits = 0; + assert( st->bfi != 1 ); - /* set bitstream pointers for SCEs */ - for ( k = 0; k < st_ivas->nSCE; k++ ) + st->core = -1; + move16(); + st->bwidth = -1; + move16(); + + test(); + IF( ( st->total_brate == FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) { - sts = st_ivas->hSCE[k]->hCoreCoder; + st->core = ACELP_CORE; + move16(); + } + /* SC-VBR */ + ELSE IF( EQ_32( st->total_brate, PPP_NELP_2k80 ) ) + { + st->core = ACELP_CORE; + move16(); + return; + } + + /*---------------------------------------------------------------------* + * ACELP/HQ core selection + *---------------------------------------------------------------------*/ + + test(); + IF( LT_32( st->total_brate, ACELP_24k40 ) ) + { + st->core = ACELP_CORE; + move16(); + } + ELSE IF( GE_32( st->total_brate, ACELP_24k40 ) && LE_32( st->total_brate, ACELP_64k ) ) + { + /* read the ACELP/HQ core selection bit */ + st->core = imult1616( get_next_indice_fx( st, 1 ), HQ_CORE ); + move16(); + } + ELSE + { + st->core = HQ_CORE; + move16(); + } + + /*-----------------------------------------------------------------* + * Read ACELP signalling bits from the bitstream + *-----------------------------------------------------------------*/ + + IF( st->core == ACELP_CORE ) + { + /* find the section in the ACELP signalling table corresponding to bitrate */ + start_idx = 0; + move16(); + WHILE( acelp_sig_tbl[start_idx] != st->total_brate ) + { + start_idx = add( start_idx, 1 ); + } + + /* skip the bitrate */ + start_idx = add( start_idx, 1 ); + + /* retrieve the number of bits */ + nBits = extract_l( acelp_sig_tbl[start_idx] ); + start_idx = add( start_idx, 1 ); + + /* retrieve the signalling indice */ + ind = acelp_sig_tbl[start_idx + get_next_indice_fx( st, nBits )]; + st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7 ) ); + move16(); + + /* convert signalling indice into signalling information */ + if ( EQ_32( L_and( ind, 0x7 ), LR_MDCT ) ) + { + st->core = HQ_CORE; + move16(); + } + } + + /*-----------------------------------------------------------------* + * Read HQ signalling bits from the bitstream + * Set HQ core type + *-----------------------------------------------------------------*/ + + IF( EQ_16( st->core, HQ_CORE ) ) + { + /* read the HQ/TCX core switching flag */ + if ( get_next_indice_fx( st, 1 ) != 0 ) + { + st->core = TCX_20_CORE; + move16(); + } + + /* For TCX: read/set band-width (needed for different I/O sampling rate support) */ + test(); + IF( EQ_16( st->core, TCX_20_CORE ) && GT_32( st->total_brate, ACELP_16k40 ) ) + { + ind = get_next_indice_fx( st, 2 ); + + IF( ind == 0 ) + { + st->bwidth = NB; + move16(); + } + ELSE IF( EQ_32( ind, 1 ) ) + { + st->bwidth = WB; + move16(); + } + ELSE IF( EQ_32( ind, 2 ) ) + { + st->bwidth = SWB; + move16(); + } + ELSE + { + st->bwidth = FB; + move16(); + } + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * mdct_switching_dec() + * + * Set up MDCT core switching if indicated in the bit stream + *-------------------------------------------------------------------*/ + +void mdct_switching_dec_fx( + Decoder_State *st /* i/o: decoder state structure */ +) +{ + if ( !st->bfi ) + { + IF( st->Opt_AMR_WB != 0 ) + { + return; + } + + test(); + test(); + IF( EQ_32( st->total_brate, ACELP_13k20 ) || EQ_32( st->total_brate, ACELP_32k ) ) + { + st->mdct_sw_enable = MODE1; + move16(); + } + ELSE IF( LE_32( ACELP_16k40, st->total_brate ) && LE_32( st->total_brate, ACELP_24k40 ) ) + { + st->mdct_sw_enable = MODE2; + move16(); + } + + test(); + test(); + IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->mdct_sw_enable, MODE1 ) ) + { + /* Read ahead core mode signaling */ + Word16 next_bit_pos_save; + Word16 core_save; + Word16 bwidth_save; + + next_bit_pos_save = st->next_bit_pos; + move16(); + core_save = st->core; + move16(); + bwidth_save = st->bwidth; + move16(); + + decision_matrix_core_dec( st ); /* sets st->core */ + + IF( EQ_16( st->core, TCX_20_CORE ) ) + { + /* Trigger TCX */ + st->codec_mode = MODE2; + move16(); + st->mdct_sw = MODE1; + move16(); + } + ELSE + { + /* Rewind bitstream */ + st->next_bit_pos = next_bit_pos_save; + move16(); + IF( st->bfi != 0 ) + { + st->core = core_save; + move16(); + st->bwidth = bwidth_save; + move16(); + } + } + } + ELSE IF( EQ_16( st->codec_mode, MODE2 ) && EQ_16( st->mdct_sw_enable, MODE2 ) ) + { + /* Read ahead core mode signaling */ + Word16 next_bit_pos_save; + Word16 core_save; + Word16 bwidth_save; + + next_bit_pos_save = st->next_bit_pos; + move16(); + core_save = st->core; + move16(); + bwidth_save = st->bwidth; + move16(); + + dec_prm_core( st ); /* sets st->core */ + + IF( EQ_16( st->core, HQ_CORE ) ) + { + /* Trigger HQ_CORE */ + st->codec_mode = MODE1; + move16(); + st->mdct_sw = MODE2; + move16(); + } + ELSE + { + /* Rewind bitstream */ + st->next_bit_pos = next_bit_pos_save; + move16(); + if ( st->bfi != 0 ) + { + st->core = core_save; + move16(); + } + /* always reset bwidth, to not interfere with BER logic */ + st->bwidth = bwidth_save; + move16(); + } + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * reset_elements() + * + * Simulate packet losses by reading FEC pattern from external file + *-------------------------------------------------------------------*/ + +Decoder_State **reset_elements( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + Word16 k, n; + Decoder_State **sts = NULL; /* to avoid compilation warning */ + + FOR( k = 0; k < st_ivas->nSCE; k++ ) + { + sts = st_ivas->hSCE[k]->hCoreCoder; + + sts[0]->bfi = 0; + sts[0]->BER_detect = 0; + sts[0]->mdct_sw_enable = 0; + sts[0]->mdct_sw = 0; + + move16(); + move16(); + move16(); + move16(); + + reset_indices_dec( sts[0] ); + } + + FOR( k = 0; k < st_ivas->nCPE; k++ ) + { + sts = st_ivas->hCPE[k]->hCoreCoder; + + FOR( n = 0; n < CPE_CHANNELS; n++ ) + { + sts[n]->bfi = 0; + sts[n]->BER_detect = 0; + sts[n]->mdct_sw_enable = 0; + sts[n]->mdct_sw = 0; + + move16(); + move16(); + move16(); + move16(); + + reset_indices_dec( sts[n] ); + } + } + + return sts; /* return last decoder state */ +} + + +/*-------------------------------------------------------------------* + * ivas_set_bitstream_pointers() + * + * Set bitstream pointers for every SCE/CPE Core-Decoder + *-------------------------------------------------------------------*/ + +void ivas_set_bitstream_pointers( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + Word16 k, num_bits; + Decoder_State **sts; + + num_bits = 0; + + /* set bitstream pointers for SCEs */ + for ( k = 0; k < st_ivas->nSCE; k++ ) + { + sts = st_ivas->hSCE[k]->hCoreCoder; sts[0]->bit_stream = st_ivas->bit_stream + num_bits; num_bits += (Word16) ( st_ivas->hSCE[k]->element_brate / FRAMES_PER_SEC ); } @@ -3733,12 +4375,65 @@ void ivas_set_bitstream_pointers( return; } +#ifdef DEBUGGING + +/*-------------------------------------------------------------------* + * file_read_FECpattern() + * + * Simulate packet losses by reading FEC pattern from external file + *-------------------------------------------------------------------*/ + +static ivas_error file_read_FECpattern( + Word16 *bfi ) +{ + ivas_error error; + + error = IVAS_ERR_OK; + *bfi = 0; + + /* FEC pattern file provided */ + if ( FEC_pattern != NULL ) + { + Word16 tmp = 0; + if ( fread( &tmp, sizeof( Word16 ), 1, FEC_pattern ) != 1 ) + { + if ( feof( FEC_pattern ) != 0 ) + { +#ifdef WRAP_AS_EIDXOR + fseek( FEC_pattern, 0L, SEEK_SET ); + fread( &tmp, sizeof( Word16 ), 1, FEC_pattern ); +#else + tmp = 0; + fseek( FEC_pattern, 0L, SEEK_SET ); +#endif + } + else + { + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error reading the FEC pattern file !" ); + } + } + + if ( tmp == 2609 || tmp == 1 || tmp == (UWord16) 0x6B20 /* == G192_SYNC_BAD_FRAME */ ) + { + *bfi = 1; + } + else + { + *bfi = 0; + } + } + + return error; +} + +#endif /*-------------------------------------------------------------------* * read_indices() * - * Read indices from an ITU-T G.192 bitstream to the buffer - * Simulate packet losses by inserting frame erasures + * Detect SID, NO_DATA, BFI, etc. and set bitstream pointers + * Set ivas_total_brate + * Note: each bit is represented in bitsream buffer as a uint16_t of value 0 or 1 *-------------------------------------------------------------------*/ /*! r: 1 = reading OK, 0 = problem */ @@ -3770,15 +4465,28 @@ ivas_error read_indices_fx( move16(); sts = reset_elements( st_ivas ); +#ifdef DEBUGGING + file_read_FECpattern( &st_ivas->bfi ); + st_ivas->bfi |= bfi; + + if ( bfi == FRAMEMODE_MISSING ) + { + for ( k = 0; k < num_bits; k++ ) + { + bit_stream[k] = 0; + } + } +#else st_ivas->bfi = bfi; move16(); +#endif /* convert the frame length to total bitrate */ total_brate = imult3216( num_bits, FRAMES_PER_SEC ); move32(); - /* verify that a valid num bits value is present in the G.192 file */ - /* only AMRWB, EVS or IVAS bitrates or 0(NO DATA) are allowed in G.192 file frame reading */ + /* verify that a valid num bits value is present */ + /* only AMRWB, EVS or IVAS bitrates or 0 (NO DATA) are allowed */ IF( NE_32( st_ivas->ivas_format, MONO_FORMAT ) ) { k = 0; @@ -3806,7 +4514,7 @@ ivas_error read_indices_fx( } ELSE IF( EQ_16( k, SIZE_IVAS_BRATE_TBL ) ) { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error, illegal bitrate (%d) in the G.192 frame ! Exiting ! \n", total_brate ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error, illegal bitrate (%d) detected! Exiting ! \n", total_brate ); } ELSE { @@ -3819,14 +4527,14 @@ ivas_error read_indices_fx( st_ivas->element_mode_init = EVS_MONO; move16(); - IF( rate2EVSmode_float( total_brate, NULL ) < 0 ) /* negative value means that a valid rate was not found */ + IF( rate2EVSmode( total_brate, NULL ) < 0 ) /* negative value means that a valid rate was not found */ { - return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error, illegal bitrate (%d) in the G.192 frame ! Exiting ! \n", total_brate ); + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error, illegal bitrate (%d) detected! Exiting ! \n", total_brate ); } } - /* G.192 RX DTX handler*/ - /* handle SID_FIRST, SID_BAD, SPEECH_LOST, NO_DATA as properly as possible for the ITU-T G.192 format */ + /* G.RX DTX handler*/ + /* handle SID_FIRST, SID_BAD, SPEECH_LOST, NO_DATA */ /* (total_brate, bfi , st_CNG) = rx_handler(received frame type, [previous frame type], past CNG state, past core) */ curr_ft_good_sp = 0; move16(); @@ -3888,7 +4596,6 @@ ivas_error read_indices_fx( it declares every bad synch marked frame initially as a lost_speech frame, and then the RXDTX handler CNG state decides the decoding mode CNG/SPEECH. While In the AMRWB ETSI/3GPP format eid a CRC error in a detected SID_UPDATE frames triggers SID_BAD. - Here we inhibit use of the SID-length info, even though it is available in the G.192 file format after STL/EID-XOR . */ IF( sid_upd_bad ) @@ -4049,4 +4756,502 @@ ivas_error read_indices_fx( return error; } -#undef WMC_TOOL_SKIP + + +/*-------------------------------------------------------------------* + * berCheck() + * + * Check for bit errors in channel aware signalling. + *-------------------------------------------------------------------*/ + +static void berCheck( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *coder_type /* i/o: coder type */ +) +{ + /* In case of RF flag = 1, and valid RF packet with primary and partial copy */ + test(); + test(); + IF( ( EQ_16( st->bwidth, NB ) || EQ_16( st->bwidth, FB ) ) || ( GE_16( *coder_type, TRANSITION ) ) ) + { + if ( EQ_16( st->use_partial_copy, 1 ) ) + { + st->use_partial_copy = 0; + move16(); + } + + st->bfi = 1; + move16(); + st->bwidth = st->last_bwidth; + move16(); + st->BER_detect = 1; + move16(); + *coder_type = GENERIC; + move16(); + } + + return; +} + + +/*-------------------------------------------------------------------* + * getPartialCopyInfo() + * + * Check if the frame includes a partial copy for channel aware processing. + *-------------------------------------------------------------------*/ + +void getPartialCopyInfo( + Decoder_State *st, /* i/o: decoder state structure */ + Word16 *coder_type, + Word16 *sharpFlag ) +{ + Word16 nBits; + Word16 ind; + /* check the rf flag in the packet */ + get_rfFlag( st, &( st->rf_flag ), &nBits, &ind ); + + /* get rf frame type info */ + get_rfFrameType( st, &( st->rf_frame_type ) ); + + /* Get the FEC offset info */ + get_rf_fec_offset( st, &( st->rf_fec_offset ) ); + + /* reset number of target bits in case of rate switching */ + st->rf_target_bits = 0; + move16(); + + /* Get the number of bits used for RF*/ + IF( EQ_16( st->rf_flag, 1 ) ) + { + *coder_type = s_and( ind, 0x7 ); + move16(); + st->bwidth = s_and( shr( ind, 3 ), 0x7 ); + move16(); + *sharpFlag = s_and( shr( ind, 6 ), 0x1 ); + move16(); + st->codec_mode = MODE2; + move16(); + get_rfTargetBits( st->rf_frame_type, &( st->rf_target_bits ) ); + + IF( EQ_16( st->bfi, FRAMEMODE_FUTURE ) ) + { + st->use_partial_copy = 1; + move16(); + /* now set the frame mode to normal mode */ + test(); + IF( GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) ) + { + st->bfi = 1; + move16(); + st->core = 1; + move16(); + } + ELSE + { + st->bfi = FRAMEMODE_NORMAL; + move16(); + st->core = 0; + move16(); + } + } + /* check for bit errors */ + berCheck( st, coder_type ); + + get_next_indice_tmp_fx( st, nBits ); + } + + return; +} + + +/*-------------------------------------------------------------------* + * get_rfFlag() + * + * Check if rf flag is present in the bitstream + *-------------------------------------------------------------------*/ + +void get_rfFlag( + Decoder_State *st, /* i: decoder state structure */ + Word16 *rf_flag, /* o : check for the RF flag */ + Word16 *nBits, + Word16 *ind ) +{ + Word16 start_idx, nBits_tmp; + Word16 ind_tmp; + + /* Init */ + *rf_flag = 0; + move16(); + + /* check for rf_flag in the packet and extract the rf_frame_type and rf_fec_offset */ + test(); + test(); + IF( EQ_32( st->total_brate, ACELP_13k20 ) && ( ( st->bfi == FRAMEMODE_NORMAL ) || EQ_16( st->bfi, FRAMEMODE_FUTURE ) ) ) + { + /* find the section in the ACELP signalling table corresponding to bitrate */ + start_idx = 0; + move16(); + WHILE( acelp_sig_tbl[start_idx] != st->total_brate ) + { + start_idx = add( start_idx, 1 ); + assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); + } + + /* skip the bitrate */ + start_idx = add( start_idx, 1 ); + + /* retrieve the number of bits */ + nBits_tmp = (Word16) acelp_sig_tbl[start_idx++]; + move16(); + + /* retrieve the signalling indice */ + ind_tmp = (Word16) acelp_sig_tbl[add( start_idx, get_indice_fx( st, 0, nBits_tmp ) )]; + move16(); + + /* convert signalling indice into RF flag. */ + *rf_flag = s_and( shr( ind_tmp, 7 ), 0x1 ); + move16(); + + if ( ind ) + { + *ind = ind_tmp; + move16(); + } + + if ( nBits ) + { + *nBits = nBits_tmp; + move16(); + } + } + + return; +} + + +/*-------------------------------------------------------------------* + * get_rfFrameType() + * + * Extract the rf frame type + *-------------------------------------------------------------------*/ + +void get_rfFrameType( + Decoder_State *st, /* i : decoder state structure */ + Word16 *rf_frame_type /* o : RF frame type */ +) +{ + Word16 num_bits = 0; + move16(); + + IF( EQ_16( st->rf_flag, 1 ) ) + { + /*num_bits = st->total_brate/50;*/ + IF( EQ_32( st->total_brate, ACELP_13k20 ) ) + { + num_bits = 264; + move16(); /* @13.2kbps */ + } + ELSE + { + UWord16 lsb; + Word32 L_tmp; + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + } + + /* the last three bits in a packet is the RF frame type */ + *rf_frame_type = get_indice_fx( st, sub( num_bits, 3 ), 3 ); + move16(); + } + ELSE + { + *rf_frame_type = 0; + move16(); + } + + return; +} + + +/*-------------------------------------------------------------------* + * get_rf_fec_offset() + * + * Extract the FEC offset + *-------------------------------------------------------------------*/ + +void get_rf_fec_offset( + Decoder_State *st, /* i : decoder state structure */ + Word16 *rf_fec_offset /* o : RF fec offset */ +) +{ + Word16 num_bits, tmp; + + IF( EQ_16( st->rf_flag, 1 ) ) + { + /*num_bits = st->total_brate/50;*/ + IF( EQ_32( st->total_brate, ACELP_13k20 ) ) + { + num_bits = 264; + move16(); /* @13.2kbps */ + } + ELSE + { + UWord16 lsb; + Word32 L_tmp; + Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ + num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ + } + + /* the two bits before the rf frame type contain the fec offset */ + tmp = get_indice_fx( st, sub( num_bits, 5 ), 2 ); + + IF( tmp == 0 ) + { + *rf_fec_offset = 2; + move16(); + } + ELSE + { + *rf_fec_offset = add( shl( tmp, 1 ), 1 ); + move16(); + } + } + ELSE + { + *rf_fec_offset = 0; + move16(); + } + + return; +} + + +/*-------------------------------------------------------------------* + * get_rfTargetBits() + * + * Return the number of RF target bits + *-------------------------------------------------------------------*/ + +void get_rfTargetBits( + Word16 rf_frame_type, /* i : RF frame type */ + Word16 *rf_target_bits /* o : Number of RF target bits */ +) +{ + /* Number of RF bits for different RF coder types */ + SWITCH( rf_frame_type ) + { + case RF_NO_DATA: + *rf_target_bits = 5; + move16(); + BREAK; + case RF_TCXFD: + *rf_target_bits = 27; + move16(); + BREAK; + case RF_TCXTD1: + *rf_target_bits = 16; + move16(); + BREAK; + case RF_TCXTD2: + *rf_target_bits = 16; + move16(); + BREAK; + case RF_ALLPRED: + /* Es_pred bits 3 bits, LTF: 1, pitch: 8,5,5,5, FCB: 0, gain: 7,0,7,0, Diff GFr: 4*/ + *rf_target_bits = 63; + move16(); + BREAK; + case RF_NOPRED: + /* Es_pred bits 3 bits, LTF: 0, pitch: 0, FCB: 7,7,7,7, gain: 6,0,6,0, Diff GFr: 2*/ + *rf_target_bits = 66; + move16(); + BREAK; + case RF_GENPRED: + /* Es_pred bits 3 bits, LTF: 1, pitch: 8,0,8,0, FCB: 6,7,5,5, gain: 5,0,5,0, Diff GFr: 0*/ + *rf_target_bits = 70; + move16(); + BREAK; + case RF_NELP: + /* gain: 19, Diff GFr: 5 */ + *rf_target_bits = 45; + move16(); + BREAK; + } + + return; +} + + +/*-------------------------------------------------------------------* + * get_NextCoderType_fx() + * + * Extract the coder type of next frame + *-------------------------------------------------------------------*/ + +void get_NextCoderType_fx( + UWord8 *bitsteam, /* i : bitstream */ + Word16 *next_coder_type /* o : next coder type */ +) +{ + Word16 k; + Word16 start_idx; + Word16 nBits_tmp; + Word8 bit_stream[ACELP_13k20 / 50]; + UWord16 tmp; + + FOR( k = 0; k < ACELP_13k20 / 50; k++ ) + { + bit_stream[k] = (UWord8) s_and( shr( bitsteam[k / 8], sub( 7, s_and( k, 7 ) ) ), 0x1 ); + move16(); + } + start_idx = 0; + move16(); + WHILE( acelp_sig_tbl[start_idx] != ACELP_13k20 ) + { + start_idx = add( start_idx, 1 ); + assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); + } + + /* skip the bitrate */ + start_idx = add( start_idx, 1 ); + + tmp = 0; + move16(); + nBits_tmp = extract_l( acelp_sig_tbl[start_idx++] ); + move16(); + FOR( k = 0; k < nBits_tmp; k++ ) + { + tmp = lshl( tmp, 1 ); + tmp = add( tmp, bit_stream[k] ); + } + + /* retrieve the signalling indice */ + *next_coder_type = s_and( extract_l( acelp_sig_tbl[start_idx + tmp] ), 0x7 ); + move16(); + + return; +} + + +/*-------------------------------------------------------------------* + * get_indice_preview() + * + * Indices preview to parse for the presence of partial copy + *-------------------------------------------------------------------*/ + +static UWord16 get_indice_preview( + UWord8 *bitstream, + Word16 bitstreamSize, + Word16 pos, + Word16 nb_bits ) +{ + UWord16 value; + Word16 i; + UWord16 bitstreamShort[MAX_BITS_PER_FRAME + 16]; + UWord16 *bitstreamShortPtr; + + /* convert bitstream from compact bytes to short values */ + bitstreamShortPtr = bitstreamShort; + FOR( i = 0; i < bitstreamSize; i++ ) + { + *bitstreamShortPtr++ = s_and( shr( bitstream[i / 8], sub( 7, ( s_and( i, 7 ) ) ) ), 0x1 ); + move16(); + } + + assert( nb_bits <= 16 ); + value = 0; + move16(); + FOR( i = 0; i < nb_bits; i++ ) + { + value = shl( value, 1 ); + value = add( value, bitstreamShort[pos + i] ); + } + + return value; +} + + +/*-------------------------------------------------------------------* + * evs_dec_previewFrame() + * + * Signalling index preview + *-------------------------------------------------------------------*/ + +void evs_dec_previewFrame( + UWord8 *bitstream, + Word16 bitstreamSize, + Word16 *partialCopyFrameType, + Word16 *partialCopyOffset ) +{ + Word32 total_brate; + Word16 start_idx, nBits; + Word32 ind; + Word16 rf_flag; + + rf_flag = 0; + move16(); + *partialCopyFrameType = 0; + move16(); + *partialCopyOffset = 0; + move16(); + total_brate = L_mult0( bitstreamSize, 50 ); + + IF( EQ_32( total_brate, ACELP_13k20 ) ) + { + /* find the section in the ACELP signalling table corresponding to bitrate */ + start_idx = 0; + move16(); + WHILE( acelp_sig_tbl[start_idx] != total_brate ) + { + start_idx = add( start_idx, 1 ); + assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); + } + + /* skip the bitrate */ + start_idx = add( start_idx, 1 ); + /* retrieve the number of bits */ + nBits = extract_l( acelp_sig_tbl[start_idx++] ); + + /* retrieve the signalling indice */ + ind = acelp_sig_tbl[( start_idx + get_indice_preview( bitstream, bitstreamSize, 0, nBits ) )]; + move32(); + + /* convert signalling indice into RF flag. */ + rf_flag = s_and( extract_l( L_shr( ind, 7 ) ), 0x1 ); + assert( rf_flag == ( ( ind >> 7 ) & 0x1 ) ); + IF( rf_flag != 0 ) + { + /* read the fec offset at which the partial copy is received */ + ind = get_indice_preview( bitstream, bitstreamSize, sub( bitstreamSize, 5 ), 2 ); + IF( ind == 0 ) *partialCopyOffset = 2; + ELSE IF( EQ_32( ind, 1 ) ) *partialCopyOffset = 3; + ELSE IF( EQ_32( ind, 2 ) ) *partialCopyOffset = 5; + ELSE IF( EQ_32( ind, 3 ) ) *partialCopyOffset = 7; + move16(); + /* the last three bits in a packet is the RF frame type */ + *partialCopyFrameType = get_indice_preview( bitstream, bitstreamSize, bitstreamSize - 3, 3 ); + move16(); + } + } + + return; +} + + +void dtx_read_padding_bits_fx( + DEC_CORE_HANDLE st, + const Word16 num_bits ) +{ + /* TODO: temporary hack, need to decide what to do with core-coder bitrate */ + Word32 tmp; + + tmp = st->total_brate; + move32(); + st->total_brate = L_add( st->total_brate, L_mult0( num_bits, FRAMES_PER_SEC ) ); + move32(); + get_next_indice_fx( st, num_bits ); + st->total_brate = tmp; + move32(); + + return; +} diff --git a/lib_com/bitstream_fx.c b/lib_com/bitstream_fx.c deleted file mode 100644 index ce8d9018e..000000000 --- a/lib_com/bitstream_fx.c +++ /dev/null @@ -1,1316 +0,0 @@ -/****************************************************************************************************** - - (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository. All Rights Reserved. - - This software is protected by copyright law and by international treaties. - The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, - Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., - Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, - Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other - contributors to this repository retain full ownership rights in their respective contributions in - the software. This notice grants no license of any kind, including but not limited to patent - license, nor is any license granted by implication, estoppel or otherwise. - - Contributors are required to enter into the IVAS codec Public Collaboration agreement before making - contributions. - - This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and - solely for the purpose of inspection. All implied warranties of non-infringement, merchantability - and fitness for a particular purpose are hereby disclaimed and excluded. - - Any dispute, controversy or claim arising under or in relation to providing this software shall be - submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in - accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and - the United Nations Convention on Contracts on the International Sales of Goods. - -*******************************************************************************************************/ - -/*==================================================================================== - EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 - ====================================================================================*/ - -#include -#include -#include -#include "options.h" -#include "ivas_cnst.h" /* Common constants */ -#include "prot_fx.h" /* Function prototypes */ -#include "ivas_prot_fx.h" -#include "basop_util.h" -#include "rom_com.h" -#include "mime.h" - -#ifdef DEBUGGING -/*-------------------------------------------------------------------* - * Global variables - *--------------------------------------------------------------------*/ - -int16_t FEC_seed = 12558; /* Seed for random FEC generator */ -FILE *FEC_pattern = NULL; /* FEC pattern file (for simulation of FEC) */ -float FEC_random = 0; /* FEC rate in percent (for simulation of FEC) */ -/*-------------------------------------------------------------------* - * file_read_FECpattern() - * - * Simulate packet losses by reading FEC pattern from external file - *-------------------------------------------------------------------*/ - -static int16_t file_read_FECpattern( void ) -{ - int16_t bfi = 0; - - /* FEC pattern file provided */ - if ( FEC_pattern != NULL ) - { - int16_t tmp = 0; - if ( fread( &tmp, sizeof( int16_t ), 1, FEC_pattern ) != 1 ) - { - if ( feof( FEC_pattern ) != 0 ) - { - tmp = 0; - fseek( FEC_pattern, 0L, SEEK_SET ); - } - else - { - fprintf( stderr, "\nError reading the FEC pattern file !" ); - exit( -1 ); - } - } - - if ( tmp == 2609 || tmp == 1 || tmp == SYNC_BAD_FRAME ) - { - bfi = 1; - } - else - { - bfi = 0; - } - } - - /* random FEC simulation requested */ - else if ( FEC_random > 0 ) - { - float ftmp = (float) /*own_random*/ Random( &FEC_seed ) + 32768.0f; - if ( ftmp <= FEC_random / 100.0f * 65535.0f ) - { - bfi = 1; - } - else - { - bfi = 0; - } - } - - return bfi; -} -#endif -/*-------------------------------------------------------------------* - * pack_bit() - * - * insert a bit into packed octet - *-------------------------------------------------------------------*/ -void pack_bit( - const Word16 bit, /* i: bit to be packed */ - UWord8 **pt, /* i/o: pointer to octet array into which bit will be placed */ - UWord8 *omask /* i/o: output mask to indicate where in the octet the bit is to be written */ -) -{ - if ( EQ_16( *omask, 0x80 ) ) - { - **pt = 0; - move16(); - } - IF( bit != 0 ) - { - **pt = (UWord8) s_or( **pt, *omask ); - move16(); - } - *omask = (UWord8) shr( *omask, 1 ); - move16(); - IF( *omask == 0 ) - { - *omask = 0x80; - move16(); - ( *pt )++; - } - - return; -} - - -/*-------------------------------------------------------------------* - * rate2AMRWB_IOmode() - * - * lookup AMRWB IO mode - *-------------------------------------------------------------------*/ -static Word16 rate2AMRWB_IOmode( - Word32 brate /* i: bitrate */ -) -{ - SWITCH( brate ) - { - /* EVS AMR-WB IO modes */ - case SID_1k75: - return AMRWB_IO_SID; - case ACELP_6k60: - return AMRWB_IO_6600; - case ACELP_8k85: - return AMRWB_IO_8850; - case ACELP_12k65: - return AMRWB_IO_1265; - case ACELP_14k25: - return AMRWB_IO_1425; - case ACELP_15k85: - return AMRWB_IO_1585; - case ACELP_18k25: - return AMRWB_IO_1825; - case ACELP_19k85: - return AMRWB_IO_1985; - case ACELP_23k05: - return AMRWB_IO_2305; - case ACELP_23k85: - return AMRWB_IO_2385; - default: - break; - } - return -1; -} - -/*-------------------------------------------------------------------* - * rate2EVSmode() - * - * lookup EVS mode - *-------------------------------------------------------------------*/ -Word16 rate2EVSmode( - const Word32 brate, /* i: bitrate */ - Word16 *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ -) -{ - if ( is_amr_wb != NULL ) - { - *is_amr_wb = 0; - move16(); - } - SWITCH( brate ) - { - /* EVS Primary modes */ - case FRAME_NO_DATA: - return NO_DATA_TYPE; - case SID_2k40: - return PRIMARY_SID; - case PPP_NELP_2k80: - return PRIMARY_2800; - case ACELP_7k20: - return PRIMARY_7200; - case ACELP_8k00: - return PRIMARY_8000; - case ACELP_9k60: - return PRIMARY_9600; - case ACELP_13k20: - return PRIMARY_13200; - case ACELP_16k40: - return PRIMARY_16400; - case ACELP_24k40: - return PRIMARY_24400; - case ACELP_32k: - return PRIMARY_32000; - case ACELP_48k: - return PRIMARY_48000; - case ACELP_64k: - return PRIMARY_64000; - case HQ_96k: - return PRIMARY_96000; - case HQ_128k: - return PRIMARY_128000; - default: - BREAK; - } - if ( is_amr_wb != NULL ) - { - *is_amr_wb = 1; - move16(); - } - return rate2AMRWB_IOmode( brate ); -} - -/*-------------------------------------------------------------------* - * push_indice( ) - * - * Push a new indice into the buffer - *-------------------------------------------------------------------*/ - -/*-------------------------------------------------------------------* - * get_next_indice_fx( ) - * - * Get the next indice from the buffer - *-------------------------------------------------------------------*/ - -UWord16 get_next_indice_fx( /* o : value of the indice */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ -) -{ - UWord16 value; - Word16 i; - Word16 nbits_total; - - assert( nb_bits <= 16 ); - value = 0; - move16(); - - nbits_total = extract_l( Mpy_32_32( st_fx->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - /* detect corrupted bitstream */ - IF( GT_16( add( st_fx->next_bit_pos, nb_bits ), nbits_total ) ) - { - st_fx->BER_detect = 1; - move16(); - return ( 0 ); - } - - FOR( i = 0; i < nb_bits; i++ ) - { - value = (UWord16) L_shl( value, 1 ); - value = (UWord16) L_add( value, st_fx->bit_stream[add( st_fx->next_bit_pos, i )] ); - } - - /* update the position in the bitstream */ - st_fx->next_bit_pos = add( st_fx->next_bit_pos, nb_bits ); - move16(); - return value; -} - -/*-------------------------------------------------------------------* - * get_next_indice_1_fx( ) - * - * Get the next 1-bit indice from the buffer - *-------------------------------------------------------------------*/ - -UWord16 get_next_indice_1_fx( /* o : value of the indice */ - Decoder_State *st_fx /* i/o: decoder state structure */ -) -{ - Word16 nbits_total; - nbits_total = extract_l( Mpy_32_32( st_fx->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - /* detect corrupted bitstream */ - test(); - test(); - test(); - IF( ( GT_16( add( st_fx->next_bit_pos, 1 ), nbits_total ) && EQ_16( st_fx->codec_mode, MODE1 ) ) || - ( GT_16( add( st_fx->next_bit_pos, 1 ), add( nbits_total, 2 * 8 ) ) && EQ_16( st_fx->codec_mode, MODE2 ) ) /* add two zero bytes for arithmetic coder flush */ - ) - { - st_fx->BER_detect = 1; - move16(); - return ( 0 ); - } - - return st_fx->bit_stream[st_fx->next_bit_pos++]; -} - -/*-------------------------------------------------------------------* - * get_next_indice_tmp() - * - * update the total number of bits and the position in the bitstream - *-------------------------------------------------------------------*/ - -void get_next_indice_tmp_fx( - Decoder_State *st_fx, /* o : decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ -) -{ - /* update the position in the bitstream */ - st_fx->next_bit_pos = add( st_fx->next_bit_pos, nb_bits ); - move16(); -} - -/*-------------------------------------------------------------------* - * get_indice_1_fx( ) - * - * Get a 1-bit indice at specific position in the buffer - *-------------------------------------------------------------------*/ - -UWord16 get_indice_1_fx( /* o : value of the indice */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 pos /* i : absolute position in the bitstream (update after the read) */ -) -{ - Word16 nbits_total; - nbits_total = extract_l( Mpy_32_32( st_fx->total_brate, ONE_BY_FRAMES_PER_SEC_Q31 ) ); - /* detect corrupted bitstream */ - IF( GT_16( add( pos, 1 ), nbits_total ) ) - { - st_fx->BER_detect = 1; - move16(); - return ( 0 ); - } - - return st_fx->bit_stream[pos]; -} - -/*-------------------------------------------------------------------* - * reset_indices_enc_fx() - * - * Reset the buffer of indices - *-------------------------------------------------------------------*/ - -void reset_indices_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder state structure */ - const Word16 max_num_indices /* i : max number of indices */ -) -{ - Word16 i; - - hBstr->nb_ind_tot = 0; - move16(); - hBstr->nb_bits_tot = 0; - move16(); - FOR( i = 0; i < max_num_indices; i++ ) - { - hBstr->ind_list[i].nb_bits = -1; - move16(); - } - - return; -} - - -static void dec_prm_core( Decoder_State *st ) -{ - Word16 n, frame_size_index, num_bits; - UWord16 lsb; - Word32 L_tmp; - - frame_size_index = -1; - move16(); - st->core = -1; - move16(); - - IF( st->total_brate == FRAME_NO_DATA ) - { - st->m_frame_type = ZERO_FRAME; - move16(); - } - ELSE IF( EQ_32( st->total_brate, SID_2k40 ) ) - { - st->m_frame_type = SID_FRAME; - move16(); - } - ELSE - { - st->m_frame_type = ACTIVE_FRAME; - move16(); - Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - assert( num_bits == st->total_brate / 50 ); - FOR( n = 0; n < FRAME_SIZE_NB; ++n ) - { - IF( EQ_16( FrameSizeConfig[n].frame_bits, num_bits ) ) - { - frame_size_index = n; - move16(); - BREAK; - } - } - - /* Get bandwidth mode */ - st->bwidth = get_next_indice_fx( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); - move16(); - - st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); - move16(); - - IF( GT_16( st->bwidth, FB ) ) - { - st->bwidth = FB; - move16(); - st->BER_detect = 1; - move16(); - } - - test(); - IF( GT_16( st->bwidth, SWB ) && LT_32( st->total_brate, ACELP_16k40 ) ) - { - st->bwidth = SWB; - move16(); - st->BER_detect = 1; - move16(); - } - - /* Skip reserved bit */ - get_next_indice_tmp_fx( st, FrameSizeConfig[frame_size_index].reserved_bits ); - - IF( get_next_indice_1_fx( st ) != 0 ) /* TCX */ - { - st->core = TCX_20_CORE; - move16(); - if ( get_next_indice_1_fx( st ) != 0 ) - { - st->core = HQ_CORE; - move16(); - } - } - ELSE /* ACELP */ - { - st->core = ACELP_CORE; - move16(); - } - } -} - -/*-----------------------------------------------------------------* - * decision_matrix_core_dec() - * - * Read core mode signalling bits from the bitstream - * Set st->core, and st->bwidth if signalled together with the core. - *-----------------------------------------------------------------*/ - -static void decision_matrix_core_dec( - Decoder_State *st /* i/o: decoder state structure */ -) -{ - Word16 start_idx; - Word32 ind; - Word16 nBits; - - assert( st->bfi != 1 ); - - st->core = -1; - move16(); - st->bwidth = -1; - move16(); - - test(); - IF( ( st->total_brate == FRAME_NO_DATA ) || EQ_32( st->total_brate, SID_2k40 ) ) - { - st->core = ACELP_CORE; - move16(); - } - /* SC-VBR */ - ELSE IF( EQ_32( st->total_brate, PPP_NELP_2k80 ) ) - { - st->core = ACELP_CORE; - move16(); - return; - } - - /*---------------------------------------------------------------------* - * ACELP/HQ core selection - *---------------------------------------------------------------------*/ - - test(); - IF( LT_32( st->total_brate, ACELP_24k40 ) ) - { - st->core = ACELP_CORE; - move16(); - } - ELSE IF( GE_32( st->total_brate, ACELP_24k40 ) && LE_32( st->total_brate, ACELP_64k ) ) - { - /* read the ACELP/HQ core selection bit */ - st->core = imult1616( get_next_indice_fx( st, 1 ), HQ_CORE ); - move16(); - } - ELSE - { - st->core = HQ_CORE; - move16(); - } - - /*-----------------------------------------------------------------* - * Read ACELP signalling bits from the bitstream - *-----------------------------------------------------------------*/ - - IF( st->core == ACELP_CORE ) - { - /* find the section in the ACELP signalling table corresponding to bitrate */ - start_idx = 0; - move16(); - WHILE( acelp_sig_tbl[start_idx] != st->total_brate ) - { - start_idx = add( start_idx, 1 ); - } - - /* skip the bitrate */ - start_idx = add( start_idx, 1 ); - - /* retrieve the number of bits */ - nBits = extract_l( acelp_sig_tbl[start_idx] ); - start_idx = add( start_idx, 1 ); - - /* retrieve the signalling indice */ - ind = acelp_sig_tbl[start_idx + get_next_indice_fx( st, nBits )]; - st->bwidth = extract_l( L_and( L_shr( ind, 3 ), 0x7 ) ); - move16(); - - /* convert signalling indice into signalling information */ - if ( EQ_32( L_and( ind, 0x7 ), LR_MDCT ) ) - { - st->core = HQ_CORE; - move16(); - } - } - - /*-----------------------------------------------------------------* - * Read HQ signalling bits from the bitstream - * Set HQ core type - *-----------------------------------------------------------------*/ - - IF( EQ_16( st->core, HQ_CORE ) ) - { - /* read the HQ/TCX core switching flag */ - if ( get_next_indice_fx( st, 1 ) != 0 ) - { - st->core = TCX_20_CORE; - move16(); - } - - /* For TCX: read/set band-width (needed for different I/O sampling rate support) */ - test(); - IF( EQ_16( st->core, TCX_20_CORE ) && GT_32( st->total_brate, ACELP_16k40 ) ) - { - ind = get_next_indice_fx( st, 2 ); - - IF( ind == 0 ) - { - st->bwidth = NB; - move16(); - } - ELSE IF( EQ_32( ind, 1 ) ) - { - st->bwidth = WB; - move16(); - } - ELSE IF( EQ_32( ind, 2 ) ) - { - st->bwidth = SWB; - move16(); - } - ELSE - { - st->bwidth = FB; - move16(); - } - } - } - - return; -} - -/*-------------------------------------------------------------------* - * mdct_switching_dec() - * - * Set up MDCT core switching if indicated in the bit stream - *-------------------------------------------------------------------*/ - -void mdct_switching_dec_fx( - Decoder_State *st /* i/o: decoder state structure */ -) -{ - if ( !st->bfi ) - { - IF( st->Opt_AMR_WB != 0 ) - { - return; - } - - test(); - test(); - IF( EQ_32( st->total_brate, ACELP_13k20 ) || EQ_32( st->total_brate, ACELP_32k ) ) - { - st->mdct_sw_enable = MODE1; - move16(); - } - ELSE IF( LE_32( ACELP_16k40, st->total_brate ) && LE_32( st->total_brate, ACELP_24k40 ) ) - { - st->mdct_sw_enable = MODE2; - move16(); - } - - test(); - test(); - IF( EQ_16( st->codec_mode, MODE1 ) && EQ_16( st->mdct_sw_enable, MODE1 ) ) - { - /* Read ahead core mode signaling */ - Word16 next_bit_pos_save; - Word16 core_save; - Word16 bwidth_save; - - next_bit_pos_save = st->next_bit_pos; - move16(); - core_save = st->core; - move16(); - bwidth_save = st->bwidth; - move16(); - - decision_matrix_core_dec( st ); /* sets st->core */ - - IF( EQ_16( st->core, TCX_20_CORE ) ) - { - /* Trigger TCX */ - st->codec_mode = MODE2; - move16(); - st->mdct_sw = MODE1; - move16(); - } - ELSE - { - /* Rewind bitstream */ - st->next_bit_pos = next_bit_pos_save; - move16(); - IF( st->bfi != 0 ) - { - st->core = core_save; - move16(); - st->bwidth = bwidth_save; - move16(); - } - } - } - ELSE IF( EQ_16( st->codec_mode, MODE2 ) && EQ_16( st->mdct_sw_enable, MODE2 ) ) - { - /* Read ahead core mode signaling */ - Word16 next_bit_pos_save; - Word16 core_save; - Word16 bwidth_save; - - next_bit_pos_save = st->next_bit_pos; - move16(); - core_save = st->core; - move16(); - bwidth_save = st->bwidth; - move16(); - - dec_prm_core( st ); /* sets st->core */ - - IF( EQ_16( st->core, HQ_CORE ) ) - { - /* Trigger HQ_CORE */ - st->codec_mode = MODE1; - move16(); - st->mdct_sw = MODE2; - move16(); - } - ELSE - { - /* Rewind bitstream */ - st->next_bit_pos = next_bit_pos_save; - move16(); - if ( st->bfi != 0 ) - { - st->core = core_save; - move16(); - } - /* always reset bwidth, to not interfere with BER logic */ - st->bwidth = bwidth_save; - move16(); - } - } - } - - return; -} - - -/*-------------------------------------------------------------------* - * BRATE2IDX_fx() - * - * Convert Bitrate to Index Value - *-------------------------------------------------------------------*/ - -Word16 BRATE2IDX_fx( Word32 brate ) -{ - - Word32 L_temp; - Word32 L_idx; -#define START 9 - extern const Word16 bit_rates_div50[]; - - /* This is a Fast Bit Rate Value to Index Value Binary Search */ - L_temp = L_msu0( brate, bit_rates_div50[START], 50 ); - L_temp = L_min( 6, L_max( -6, L_temp ) ); - L_idx = L_add( L_temp, START ); - L_temp = L_msu0( brate, bit_rates_div50[L_idx], 50 ); - L_temp = L_min( 3, L_max( -3, L_temp ) ); - L_idx = L_add( L_temp, L_idx ); - L_temp = L_msu0( brate, bit_rates_div50[L_idx], 50 ); - L_temp = L_min( 1, L_max( -2, L_temp ) ); - L_idx = L_add( L_temp, L_idx ); - L_temp = L_msu0( brate, bit_rates_div50[L_idx], 50 ); - if ( L_temp != 0 ) - L_idx = L_add( L_idx, 1 ); - return (Word16) L_idx; -} - - -/*-------------------------------------------------------------------* - * BRATE2IDX16k_fx() - * - * Convert Bitrate to Index Value - *-------------------------------------------------------------------*/ - -Word16 BRATE2IDX16k_fx( Word32 brate ) -{ - Word32 L_temp, L_idx; -#define START_16K 5 - extern const Word16 bit_rates_16k_div50[]; - - if ( EQ_32( brate, ACELP_16k40 ) ) - { - brate = ACELP_14k80; - move16(); - } - - /* This is a Fast Bit Rate Value to Index Value Binary Search */ - L_temp = L_msu0( brate, bit_rates_16k_div50[START_16K], 50 ); - L_temp = L_min( 3, L_max( -3, L_temp ) ); - L_idx = L_add( L_temp, START_16K ); - L_temp = L_msu0( brate, bit_rates_16k_div50[L_idx], 50 ); - L_temp = L_min( 2, L_max( -2, L_temp ) ); - L_idx = L_add( L_temp, L_idx ); - L_temp = L_msu0( brate, bit_rates_16k_div50[L_idx], 50 ); - L_temp = L_min( 1, L_max( -1, L_temp ) ); - L_idx = L_add( L_temp, L_idx ); - - return (Word16) L_idx; -} - -/*-------------------------------------------------------------------* - * BIT_ALLOC_IDX_fx() - *-------------------------------------------------------------------*/ - -Word32 BIT_ALLOC_IDX_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc ) -{ - Word32 L_temp; - Word16 temp; - if ( ctype == INACTIVE ) /* no sub(ctype, INACTIVE) because it is '0' */ - ctype = GENERIC; - move16(); - L_temp = L_mac0( -1l * 256, 1 * 256, ctype ); - - temp = BRATE2IDX_fx( brate ); - L_temp = L_mac0( L_temp, 4 * 256, temp ); - IF( tc >= 0 ) - L_temp = L_mac0( L_temp, ( 10 - 4 ) * 256, temp ); - /* So either 'temp' x 4 when 'tc < 0', 'temp' x 10 otherwise */ - - L_temp = L_mac0( L_temp, 1 * 256, s_max( 0, tc ) ); - - L_temp = L_mac0( L_temp, s_max( 0, sfrm ), 1 ); - if ( sfrm < 0 ) - L_temp = L_shr( L_temp, 2 ); - L_temp = L_shr( L_temp, 6 ); - - return L_temp; -} - -/*-------------------------------------------------------------------* - * BIT_ALLOC_IDX_16KHZ_fx() - *-------------------------------------------------------------------*/ - -Word32 BIT_ALLOC_IDX_16KHZ_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc ) -{ - Word32 L_temp; - Word16 temp; - /* 'ctype' = - TRANSITION => 2 - GENERIC => 1 - ALL Other => 0 - */ - L_temp = L_and( shr( 0x0240l, shl( ctype, 1 ) ), 3 ); - - temp = BRATE2IDX16k_fx( brate ); - L_temp = L_mac0( L_temp, 3, temp ); - IF( tc >= 0 ) - L_temp = L_mac0( L_temp, ( 7 - 3 ), temp ); - /* So either 'temp' x 3 when 'tc < 0', 'temp' x 7 otherwise */ - - L_temp = L_mac0( L_temp, 1, s_max( 0, tc ) ); - - IF( sfrm >= 0 ) - { - /* Mult by 5 */ - L_temp = L_add( L_temp, L_shl( L_temp, 2 ) ); - L_temp = L_mac0( L_temp, shr( sfrm, 6 ), 1 ); - } - - return L_temp; -} - - -/*-------------------------------------------------------------------* - * berCheck() - * - * Check for bit errors in channel aware signalling. - *-------------------------------------------------------------------*/ - -static void berCheck( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 *coder_type /* i/o: coder type */ -) -{ - /* In case of RF flag = 1, and valid RF packet with primary and partial copy */ - test(); - test(); - IF( ( EQ_16( st->bwidth, NB ) || EQ_16( st->bwidth, FB ) ) || ( GE_16( *coder_type, TRANSITION ) ) ) - { - if ( EQ_16( st->use_partial_copy, 1 ) ) - { - st->use_partial_copy = 0; - move16(); - } - - st->bfi = 1; - move16(); - st->bwidth = st->last_bwidth; - move16(); - st->BER_detect = 1; - move16(); - *coder_type = GENERIC; - move16(); - } - - return; -} - -/*-------------------------------------------------------------------* - * getPartialCopyInfo() - * - * Check if the frame includes a partial copy for channel aware processing. - *-------------------------------------------------------------------*/ - -void getPartialCopyInfo( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 *coder_type, - Word16 *sharpFlag ) -{ - Word16 nBits; - Word16 ind; - /* check the rf flag in the packet */ - get_rfFlag( st, &( st->rf_flag ), &nBits, &ind ); - - /* get rf frame type info */ - get_rfFrameType( st, &( st->rf_frame_type ) ); - - /* Get the FEC offset info */ - get_rf_fec_offset( st, &( st->rf_fec_offset ) ); - - /* reset number of target bits in case of rate switching */ - st->rf_target_bits = 0; - move16(); - - /* Get the number of bits used for RF*/ - IF( EQ_16( st->rf_flag, 1 ) ) - { - *coder_type = s_and( ind, 0x7 ); - move16(); - st->bwidth = s_and( shr( ind, 3 ), 0x7 ); - move16(); - *sharpFlag = s_and( shr( ind, 6 ), 0x1 ); - move16(); - st->codec_mode = MODE2; - move16(); - get_rfTargetBits( st->rf_frame_type, &( st->rf_target_bits ) ); - - IF( EQ_16( st->bfi, FRAMEMODE_FUTURE ) ) - { - st->use_partial_copy = 1; - move16(); - /* now set the frame mode to normal mode */ - test(); - IF( GE_16( st->rf_frame_type, RF_TCXFD ) && LE_16( st->rf_frame_type, RF_TCXTD2 ) ) - { - st->bfi = 1; - move16(); - st->core = 1; - move16(); - } - ELSE - { - st->bfi = FRAMEMODE_NORMAL; - move16(); - st->core = 0; - move16(); - } - } - /* check for bit errors */ - berCheck( st, coder_type ); - - get_next_indice_tmp_fx( st, nBits ); - } -} - -/*-------------------------------------------------------------------* - * get_rfFlag() - * - * Check if rf flag is present in the bitstream - *-------------------------------------------------------------------*/ - -void get_rfFlag( - Decoder_State *st, /* i: decoder state structure */ - Word16 *rf_flag, /* o : check for the RF flag */ - Word16 *nBits, - Word16 *ind ) -{ - Word16 start_idx, nBits_tmp; - Word16 ind_tmp; - - /* Init */ - *rf_flag = 0; - move16(); - - /* check for rf_flag in the packet and extract the rf_frame_type and rf_fec_offset */ - test(); - test(); - IF( EQ_32( st->total_brate, ACELP_13k20 ) && ( ( st->bfi == FRAMEMODE_NORMAL ) || EQ_16( st->bfi, FRAMEMODE_FUTURE ) ) ) - { - /* find the section in the ACELP signalling table corresponding to bitrate */ - start_idx = 0; - move16(); - WHILE( acelp_sig_tbl[start_idx] != st->total_brate ) - { - start_idx = add( start_idx, 1 ); - assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); - } - - /* skip the bitrate */ - start_idx = add( start_idx, 1 ); - - /* retrieve the number of bits */ - nBits_tmp = (Word16) acelp_sig_tbl[start_idx++]; - move16(); - - /* retrieve the signalling indice */ - ind_tmp = (Word16) acelp_sig_tbl[add( start_idx, get_indice( st, 0, nBits_tmp ) )]; - move16(); - - /* convert signalling indice into RF flag. */ - *rf_flag = s_and( shr( ind_tmp, 7 ), 0x1 ); - move16(); - - if ( ind ) - { - *ind = ind_tmp; - move16(); - } - - if ( nBits ) - { - *nBits = nBits_tmp; - move16(); - } - } -} - -/*-------------------------------------------------------------------* - * get_rfFrameType() - * - * Extract the rf frame type - *-------------------------------------------------------------------*/ - -void get_rfFrameType( - Decoder_State *st, /* i : decoder state structure */ - Word16 *rf_frame_type /* o : RF frame type */ -) -{ - Word16 num_bits = 0; - move16(); - - IF( EQ_16( st->rf_flag, 1 ) ) - { - /*num_bits = st->total_brate/50;*/ - IF( EQ_32( st->total_brate, ACELP_13k20 ) ) - { - num_bits = 264; - move16(); /* @13.2kbps */ - } - ELSE - { - UWord16 lsb; - Word32 L_tmp; - Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - } - - /* the last three bits in a packet is the RF frame type */ - *rf_frame_type = get_indice( st, sub( num_bits, 3 ), 3 ); - move16(); - } - ELSE - { - *rf_frame_type = 0; - move16(); - } -} - -/*-------------------------------------------------------------------* - * get_rf_fec_offset() - * - * Extract the FEC offset - *-------------------------------------------------------------------*/ - -void get_rf_fec_offset( - Decoder_State *st, /* i : decoder state structure */ - Word16 *rf_fec_offset /* o : RF fec offset */ -) -{ - Word16 num_bits, tmp; - - IF( EQ_16( st->rf_flag, 1 ) ) - { - /*num_bits = st->total_brate/50;*/ - IF( EQ_32( st->total_brate, ACELP_13k20 ) ) - { - num_bits = 264; - move16(); /* @13.2kbps */ - } - ELSE - { - UWord16 lsb; - Word32 L_tmp; - Mpy_32_16_ss( st->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l( L_shr( L_tmp, 3 ) ); /* Q0 */ - } - - /* the two bits before the rf frame type contain the fec offset */ - tmp = get_indice( st, sub( num_bits, 5 ), 2 ); - - IF( tmp == 0 ) - { - *rf_fec_offset = 2; - move16(); - } - ELSE - { - *rf_fec_offset = add( shl( tmp, 1 ), 1 ); - move16(); - } - } - ELSE - { - *rf_fec_offset = 0; - move16(); - } -} - -/*-------------------------------------------------------------------* - * get_rfTargetBits() - * - * Return the number of RF target bits - *-------------------------------------------------------------------*/ - -void get_rfTargetBits( - Word16 rf_frame_type, /* i : RF frame type */ - Word16 *rf_target_bits /* o : Number of RF target bits */ -) -{ - - /* Number of RF bits for different RF coder types */ - - SWITCH( rf_frame_type ) - { - case RF_NO_DATA: - *rf_target_bits = 5; - move16(); - BREAK; - case RF_TCXFD: - *rf_target_bits = 27; - move16(); - BREAK; - case RF_TCXTD1: - *rf_target_bits = 16; - move16(); - BREAK; - case RF_TCXTD2: - *rf_target_bits = 16; - move16(); - BREAK; - case RF_ALLPRED: - /* Es_pred bits 3 bits, LTF: 1, pitch: 8,5,5,5, FCB: 0, gain: 7,0,7,0, Diff GFr: 4*/ - *rf_target_bits = 63; - move16(); - BREAK; - case RF_NOPRED: - /* Es_pred bits 3 bits, LTF: 0, pitch: 0, FCB: 7,7,7,7, gain: 6,0,6,0, Diff GFr: 2*/ - *rf_target_bits = 66; - move16(); - BREAK; - case RF_GENPRED: - /* Es_pred bits 3 bits, LTF: 1, pitch: 8,0,8,0, FCB: 6,7,5,5, gain: 5,0,5,0, Diff GFr: 0*/ - *rf_target_bits = 70; - move16(); - BREAK; - case RF_NELP: - /* gain: 19, Diff GFr: 5 */ - *rf_target_bits = 45; - move16(); - BREAK; - } -} - - -/*-------------------------------------------------------------------* - * get_NextCoderType_fx() - * - * Extract the coder type of next frame - *-------------------------------------------------------------------*/ - -void get_NextCoderType_fx( - UWord8 *bitsteam, /* i : bitstream */ - Word16 *next_coder_type /* o : next coder type */ -) -{ - Word16 k; - Word16 start_idx; - Word16 nBits_tmp; - Word8 bit_stream[ACELP_13k20 / 50]; - UWord16 tmp; - - - FOR( k = 0; k < ACELP_13k20 / 50; k++ ) - { - bit_stream[k] = (UWord8) s_and( shr( bitsteam[k / 8], sub( 7, s_and( k, 7 ) ) ), 0x1 ); - move16(); - } - start_idx = 0; - move16(); - WHILE( acelp_sig_tbl[start_idx] != ACELP_13k20 ) - { - start_idx = add( start_idx, 1 ); - assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); - } - - /* skip the bitrate */ - start_idx = add( start_idx, 1 ); - - tmp = 0; - move16(); - nBits_tmp = extract_l( acelp_sig_tbl[start_idx++] ); - move16(); - FOR( k = 0; k < nBits_tmp; k++ ) - { - tmp = lshl( tmp, 1 ); - tmp = add( tmp, bit_stream[k] ); - } - /* retrieve the signalling indice */ - *next_coder_type = s_and( extract_l( acelp_sig_tbl[start_idx + tmp] ), 0x7 ); - move16(); -} - -/*-------------------------------------------------------------------* - * get_indice_preview() - * - * Indices preview to parse for the presence of partial copy - *-------------------------------------------------------------------*/ -static UWord16 get_indice_preview( - UWord8 *bitstream, - Word16 bitstreamSize, - Word16 pos, - Word16 nb_bits ) -{ - UWord16 value; - Word16 i; - UWord16 bitstreamShort[MAX_BITS_PER_FRAME + 16]; - UWord16 *bitstreamShortPtr; - - /* convert bitstream from compact bytes to short values */ - bitstreamShortPtr = bitstreamShort; - FOR( i = 0; i < bitstreamSize; i++ ) - { - *bitstreamShortPtr++ = s_and( shr( bitstream[i / 8], sub( 7, ( s_and( i, 7 ) ) ) ), 0x1 ); - move16(); - } - - assert( nb_bits <= 16 ); - value = 0; - move16(); - FOR( i = 0; i < nb_bits; i++ ) - { - value = shl( value, 1 ); - value = add( value, bitstreamShort[pos + i] ); - } - return value; -} - -/*-------------------------------------------------------------------* - * evs_dec_previewFrame() - * - * Signalling index preview - *-------------------------------------------------------------------*/ -void evs_dec_previewFrame( - UWord8 *bitstream, - Word16 bitstreamSize, - Word16 *partialCopyFrameType, - Word16 *partialCopyOffset ) -{ - Word32 total_brate; - Word16 start_idx, nBits; - Word32 ind; - Word16 rf_flag; - - rf_flag = 0; - move16(); - *partialCopyFrameType = 0; - move16(); - *partialCopyOffset = 0; - move16(); - total_brate = L_mult0( bitstreamSize, 50 ); - - IF( EQ_32( total_brate, ACELP_13k20 ) ) - { - /* find the section in the ACELP signalling table corresponding to bitrate */ - start_idx = 0; - move16(); - WHILE( acelp_sig_tbl[start_idx] != total_brate ) - { - start_idx = add( start_idx, 1 ); - assert( ( start_idx < MAX_ACELP_SIG ) && "ERROR: start_idx larger than acelp_sig_tbl[].\n" ); - } - - /* skip the bitrate */ - start_idx = add( start_idx, 1 ); - /* retrieve the number of bits */ - nBits = extract_l( acelp_sig_tbl[start_idx++] ); - - /* retrieve the signalling indice */ - ind = acelp_sig_tbl[( start_idx + get_indice_preview( bitstream, bitstreamSize, 0, nBits ) )]; - move32(); - - /* convert signalling indice into RF flag. */ - rf_flag = s_and( extract_l( L_shr( ind, 7 ) ), 0x1 ); - assert( rf_flag == ( ( ind >> 7 ) & 0x1 ) ); - IF( rf_flag != 0 ) - { - /* read the fec offset at which the partial copy is received */ - ind = get_indice_preview( bitstream, bitstreamSize, sub( bitstreamSize, 5 ), 2 ); - IF( ind == 0 ) *partialCopyOffset = 2; - ELSE IF( EQ_32( ind, 1 ) ) *partialCopyOffset = 3; - ELSE IF( EQ_32( ind, 2 ) ) *partialCopyOffset = 5; - ELSE IF( EQ_32( ind, 3 ) ) *partialCopyOffset = 7; - move16(); - /* the last three bits in a packet is the RF frame type */ - *partialCopyFrameType = get_indice_preview( bitstream, bitstreamSize, bitstreamSize - 3, 3 ); - move16(); - } - } -} - -void dtx_read_padding_bits_fx( - DEC_CORE_HANDLE st, - const Word16 num_bits ) -{ - /* TODO: temporary hack, need to decide what to do with core-coder bitrate */ - Word32 tmp; - - tmp = st->total_brate; - move32(); - st->total_brate = L_add( st->total_brate, L_mult0( num_bits, FRAMES_PER_SEC ) ); - move32(); - get_next_indice_fx( st, num_bits ); - st->total_brate = tmp; - move32(); - - return; -} diff --git a/lib_com/ivas_arith_fx.c b/lib_com/ivas_arith_fx.c index 311bccff8..c708976da 100644 --- a/lib_com/ivas_arith_fx.c +++ b/lib_com/ivas_arith_fx.c @@ -191,7 +191,7 @@ void ivas_ari_done_decoding_14bits_ext_1_lfe( Decoder_State *st, const Word16 extra_bits_read ) { - get_next_indice_tmp( st, negate( sub( cbitsnew - 2, extra_bits_read ) ) ); + get_next_indice_tmp_fx( st, negate( sub( cbitsnew - 2, extra_bits_read ) ) ); return; } diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index fbeff95b8..9b69c7059 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1248,11 +1248,6 @@ UWord16 get_next_indice_fx( Word16 nb_bits /* i : number of bits that were used to quantize the indice */ ); -Word16 rate2EVSmode( - const Word32 brate, /* i : bitrate */ - Word16 *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ -); - /* o : value of the indice */ UWord16 get_next_indice_1_fx( Decoder_State *st_fx /* i/o: decoder state structure */ @@ -1274,11 +1269,23 @@ void reset_indices_enc_fx( const Word16 max_num_indices /* i : max number of indices */ ); -Word16 BRATE2IDX_fx( Word32 brate ); -Word16 BRATE2IDX16k_fx( Word32 brate ); +Word16 BRATE2IDX_fx( + const Word32 brate ); + +Word16 BRATE2IDX16k_fx( + Word32 brate ); -Word32 BIT_ALLOC_IDX_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc ); -Word32 BIT_ALLOC_IDX_16KHZ_fx( Word32 brate, Word16 ctype, Word16 sfrm, Word16 tc ); +Word32 BIT_ALLOC_IDX_fx( + const Word32 brate, + Word16 ctype, + const Word16 sfrm, + const Word16 tc ); + +Word32 BIT_ALLOC_IDX_16KHZ_fx( + const Word32 brate, + const Word16 ctype, + const Word16 sfrm, + const Word16 tc ); void getPartialCopyInfo( Decoder_State *st, /* i : decoder state structure */ @@ -10420,6 +10427,7 @@ Word32 sum2_32_fx( const Word32 *vec, /* i : input vector */ const Word16 lvec, /* i : length of input vector */ Word16 *e ); + void ProcessStereoIGF_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, Encoder_State *sts[CPE_CHANNELS], /* i : Encoder state */ @@ -10437,6 +10445,7 @@ void ProcessStereoIGF_fx( const Word16 sp_aud_decision0, /* i : sp_aud_decision0 */ const Word32 element_brate, /* i : element bitrate */ const Word16 mct_on ); + /*igf_enc.c*/ void IGFEncApplyStereo_fx( STEREO_MDCT_ENC_DATA_HANDLE hStereoMdct, /* i/o: MDCT stereo encoder structure */ @@ -10460,6 +10469,7 @@ void IGFSaveSpectrumForITF_ivas_fx( const Word16 igfGridIdx, /* i : IGF grid index */ const Word32 *pITFSpectrum, /* i : MDCT spectrum */ Word16 exp_pITFSpectrum ); + Word16 IGFEncWriteBitstream_ivas_fx( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -10467,6 +10477,7 @@ Word16 IGFEncWriteBitstream_ivas_fx( const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ const Word16 isIndepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); + /*igf_scf_enc.c*/ Word16 IGFSCFEncoderEncode_ivas_fx( IGFSCFENC_INSTANCE_HANDLE hPublicData, /* i/o: handle to public data or NULL in case there was no instance created */ @@ -10476,6 +10487,7 @@ Word16 IGFSCFEncoderEncode_ivas_fx( const Word16 igfGridIdx, /* i : igf grid index see declaration of IGF_GRID_IDX for details */ const Word16 indepFlag /* i : if 1 frame is independent, 0 = frame is coded with data from previous frame */ ); + /*ari_enc.c*/ Word16 ari_encode_14bits_ext_ivas_fx( Word16 *ptr, /* Q0 */ @@ -10484,6 +10496,7 @@ Word16 ari_encode_14bits_ext_ivas_fx( Word32 symbol, /* Q0 */ UWord16 const *cum_freq /* Q0 */ ); + Word16 ari_encode_14bits_sign_ivas_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ @@ -10491,22 +10504,18 @@ Word16 ari_encode_14bits_sign_ivas_fx( Tastat *s, Word16 sign /* Q0 */ ); + Word16 ari_done_encoding_14bits_ivas_fx( Word16 *ptr, /* Q0 */ Word16 bp, /* Q0 */ Tastat *s ); -void pack_bit( - const Word16 bit, /* i: bit to be packed */ - UWord8 **pt, /* i/o: pointer to octet array into which bit will be placed */ - UWord8 *omask /* i/o: output mask to indicate where in the octet the bit is to be written */ -); + void IGFEncConcatenateBitstream( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* i : instance handle of IGF Encoder */ const Word16 bsBits, /* i : number of IGF bits written to list of indices */ BSTR_ENC_HANDLE hBstr /* i/o: bitstream handle */ ); - void hq_generic_hf_encoding_fx( const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original */ Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope */ @@ -10514,6 +10523,7 @@ void hq_generic_hf_encoding_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 *hq_generic_exc_clas, /* o : bwe excitation class */ Word16 length ); + Word16 ari_decode_14bits_pow_ivas( Word16 *ptr, Word16 bp, @@ -10981,18 +10991,7 @@ UWord16 delete_indice( ); /*! r: value of the indice */ -UWord16 get_next_indice( - Decoder_State *st, /* i/o: decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ -); - -void get_next_indice_tmp( - Decoder_State *st, /* o : decoder state structure */ - Word16 nb_bits /* i : number of bits that were used to quantize the indice */ -); - -/*! r: value of the indice */ -UWord16 get_indice( +UWord16 get_indice_fx( Decoder_State *st, /* i/o: decoder state structure */ Word16 pos, /* i : absolute position in the bitstream */ Word16 nb_bits /* i : number of bits that were used to quantize the indice */ @@ -11002,12 +11001,11 @@ void reset_indices_dec( Decoder_State *st /* i/o: decoder state structure */ ); -Word16 rate2EVSmode_float( +Word16 rate2EVSmode( const Word32 brate, /* i : bitrate */ Word16 *is_amr_wb /* o : (flag) does the bitrate belong to AMR-WB? Can be NULL */ ); - /*! r: 1 = OK, 0 = something wrong */ ivas_error read_indices_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ @@ -11018,7 +11016,6 @@ ivas_error read_indices_fx( Word16 bfi /* i : bad frame indicator */ ); - void ivas_set_bitstream_pointers( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index 2bd38153a..595e750f4 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -864,7 +864,7 @@ Word16 FEC_pos_dec_fx( bit_pos_pitch_index = add( bit_pos_pitch_index, 1 ); } /* retrieve the pitch index */ - pitch_index = (Word16) get_indice( st_fx, bit_pos_pitch_index, nBits ); + pitch_index = (Word16) get_indice_fx( st_fx, bit_pos_pitch_index, nBits ); /* decode pitch period */ T0_min = PIT_MIN; diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 96ae82dde..d5a3cf71a 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -463,7 +463,7 @@ ivas_error amr_wb_dec_fx( * Extracts VAD information from the bitstream in AMR-WB IO mode *------------------------------------------------------------*/ - vad_flag = (Word16) get_next_indice( st_fx, 1 ); + vad_flag = (Word16) get_next_indice_fx( st_fx, 1 ); move16(); st_fx->coder_type = GENERIC; diff --git a/lib_dec/dec_acelp_tcx_main_fx.c b/lib_dec/dec_acelp_tcx_main_fx.c index eea558914..3ff221588 100644 --- a/lib_dec/dec_acelp_tcx_main_fx.c +++ b/lib_dec/dec_acelp_tcx_main_fx.c @@ -61,7 +61,7 @@ static void decode_frame_type_fx( Decoder_State *st ) /* SID frame */ ELSE IF( EQ_32( st->total_brate, SID_2k40 ) ) { - st->cng_type = get_next_indice( st, 1 ); + st->cng_type = get_next_indice_fx( st, 1 ); move16(); if ( NE_16( st->cng_type, FD_CNG ) ) { @@ -72,10 +72,10 @@ static void decode_frame_type_fx( Decoder_State *st ) move16(); frame_size_index = 1; move16(); - st->bwidth = get_next_indice( st, 2 ); + st->bwidth = get_next_indice_fx( st, 2 ); move16(); - frame_len_indicator = get_next_indice( st, 1 ); + frame_len_indicator = get_next_indice_fx( st, 1 ); IF( EQ_16( st->bwidth, NB ) ) { if ( frame_len_indicator ) @@ -146,7 +146,7 @@ static void decode_frame_type_fx( Decoder_State *st ) { /* Get bandwidth mode */ - st->bwidth = get_next_indice( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); + st->bwidth = get_next_indice_fx( st, FrameSizeConfig[frame_size_index].bandwidth_bits ); move16(); st->bwidth = add( st->bwidth, FrameSizeConfig[frame_size_index].bandwidth_min ); @@ -180,7 +180,7 @@ static void decode_frame_type_fx( Decoder_State *st ) IF( FrameSizeConfig[frame_size_index].reserved_bits && st->rf_flag == 0 ) { Word16 dummyBit; - dummyBit = (Word8) get_next_indice( st, 1 ); + dummyBit = (Word8) get_next_indice_fx( st, 1 ); move16(); if ( dummyBit != 0 ) { diff --git a/lib_dec/dec_amr_wb_fx.c b/lib_dec/dec_amr_wb_fx.c index 500fe34ba..c5b08a784 100644 --- a/lib_dec/dec_amr_wb_fx.c +++ b/lib_dec/dec_amr_wb_fx.c @@ -127,7 +127,7 @@ void decod_amr_wb_fx( IF( EQ_32( st_fx->core_brate, ACELP_23k85 ) ) { - hf_gain_fx[i_subfr / 64] = (Word16) get_next_indice( st_fx, 4 ); + hf_gain_fx[i_subfr / 64] = (Word16) get_next_indice_fx( st_fx, 4 ); move16(); } diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index c8dac0a0b..4bbe3c5bc 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -105,7 +105,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits test(); IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_FRAME48k ) ) && LE_32( core_brate, max_brate ) ) { - *hqswb_clas = get_next_indice( st_fx, 2 ); /* Q0 */ + *hqswb_clas = get_next_indice_fx( st_fx, 2 ); /* Q0 */ move16(); bits = 2; move16(); @@ -119,7 +119,7 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits } ELSE { - *hqswb_clas = get_next_indice( st_fx, 1 ); /* Q0 */ + *hqswb_clas = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); bits = 1; move16(); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 0161cbac0..3e7660332 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -103,7 +103,7 @@ void hq_core_dec_fx( test(); IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) { - hHQ_core->HqVoicing = get_next_indice( st_fx, 1 ); /* Q0 */ + hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); /* Q0 */ move16(); num_bits = sub( num_bits, 1 ); /* Q0 */ } diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 6423015bc..27b352cd3 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -477,7 +477,7 @@ void hq_hr_dec_fx( test(); IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) { - nf_idx = get_next_indice( st_fx, 2 ); /* Q0 */ + nf_idx = get_next_indice_fx( st_fx, 2 ); /* Q0 */ } /*------------------------------------------------------------------* diff --git a/lib_dec/range_dec_fx.c b/lib_dec/range_dec_fx.c index 7f62e0dd3..e63435f5b 100644 --- a/lib_dec/range_dec_fx.c +++ b/lib_dec/range_dec_fx.c @@ -147,16 +147,16 @@ Word32 rc_dec_bits_fx( /* i : Decoded value */ { hPVQ->rc_offset = sub( hPVQ->rc_offset, sub( bits, 16 ) ); move16(); - value = UL_lshl( UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, sub( bits, 16 ) ) ), 16 ); + value = UL_lshl( UL_deposit_l( get_indice_fx( st_fx, hPVQ->rc_offset, sub( bits, 16 ) ) ), 16 ); hPVQ->rc_offset = sub( hPVQ->rc_offset, 16 ); move16(); - value = UL_or( value, UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, 16 ) ) ); + value = UL_or( value, UL_deposit_l( get_indice_fx( st_fx, hPVQ->rc_offset, 16 ) ) ); } ELSE { hPVQ->rc_offset = sub( hPVQ->rc_offset, bits ); move16(); - value = UL_deposit_l( get_indice( st_fx, hPVQ->rc_offset, bits ) ); + value = UL_deposit_l( get_indice_fx( st_fx, hPVQ->rc_offset, bits ) ); } return value; diff --git a/lib_enc/igf_enc.c b/lib_enc/igf_enc.c index 0a01dfe66..ee4f43996 100644 --- a/lib_enc/igf_enc.c +++ b/lib_enc/igf_enc.c @@ -2360,11 +2360,6 @@ void IGFEncSetMode_ivas_fx( return; } -/*-------------------------------------------------------------------* - * pack_bit_ivas() - * - * insert a bit into packed octet - *-------------------------------------------------------------------*/ /*-------------------------------------------------------------------* * IGFEncConcatenateBitstream() diff --git a/lib_enc/igf_enc_fx.c b/lib_enc/igf_enc_fx.c index e0562467a..c57f5ffb0 100644 --- a/lib_enc/igf_enc_fx.c +++ b/lib_enc/igf_enc_fx.c @@ -1534,7 +1534,7 @@ void IGFEncSetMode_fx( * insert a bit into packed octet *-------------------------------------------------------------------*/ -static void pack_bit_ivas_fx( +static void pack_bit_fx( const Word16 bit, /* i : bit to be packed */ UWord8 **pt, /* i/o: pointer to octet array into which bit will be placed */ UWord8 *omask /* i/o: output mask to indicate where in the octet the bit is to be written */ @@ -1607,7 +1607,7 @@ void IGFEncConcatenateBitstream_ivas_fx( const IGF_ENC_INSTANCE_HANDLE hIGFEnc, /* write bit by bit */ FOR( k = 0; k < ind_list[i].nb_bits; k++ ) { - pack_bit_ivas_fx( extract_l( L_and( ind_list[i].value, imask ) ), &pFrame, &omask ); + pack_bit_fx( extract_l( L_and( ind_list[i].value, imask ) ), &pFrame, &omask ); imask = L_shr( imask, 1 ); } nb_bits_written = add( nb_bits_written, ind_list[i].nb_bits ); diff --git a/lib_util/mime_io.c b/lib_util/mime_io.c index 2976e1895..03ff3bbb7 100644 --- a/lib_util/mime_io.c +++ b/lib_util/mime_io.c @@ -201,8 +201,8 @@ MIME_ERROR MIME_WriteFrame( { int16_t mode; int16_t cmi; - mode = rate2EVSmode_float( numBits * FRAMES_PER_SEC, &isAmrWb ); - cmi = rate2EVSmode_float( totalBrate, &isAmrWb ); + mode = rate2EVSmode( numBits * FRAMES_PER_SEC, &isAmrWb ); + cmi = rate2EVSmode( totalBrate, &isAmrWb ); ToC = (uint8_t) ( isAmrWb << 5 | isAmrWb << 4 | mode ); writeByte( hMIME->file, ToC ); -- GitLab From e86e0e95614e8e7cb5fa380edf8bd86c4edcc8f9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Sat, 9 Aug 2025 17:59:52 +0200 Subject: [PATCH 2/2] bitstream.c -> bitstream_fx.c --- Workspace_msvc/lib_com.vcxproj | 1 - Workspace_msvc/lib_com.vcxproj.filters | 847 ++++++------------------ lib_com/{bitstream.c => bitstream_fx.c} | 0 3 files changed, 209 insertions(+), 639 deletions(-) rename lib_com/{bitstream.c => bitstream_fx.c} (100%) diff --git a/Workspace_msvc/lib_com.vcxproj b/Workspace_msvc/lib_com.vcxproj index 8e37844b9..6c57d3170 100644 --- a/Workspace_msvc/lib_com.vcxproj +++ b/Workspace_msvc/lib_com.vcxproj @@ -132,7 +132,6 @@ - diff --git a/Workspace_msvc/lib_com.vcxproj.filters b/Workspace_msvc/lib_com.vcxproj.filters index f247d199e..4996023dc 100644 --- a/Workspace_msvc/lib_com.vcxproj.filters +++ b/Workspace_msvc/lib_com.vcxproj.filters @@ -1,646 +1,217 @@ - + - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_evs_c - - - common_all_c - - - common_evs_c - - - common_evs_c - - - common_evs_c - - - common_evs_c - - - common_evs_c - - - common_evs_c - - - common_evs_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_ivas_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_ivas_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_all_c - - - common_ivas_c - - - - common_ivas_c - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - - common_h - + + + + + - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - common_h - - - - - {890c2f45-9385-4fce-859b-6a65469e8dc0} - - - {201ea764-9626-4dca-9cc4-5b4106f8b8b2} - - - {fbb860e2-79d0-45b1-ada1-c3a0a369ce2c} - - - {b95b7bed-a666-4a00-9332-2b528638503e} - + \ No newline at end of file diff --git a/lib_com/bitstream.c b/lib_com/bitstream_fx.c similarity index 100% rename from lib_com/bitstream.c rename to lib_com/bitstream_fx.c -- GitLab