From b6ef6a1385ef4d4c99abd6c3cdce7aeb46f6987e Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Tue, 16 Jan 2024 21:02:03 +0530 Subject: [PATCH] Added BASOPs changes in ivas_stereo_adapt_GR_dec --- lib_com/ivas_prot.h | 4 + lib_com/ivas_prot_fx.h | 88 ++++- lib_dec/ivas_stereo_adapt_GR_dec.c | 463 ++++++++++++++++++++++++++ lib_dec/ivas_stereo_cng_dec.c | 3 + lib_dec/ivas_stereo_mdct_stereo_dec.c | 3 + 5 files changed, 543 insertions(+), 18 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index c276eeda9..bc9f951e2 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -1605,6 +1605,7 @@ int16_t write_bitstream_GR( const int16_t GR_ord /* i : GR order to be used */ ); +#ifndef IVAS_FLOAT_FIXED /*! r: number of bits read */ int16_t read_flag_EC_DFT( const uint16_t *bit_stream, /* i : bitstream */ @@ -1651,6 +1652,7 @@ int16_t read_BS_adapt_GR_sg( int16_t *GR_ord, /* o : GR order to be used */ const int16_t *map0 /* i : mapping array for side gains */ ); +#endif void stereo_dft_hybrid_ITD_flag( STEREO_DFT_CONFIG_DATA_HANDLE hConfig, /* o : DFT stereo configuration */ @@ -3016,12 +3018,14 @@ int16_t write_GR0( const int16_t len /* i : input data length */ ); +#ifndef IVAS_FLOAT_FIXED /*! r: number of bits read */ int16_t read_GR0( const uint16_t *bit_stream, /* i : bitstream to be read */ int16_t *ind, /* o : parameters read */ const int16_t len /* i : number of params to be read */ ); +#endif /*----------------------------------------------------------------------------------* diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index dffe0656c..8c9eb3c7c 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -54,14 +54,12 @@ void ivas_dct_windowing_fx( const Word16 frame_len, Word32 *pOut_buf, Word32 *pBuffer_prev, - Word32 *pTemp_lfe -); + Word32 *pTemp_lfe ); void ivas_get_twid_factors_fx1( const Word16 length, const Word16 **pTwid_re, - const Word16 **pTwid_im -); + const Word16 **pTwid_im ); Word32 ivas_get_mdct_scaling_gain_fx( const Word16 dct_len_by_2 ); @@ -70,25 +68,23 @@ void ivas_imdct_fx( const Word32 *pIn, Word32 *pOut, const Word16 length, - Word16 *q_out -); + Word16 *q_out ); void ivas_mdct_fx( const Word32 *pIn, Word32 *pOut, const Word16 length, - Word16 *q_out -); + Word16 *q_out ); void ivas_itda_fx( - const Word32 *re, /* i : time alised signal after IDCT */ - Word32 *pOut, /* o : time domain buffer of size 2*length */ + const Word32 *re, /* i : time alised signal after IDCT */ + Word32 *pOut, /* o : time domain buffer of size 2*length */ const Word16 length /* i : length of time alised signal buffer */ ); void ivas_tda_fx( - const Word32 *pIn, /* i : time domain buffer of size 2*length */ - Word32 *pOut, /* o : time domain buffer of size length */ + const Word32 *pIn, /* i : time domain buffer of size 2*length */ + Word32 *pOut, /* o : time domain buffer of size length */ const Word16 length /* i : length of time alised signal buffer */ ); @@ -246,14 +242,13 @@ void stereo_dft_dec_analyze_fx( const Word16 k_offset, /* i : offset of DFT */ const Word16 delay, /* i : delay in samples for input signal */ Word16 *q, - Word16 *q_out_DFT -); + Word16 *q_out_DFT ); void filter_with_allpass_fx( - const Word32 *sig, /* i : allpass input signal */ - Word32 *out, /* o : filtered output */ - const int16_t len, /* i : length of input */ - basic_allpass_t *ap /* i/o: basic allpass structure */ + const Word32 *sig, /* i : allpass input signal */ + Word32 *out, /* o : filtered output */ + const int16_t len, /* i : length of input */ + basic_allpass_t *ap /* i/o: basic allpass structure */ ); void stereo_dft_dec_core_switching_fx( @@ -315,4 +310,61 @@ void ivas_jbm_dec_get_adapted_subframes_fx( Word16 *subframe_nbslots, /* i/o: subframe grid */ Word16 *nb_subframes /* i/o: number of subframes in the frame */ ); + +#ifdef IVAS_FLOAT_FIXED +/*! r: number of bits read */ +Word16 read_GR0( + const UWord16 *bit_stream, /* i : bitstream to be read */ + Word16 *ind, /* o : parameters read */ + const Word16 len /* i : number of params to be read */ +); + +/*! r: read value */ +Word16 get_value( + const UWord16 *bit_stream, /* i : bitstream */ + const Word16 nbits /* i : number of bits to be read */ +); + +/*! r: number of bits read */ +Word16 read_BS_GR( + const UWord16 *bit_stream, /* i : bitstream to be read */ + const Word16 nb, /* i : starting point in bitstream */ + Word16 *ind1, /* o : data array read */ + const Word16 len, /* i : number of params to be read */ + Word16 *GR_ord /* o : GR order to be used */ +); + +/*! r: number of bits read */ +Word16 read_BS_adapt_GR_sg( + const UWord16 *bit_stream, /* i : bitstream to be read */ + const Word16 nb, /* i : starting position in bitstream */ + Word16 *ind1, /* o : decoded side gain values */ + const Word16 len, /* i : number of params to be read */ + Word16 *GR_ord, /* o : GR order used (read from bitstream)*/ + const Word16 *map0 /* i : initial map */ +); + +/*! r: number of bits read */ +Word16 read_itd( + Decoder_State *st, /* i : Decoder state */ + Word16 *pI /* o : ITD value */ +); + +/*! r: number of bits read */ +Word16 read_BS_adapt_GR_rpg( + const UWord16 *bit_stream, /* i : bitstream to be read */ + const Word16 nb, /* i : starting point in bitstream */ + Word16 *ind1_pred, /* o : decoded res pred gains */ + const Word16 start, /* i : starting subband */ + const Word16 total_no, /* i : number of params to be read */ + Word16 *GR_ord /* o : GR order - read */ +); + +/*! r: number of bits read */ +Word16 read_flag_EC_DFT( + const UWord16 *bit_stream, /* i : bitstream */ + Word16 *flag /* o : flag value */ +); +#endif + #endif \ No newline at end of file diff --git a/lib_dec/ivas_stereo_adapt_GR_dec.c b/lib_dec/ivas_stereo_adapt_GR_dec.c index 81a3131f8..78ee1282c 100644 --- a/lib_dec/ivas_stereo_adapt_GR_dec.c +++ b/lib_dec/ivas_stereo_adapt_GR_dec.c @@ -37,8 +37,469 @@ #include "ivas_prot.h" #include "ivas_rom_com.h" #include "rom_dec.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif + +#ifdef IVAS_FLOAT_FIXED +/*---------------------------------------------------------------------* + * read_GR2() + * + * reading a bitstream of data encoded with GR of order 2 + *---------------------------------------------------------------------*/ + +/*! r: number of bits read */ +static Word16 read_GR2( + const UWord16 *bit_stream, /* i : bitstream to be read */ + Word16 *ind, /* o : parameters read */ + const Word16 len /* i : number of params to be read */ +) +{ + Word16 i; + UWord16 nb, ready, temp, b; + const UWord16 *p; + + p = bit_stream; + nb = 0; + + FOR( i = 0; i < len; i++ ) + { + ready = 0; + temp = 0; + DO + { + b = *p++; + IF( EQ_16( (Word16) b, 0 ) ) + { + ready = 1; + } + ELSE + { + temp = add( (Word16) temp, 1 ); + } + } + WHILE( EQ_16( (Word16) ready, 0 ) ); + b = *p++; + b = (UWord16) add( shl( (Word16) b, 1 ), (Word16) *p++ ); + ind[i] = add( shl( (Word16) temp, 2 ), (Word16) b ); + nb = (UWord16) add( (Word16) nb, add( (Word16) temp, 3 ) ); + } + + return nb; +} + + +/*---------------------------------------------------------------------* + * read_GR1() + * + * reading a bitstream of data encoded with GR of order 1 + *---------------------------------------------------------------------*/ + +/*! r: number of bits read */ +static Word16 read_GR1( + const UWord16 *bit_stream, /* i : bitstream to be read */ + Word16 *ind, /* o : parameters read */ + const Word16 len /* i : number of params to be read */ +) +{ + Word16 i; + UWord16 nb, ready, temp, b; + const UWord16 *p; + + p = bit_stream; + nb = 0; + + FOR( i = 0; i < len; i++ ) + { + ready = 0; + temp = 0; + DO + { + b = *p++; + IF( EQ_16( (Word16) b, 0 ) ) + { + ready = 1; + } + ELSE + { + temp = add( (Word16) temp, 1 ); + } + } + WHILE( EQ_16( (Word16) ready, 0 ) ); + + b = *p++; + ind[i] = add( shl( (Word16) temp, 1 ), (Word16) b ); + nb = (UWord16) add( (Word16) nb, add( (Word16) temp, 2 ) ); + } + + return nb; +} + + +/*---------------------------------------------------------------------* + * read_GR0() + * + * reading a bitstream of data encoded with GR of order 0 + *---------------------------------------------------------------------*/ + +/*! r: number of bits read */ +Word16 read_GR0( + const UWord16 *bit_stream, /* i : bitstream to be read */ + Word16 *ind, /* o : parameters read */ + const Word16 len /* i : number of params to be read */ +) +{ + Word16 i; + UWord16 nb, ready, b, temp; + const UWord16 *p; + + p = bit_stream; + nb = 0; + + FOR( i = 0; i < len; i++ ) + { + ready = 0; + temp = 0; + DO + { + b = *p++; + IF( EQ_16( (Word16) b, 0 ) ) + { + ready = 1; + } + ELSE + { + temp = add( (Word16) temp, 1 ); + } + } + WHILE( EQ_16( (Word16) ready, 0 ) ); + ind[i] = temp; + nb = (UWord16) add( (Word16) nb, add( (Word16) temp, 1 ) ); + } + + return nb; +} + + +/*---------------------------------------------------------------------* + * find_map() + * + * find the position of the value 'val' in the array 'map' + *---------------------------------------------------------------------*/ + +/*! r: index in array */ +static ivas_error find_map( + Word16 *map_idx, + const Word16 *map, /* i : array to look into */ + const Word16 val, /* i : value to look for */ + const Word16 len /* i : length of array */ +) +{ + *map_idx = 0; + + WHILE( ( NE_16( map[*map_idx], val ) ) && ( NE_16( *map_idx, len ) ) ) + { + ( *map_idx )++; + } + + + return IVAS_ERR_OK; +} + + +/*---------------------------------------------------------------------* + * decode_adapt_GR_indices1() + * + * decodes input array using the adaptive GR procedure + *---------------------------------------------------------------------*/ + +static void decode_adapt_GR_indices1( + const Word16 *ind, /* i : array of input encoded symbols */ + const Word16 len, /* i : number of parameters to decode */ + const Word16 no_symb, /* i : number of possible symbols in GR coding */ + Word16 *out, /* o : array of decoded parameters */ + const Word16 *map0 /* i : initial mapping array for the adaptive GR */ +) +{ + const Word16 *map; + Word16 map_symb, i; + + IF( EQ_16( no_symb, NO_SYMB_GR_SIDE_G ) ) + { + map = &map0[15 * no_symb]; + } + ELSE + { + map = &( map0[8 * no_symb] ); + } + + FOR( i = 0; i < len; i++ ) + { + map_symb = ind[i]; + find_map( out + i, map, map_symb, no_symb ); + map = &( map0[out[i] * no_symb] ); + } + + return; +} + + +/*---------------------------------------------------------------------* + * get_value() + * + * reads a value on 'nbits' from a bitstream + *---------------------------------------------------------------------*/ + +/*! r: read value */ +Word16 get_value( + const UWord16 *bit_stream, /* i : bitstream */ + const Word16 nbits /* i : number of bits to be read */ +) +{ + Word16 i; + UWord16 mask = 0, val = 0; + + FOR( i = nbits - 1; i >= 0; i-- ) + { + val = (UWord16) add( (Word16) val, shl( bit_stream[i], mask ) ); + mask = add( mask, 1 ); + } + + return val; +} + + +/*---------------------------------------------------------------------* + * read_BS_GR() + * + * decode simple GR code from a bitstream + *---------------------------------------------------------------------*/ + +/*! r: number of bits read */ +Word16 read_BS_GR( + const UWord16 *bit_stream, /* i : bitstream to be read */ + const Word16 nb, /* i : starting point in bitstream */ + Word16 *ind1, /* o : data array read */ + const Word16 len, /* i : number of params to be read */ + Word16 *GR_ord /* o : GR order to be used */ +) +{ + Word16 b, ind1_tmp[STEREO_DFT_BAND_MAX], tmp, i; + + *GR_ord = bit_stream[nb]; + b = 1; + + IF( EQ_16( *GR_ord, 0 ) ) + { + b = add( b, read_GR0( &bit_stream[nb + b], ind1_tmp, len ) ); + } + ELSE + { + b = add( b, read_GR1( &bit_stream[nb + b], ind1_tmp, len ) ); + } + + FOR( i = 0; i < len; i++ ) + { + tmp = add( ind1_tmp[i], 1 ); + IF( tmp & 1 ) /* if odd number */ + { + ind1[i] = negate( shr( ind1_tmp[i], 1 ) ); + } + ELSE + { + ind1[i] = shr( tmp, 1 ); + } + } + + return b; +} + + +/*---------------------------------------------------------------------* + * read_BS_adapt_GR_sg() + * + * read and decode with adaptive GR the bitstream containing side gains values + *---------------------------------------------------------------------*/ + +/*! r: number of bits read */ +Word16 read_BS_adapt_GR_sg( + const UWord16 *bit_stream, /* i : bitstream to be read */ + const Word16 nb, /* i : starting position in bitstream */ + Word16 *ind1, /* o : decoded side gain values */ + const Word16 len, /* i : number of params to be read */ + Word16 *GR_ord, /* o : GR order used (read from bitstream)*/ + const Word16 *map0 /* i : initial map */ +) +{ + Word16 b, ind1_tmp[STEREO_DFT_BAND_MAX], ord; + + /* read first component */ + b = 0; + b = add( b, read_GR1( &bit_stream[nb], ind1_tmp, 1 ) ); + /* read GR ord */ + ord = bit_stream[nb + b]; + b = add( b, 1 ); + + IF( EQ_16( ord, 0 ) ) + { + *GR_ord = 1; + b = add( b, read_GR1( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) ); + } + ELSE + { + ord = bit_stream[nb + b]; + b = add( b, 1 ); + IF( EQ_16( ord, 0 ) ) + { + *GR_ord = 0; + + b = add( b, read_GR0( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) ); + } + ELSE + { + *GR_ord = 2; + b = add( b, read_GR2( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) ); + } + } + + decode_adapt_GR_indices1( ind1_tmp, len, NO_SYMB_GR_SIDE_G, ind1, map0 ); + + return b; +} + + +/*---------------------------------------------------------------------* + * read_itd() + * + * read and decode ITD in DFT mode + *---------------------------------------------------------------------*/ + +/*! r: number of bits read */ +Word16 read_itd( + Decoder_State *st, /* i : Decoder state */ + Word16 *pI /* o : ITD value */ +) +{ + Word16 huff_flag, sign_flag, I, i, nb = 0, ready; + + huff_flag = (Word16) get_next_indice( st, 1 ); + sign_flag = (Word16) get_next_indice( st, 1 ); + nb = add( nb, 2 ); + + IF( EQ_16( huff_flag, 1 ) ) + { + ready = 0; + I = 0; + + WHILE( ( EQ_16( ready, 0 ) ) && ( LT_16( nb, 10 ) ) ) + { + I = add( shl( I, 1 ), (Word16) get_next_indice( st, 1 ) ); + nb = add( nb, 1 ); + + FOR( i = 0; i < 20; i++ ) + { + IF( ( EQ_16( I, dft_code_itd[i] ) ) && ( EQ_16( dft_len_itd[i], ( sub( nb, 2 ) ) ) ) ) + { + I = i; + ready = 1; + BREAK; + } + } + } + IF( EQ_16( ready, 0 ) ) + { + printf( "Error reading Huffman code for ITD: \n" ); + } + } + ELSE + { + I = (Word16) get_next_indice( st, STEREO_DFT_ITD_NBITS - 1 ); + nb = add( nb, STEREO_DFT_ITD_NBITS - 1 ); + } + + I = add( I, shl( sign_flag, 8 ) ); + *pI = I; + + return nb; +} + + +/*---------------------------------------------------------------------* + * read_BS_adapt_GR_rpg() + * + * read and decode residual prediction gain values using adaptive GR + *---------------------------------------------------------------------*/ + +/*! r: number of bits read */ +Word16 read_BS_adapt_GR_rpg( + const UWord16 *bit_stream, /* i : bitstream to be read */ + const Word16 nb, /* i : starting point in bitstream */ + Word16 *ind1_pred, /* o : decoded res pred gains */ + const Word16 start, /* i : starting subband */ + const Word16 total_no, /* i : number of params to be read */ + Word16 *GR_ord /* o : GR order - read */ +) +{ + Word16 b, ind1_tmp[STEREO_DFT_BAND_MAX], i, len; + len = sub( total_no, start ); + + /* read first band */ + b = read_GR1( &bit_stream[nb], ind1_tmp, 1 ); + + IF( EQ_16( ind1_tmp[0], dft_maps_rpg[8 * NO_SYMB_GR_PRED_G] ) ) + { + FOR( i = start; i < total_no; i++ ) + { + ind1_pred[i] = 0; + } + } + ELSE + { + *GR_ord = bit_stream[nb + b]; /* GR order */ + b = add( b, 1 ); + IF( EQ_16( *GR_ord, 0 ) ) + { + b = add( b, read_GR0( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) ); + } + ELSE + { + /* GR ord 1 */ + b = add( b, read_GR1( &bit_stream[nb + b], &ind1_tmp[1], len - 1 ) ); + } + decode_adapt_GR_indices1( ind1_tmp, total_no - start, NO_SYMB_GR_PRED_G, &ind1_pred[start], dft_maps_rpg ); + } + + return b; +} +/*---------------------------------------------------------------------* + * read_flag_EC_DFT() + * + * read flag differentiating between: CBR/EC with adaptive GR/GR for differential coding + *---------------------------------------------------------------------*/ + +/*! r: number of bits read */ +Word16 read_flag_EC_DFT( + const UWord16 *bit_stream, /* i : bitstream */ + Word16 *flag /* o : flag value */ +) +{ + Word16 flg; + + flg = bit_stream[0]; + IF( EQ_16( flg, 0 ) ) + { + *flag = flg; + return 1; + } + ELSE + { + *flag = add( 2, bit_stream[1] ); + return 2; + } +} +#else /*---------------------------------------------------------------------* * read_GR2() * @@ -494,3 +955,5 @@ int16_t read_flag_EC_DFT( return 2; } } + +#endif \ No newline at end of file diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 1d6177b94..64a163907 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -39,6 +39,9 @@ #include "ivas_cnst.h" #include "ivas_rom_com.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif // IVAS_FLOAT_FIXED /*------------------------------------------------------------------- * Local constants diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index 1479aab89..0bd589273 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -38,6 +38,9 @@ #include "ivas_prot.h" #include "prot.h" #include "wmc_auto.h" +#ifdef IVAS_FLOAT_FIXED +#include "ivas_prot_fx.h" +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* -- GitLab