From dc0147992d263972ef47907f244d17ba9dd0cef4 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Thu, 1 Feb 2024 12:06:57 +0530 Subject: [PATCH] Few functions in ivas_masa_dec converted to fixed point --- lib_com/ivas_cnst.h | 3 + lib_com/ivas_masa_com.c | 144 +++++++ lib_com/ivas_omasa_com.c | 4 +- lib_com/ivas_prot.h | 3 +- lib_com/ivas_prot_fx.h | 19 + lib_com/prot_fx2.h | 4 +- lib_dec/ivas_masa_dec.c | 775 +++++++++++++++++++++++++++++++++-- lib_dec/ivas_omasa_dec.c | 4 + lib_dec/ivas_qmetadata_dec.c | 8 +- lib_dec/ivas_stat_dec.h | 9 +- 10 files changed, 937 insertions(+), 36 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 6a70a92e6..e130f0869 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -349,6 +349,8 @@ typedef enum #define PARAM_ISM_MAX_CHAN 16 #define PARAM_ISM_HYS_BUF_SIZE 10 +#define STEP_PARAM_ISM_POW_RATIO_NBITS_Q15 (4681) /* 1.0f / (float)((1 << PARAM_ISM_POW_RATIO_NBITS) - 1) */ + /* ISM DTX */ #define ISM_DTX_COH_SCA_BITS 4 #define ISM_DTX_AZI_BITS_HIGH 8 @@ -1154,6 +1156,7 @@ enum #define NO_BITS_MASA_ISM_NO_OBJ 2 #ifdef IVAS_FLOAT_FIXED #define MASA2TOTAL_THR 0.979965f // Temporary +#define MASA2TOTAL_THR_Q30 1052229376l // 0.979965f in Q30 //Maximum error in float to fixed conversion : 0.005% //Assuming the accuracy of 99.995% //New value = 99.995 / 100 * 0.98 = 0.979951 diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 976a92fc5..f4659907c 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -1423,6 +1423,56 @@ int16_t valid_ratio_index( return out; } +#ifdef IVAS_FLOAT_FIXED +Word16 valid_ratio_index_fx( + Word16 index, /* i : index to be checked */ + const Word16 K, /* i : L1 norm to check against */ + const Word16 len /* i : vector length */ +) +{ + Word16 out; + Word16 i, sum, elem; + Word16 base[4]; + + sum = 0; + move16(); + set16_fx( base, 1, len ); + + FOR ( i = 1; i < len; i++ ) + { + base[i] = i_mult(base[i - 1], 10); + } + sum = 0; + move16(); + FOR ( i = len - 1; i >= 0; i-- ) + { + IF(EQ_16(index, 0)) + { + elem = 0; + move16(); + } + ELSE + { + elem = idiv1616(index, base[i]); + } + sum = add(sum, elem); + index = sub(index, i_mult(elem, base[i])); + } + IF ( LE_16(sum, K ) ) + { + out = 1; + move16(); + } + ELSE + { + out = 0; + move16(); + } + + return out; +} +#endif + /*--------------------------------------------------------------- * reconstruct_ism_ratios() @@ -1458,6 +1508,46 @@ void reconstruct_ism_ratios( } +/*--------------------------------------------------------------- + * reconstruct_ism_ratios_fx() + * + * Obtains ISM ratio values from the quantized indexes + *---------------------------------------------------------------*/ + +void reconstruct_ism_ratios_fx( + Word16 *ratio_ism_idx, /* i : index vector Q0 */ + const Word16 nchan_ism, /* i : number of components/objects Q0 */ + const Word16 step, /* i : quantization step Q15 */ + Word32 *q_energy_ratio_ism /* o : reconstructed ISM values Q30 */ +) +{ + int16_t i; + Word32 sum; + + sum = 0; + move32(); + + FOR ( i = 0; i < nchan_ism - 1; i++ ) + { + q_energy_ratio_ism[i] = L_shl(L_mult(ratio_ism_idx[i], step), 14); // q0 + q15 + 1 + 14 = q30; + move32(); + + sum = L_add(sum, q_energy_ratio_ism[i]); + } + + q_energy_ratio_ism[nchan_ism - 1] = L_sub(ONE_IN_Q30, sum); + move32(); + + IF ( LT_32(q_energy_ratio_ism[nchan_ism - 1], 0) ) + { + q_energy_ratio_ism[nchan_ism - 1] = 0; + move32(); + } + + return; +} + + /*--------------------------------------------------------------- * ivas_omasa_modify_masa_energy_ratios() * @@ -1534,6 +1624,60 @@ void distribute_evenly_ism( return; } +#ifdef IVAS_FLOAT_FIXED +/*--------------------------------------------------------------- + * distribute_evenly_ism_fx() + * + * Obtain ISM ratio indexes for even content distribution bbetween objects + *---------------------------------------------------------------*/ + +void distribute_evenly_ism_fx( + Word16 *idx, /* o : index values */ + const Word16 K, /* i : sum of indexes */ + const Word16 nchan_ism /* i : number of objects */ +) +{ + Word16 i; + Word16 sum; + + sum = 0; + move16(); + FOR( i = 0; i < nchan_ism; i++ ) + { + IF(EQ_16(K, 0)) + { + idx[i] = 0; + move16(); + } + ELSE + { + idx[i] = idiv1616( K, nchan_ism ); + move16(); + } + sum = add( sum, idx[i] ); + } + + assert( LE_16( sum, K ) ); + + i = 0; + move16(); + WHILE( LT_16( sum, K ) ) + { + IF( EQ_16( i, nchan_ism ) ) + { + i = 0; + move16(); + } + idx[i] = add( idx[i], 1 ); + move16(); + sum = add( sum, 1 ); + i = add( i, 1 ); + } + + return; +} +#endif + /*--------------------------------------------------------------- * calculate_cpe_brate_MASA_ISM() diff --git a/lib_com/ivas_omasa_com.c b/lib_com/ivas_omasa_com.c index e49a2c8fe..b98e6e302 100644 --- a/lib_com/ivas_omasa_com.c +++ b/lib_com/ivas_omasa_com.c @@ -903,8 +903,8 @@ static Word16 get_bits_ism( Word32 val ) void calculate_nbits_meta_fx( const Word16 nchan_ism, - Word32 q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], // Qx - Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], // Qx + const Word32 q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], // Q30 + const Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], // Q30 const Word16 numSf, const Word16 numCodingBands, Word16 *bits_ism, diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 7db57ae2a..c5b72e895 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -6037,8 +6037,7 @@ void ivas_omasa_decode_masa_to_total_fx( Word16 *index, Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], const Word16 nbands, - const Word16 nblocks, - Word16 *q); + const Word16 nblocks); #endif void ivas_omasa_modify_masa_energy_ratios( diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 480d3dd14..f16dfa1b1 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -101,6 +101,25 @@ ivas_error ivas_masa_dec_reconfigure_fx( Word16 *data /* o : output synthesis signal */ ); +void reconstruct_ism_ratios_fx( + Word16 *ratio_ism_idx, /* i : index vector Q0 */ + const Word16 nchan_ism, /* i : number of components/objects Q0 */ + const Word16 step, /* i : quantization step Q15 */ + Word32 *q_energy_ratio_ism /* o : reconstructed ISM values Q30 */ +); + +void distribute_evenly_ism_fx( + Word16 *idx, /* o : index values */ + const Word16 K, /* i : sum of indexes */ + const Word16 nchan_ism /* i : number of objects */ +); + +Word16 valid_ratio_index_fx( + Word16 index, /* i : index to be checked */ + const Word16 K, /* i : L1 norm to check against */ + const Word16 len /* i : vector length */ +); + Word16 ivas_jbm_dec_get_num_tc_channels_fx( Decoder_Struct *st_ivas /* i : IVAS decoder handle */ ); diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 5e52d1613..12abc90f8 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -8227,8 +8227,8 @@ void save_synthesis_hq_fec_fx( ); void calculate_nbits_meta_fx( const Word16 nchan_ism, - Word32 q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], // Qx - Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], // Qx + const Word32 q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], // Q30 + const Word32 masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], // Q30 const Word16 numSf, const Word16 numCodingBands, Word16 *bits_ism, diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 16564e0b5..f25a28e84 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -59,6 +59,8 @@ * Local function prototypes *-----------------------------------------------------------------------*/ +static Word16 rint_fx( Word32 num ); + static void index_16bits( IVAS_QMETADATA_HANDLE hQMetaData, SPHERICAL_GRID_DATA *Sph_Grid16 ); static void create_masa_ext_out_meta( MASA_DECODER *hMasa, IVAS_QMETADATA_HANDLE hQMetaData, const int16_t nchan_transport ); @@ -88,13 +90,24 @@ static ivas_error ivas_masa_dec_config_fx( Decoder_Struct *st_ivas ); #endif static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const int16_t nchan_ism, uint16_t *bit_stream, int16_t *next_bit_pos, const int16_t idx_separated_object, const int16_t ism_imp, const int16_t dirac_bs_md_write_idx, const int16_t dirac_md_buffer_length ); +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_decode_masaism_metadata_fx( IVAS_QMETADATA_HANDLE hQMetaData, MASA_DECODER_HANDLE hMasa, MASA_ISM_DATA_HANDLE hMasaIsmData, const Word16 nchan_ism, UWord16 *bit_stream, Word16 *next_bit_pos, const Word16 idx_separated_object, const Word16 ism_imp, const Word16 dirac_bs_md_write_idx, const Word16 dirac_md_buffer_length ); +#endif static void decode_index_slice( int16_t index, int16_t *ratio_idx_ism, const int16_t nchan_ism, const int16_t K ); +#ifdef IVAS_FLOAT_FIXED +static void decode_index_slice_fx( Word16 index, Word16 *ratio_idx_ism, const Word16 nchan_ism, const Word16 K ); +#endif static void decode_ism_ratios( uint16_t *bit_stream, int16_t *next_bit_pos, float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], float ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t nbands, const int16_t nblocks, const int16_t idx_separated_object ); +#ifdef IVAS_FLOAT_FIXED +static void decode_ism_ratios_fx( UWord16 *bit_stream, Word16 *next_bit_pos, const Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], Word32 ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const Word16 nchan_ism, const Word16 nbands, const Word16 nblocks, const Word16 idx_separated_object ); +#endif static void read_ism_ratio_index( int16_t ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const int16_t nchan_ism, const int16_t numCodingBands, const int16_t sf, int16_t ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], uint16_t *bit_stream, int16_t *next_bit_pos, float *masa_to_total_energy_ratio, const int16_t idx_sep_obj, int16_t *num_zeros ); - +#ifdef IVAS_FLOAT_FIXED +static void read_ism_ratio_index_fx( Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const Word16 nchan_ism, const Word16 numCodingBands, const Word16 sf, Word16 ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], UWord16 *bit_stream, Word16 *next_bit_pos, const Word32 *masa_to_total_energy_ratio_fx, const Word16 idx_sep_obj, Word16 *num_zeros ); +#endif /*-----------------------------------------------------------------------* * ivas_masa_decode() @@ -348,9 +361,40 @@ ivas_error ivas_masa_decode( { if ( st_ivas->hDirAC != NULL ) { - *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, +#ifdef IVAS_FLOAT_FIXED + *nb_bits_read += ivas_decode_masaism_metadata_fx( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx, st_ivas->hSpatParamRendCom->dirac_md_buffer_length ); + FOR(Word32 dir = 0; dir < MAX_PARAM_SPATIAL_SUBFRAMES; dir++) + { + FOR(Word16 sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; ++sf) + { + Word16 meta_write_index = (add(st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx, sf)) % st_ivas->hSpatParamRendCom->dirac_md_buffer_length; + FOR(Word32 b = 0; b < MASA_FREQUENCY_BANDS; ++b) + { + st_ivas->hMasaIsmData->energy_ratio_ism[dir][meta_write_index][b] = fix_to_float(st_ivas->hMasaIsmData->energy_ratio_ism_fx[dir][meta_write_index][b], Q30); + } + } + } + FOR(Word32 n = 0; n < st_ivas->nchan_ism; n++) + { + st_ivas->hMasaIsmData->q_azimuth_old_fx[n] = float_to_fix(st_ivas->hMasaIsmData->q_azimuth_old[n], Q22); + } + + //FOR(Word32 k = 0; k < (nblocks != 1 ? nblocks : MAX_PARAM_SPATIAL_SUBFRAMES); k++) + //FOR(Word32 k = 0; k < ( hQMetaData->q_direction->cfg.nblocks != 1 ? hQMetaData->q_direction->cfg.nblocks : MAX_PARAM_SPATIAL_SUBFRAMES); k++) + FOR(Word32 k = 0; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++) + { + //FOR(Word32 j = 0; j < (hQMetaData->q_direction->cfg.nbands != 1 ? hQMetaData->q_direction->cfg.nbands : MASA_FREQUENCY_BANDS); j++) + FOR(Word32 j = 0; j < MASA_FREQUENCY_BANDS; j++) + { + st_ivas->hMasaIsmData->masa_to_total_energy_ratio[k][j] = fix_to_float(st_ivas->hMasaIsmData->masa_to_total_energy_ratio_fx[k][j], Q30); + } + } +#else + *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, + st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx, st_ivas->hSpatParamRendCom->dirac_md_buffer_length ); +#endif for ( obj = 0; obj <= st_ivas->nchan_ism; obj++ ) { if ( st_ivas->hMasaIsmData->idx_separated_ism == obj ) @@ -369,8 +413,38 @@ ivas_error ivas_masa_decode( } else { +#ifdef IVAS_FLOAT_FIXED + *nb_bits_read += ivas_decode_masaism_metadata_fx( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, + st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); + FOR(Word32 dir = 0; dir < MAX_PARAM_SPATIAL_SUBFRAMES; dir++) + { + FOR(Word32 sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; ++sf) + { + FOR(Word32 b = 0; b < MASA_FREQUENCY_BANDS; ++b) + { + st_ivas->hMasaIsmData->energy_ratio_ism[dir][sf][b] = fix_to_float(st_ivas->hMasaIsmData->energy_ratio_ism_fx[dir][sf][b], Q30); + } + } + } + FOR(Word32 n = 0; n < st_ivas->nchan_ism; n++) + { + st_ivas->hMasaIsmData->q_azimuth_old_fx[n] = float_to_fix(st_ivas->hMasaIsmData->q_azimuth_old[n], Q22); + } + + //FOR(Word32 k = 0; k < (nblocks != 1 ? nblocks : MAX_PARAM_SPATIAL_SUBFRAMES); k++) + //FOR(Word32 k = 0; k < ( hQMetaData->q_direction->cfg.nblocks != 1 ? hQMetaData->q_direction->cfg.nblocks : MAX_PARAM_SPATIAL_SUBFRAMES); k++) + FOR(Word32 k = 0; k < MAX_PARAM_SPATIAL_SUBFRAMES; k++) + { + //FOR(Word32 j = 0; j < (hQMetaData->q_direction->cfg.nbands != 1 ? hQMetaData->q_direction->cfg.nbands : MASA_FREQUENCY_BANDS); j++) + FOR(Word32 j = 0; j < MASA_FREQUENCY_BANDS; j++) + { + st_ivas->hMasaIsmData->masa_to_total_energy_ratio[k][j] = fix_to_float(st_ivas->hMasaIsmData->masa_to_total_energy_ratio_fx[k][j], Q30); + } + } +#else *nb_bits_read += ivas_decode_masaism_metadata( hQMetaData, st_ivas->hMasa, st_ivas->hMasaIsmData, st_ivas->nchan_ism, st->bit_stream, &st->next_bit_pos, st_ivas->hMasaIsmData->idx_separated_ism, ism_imp, 0, MAX_PARAM_SPATIAL_SUBFRAMES ); +#endif } } } @@ -3199,6 +3273,75 @@ static void decode_index_slice( return; } +#ifdef IVAS_FLOAT_FIXED +static void decode_index_slice_fx( + Word16 index, /* i : index to decode */ + Word16 *ratio_idx_ism, /* o : decodec array of integers */ + const Word16 nchan_ism, /* i : number of elements in array (objects) */ + const Word16 K /* i : sum of array elements */ +) +{ + Word16 i, j, sum, elem; + Word16 base[MAX_NUM_OBJECTS]; + + SWITCH ( nchan_ism ) + { + case 2: + ratio_idx_ism[0] = index; + move16(); + ratio_idx_ism[1] = sub(K, ratio_idx_ism[0]); + move16(); + break; + case 3: + case 4: + { + j = 0; + move16(); + WHILE ( GE_16( index, 0) ) + { + IF ( valid_ratio_index_fx( j, K, nchan_ism - 1 ) ) + { + index = sub(index, 1); + } + j = add(j, 1); + } + j = sub(j,1); + base[0] = 1; + move16(); + FOR ( i = 1; i < nchan_ism - 1; i++ ) + { + base[i] = i_mult(base[i - 1], 10); + move16(); + } + sum = 0; + move16(); + FOR ( i = nchan_ism - 2; i >= 0; i-- ) + { + IF(EQ_16(j, 0)) + { + elem = 0; + move16(); + } + ELSE + { + elem = idiv1616(j, base[i]); + } + ratio_idx_ism[sub(sub(nchan_ism, i), 2)] = elem; + move16(); + sum = add(sum, elem); + j = sub(j, i_mult(elem, base[i])); + } + ratio_idx_ism[nchan_ism - 1] = sub(K, sum); + move16(); + } + + default: + BREAK; + } + + return; +} +#endif static void read_ism_ratio_index( @@ -3471,6 +3614,321 @@ static void read_ism_ratio_index( } } +#ifdef IVAS_FLOAT_FIXED +static void read_ism_ratio_index_fx( + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM read ratio indexes */ + const Word16 nchan_ism, /* i : number of objects */ + const Word16 numCodingBands, /* i : number of subbands */ + const Word16 sf, /* i : index of subframe */ + Word16 ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : previous subframe ISM ratio indexes */ + UWord16 *bit_stream, /* i : bitstream */ + Word16 *next_bit_pos, /* i/o: position in bitstream */ + const Word32 *masa_to_total_energy_ratio_fx, /* i : masa to total ratios */ + const Word16 idx_sep_obj, /* i : index of separated index, -1 if none */ + Word16 *num_zeros /* i/o: number of zero values in first subframe for separated object */ +) +{ + Word16 b, i, b_signif; + Word16 index; + Word16 GR_order, differential_subframe; + Word16 buf; + Word16 no_levels_ratio_ism; + Word16 bits_index; + Word16 ratio_ism_idx_ref[MAX_NUM_OBJECTS]; + Word16 idx_sep_obj_local, shift_one; + + idx_sep_obj_local = idx_sep_obj; + move16(); + + IF( GT_16( idx_sep_obj, -1 ) ) + { + IF( EQ_16( idx_sep_obj, sub( nchan_ism, 1 ) ) && GT_16( nchan_ism, 2 ) ) + { + idx_sep_obj_local = 0; + move16(); + } + } + + b_signif = 0; + move16(); + no_levels_ratio_ism = ( ( 1 << PARAM_ISM_POW_RATIO_NBITS ) - 1 ); + move16(); + + test(); + WHILE( ( LT_16( b_signif, numCodingBands ) ) && ( GE_32( masa_to_total_energy_ratio_fx[b_signif], MASA2TOTAL_THR_Q30 ) ) ) + { + /* distribute evenly the objects */ + distribute_evenly_ism_fx( ratio_ism_idx[b_signif], no_levels_ratio_ism, nchan_ism ); + b_signif = add( b_signif, 1 ); + } + + IF( EQ_16( b_signif, numCodingBands ) ) + { + return; + } + ELSE + { + + IF( EQ_16( sf, 0 ) ) + { + bits_index = bits_index_ism_ratio( nchan_ism ); + + /* read coding type */ + IF( bit_stream[( *next_bit_pos )--] == 1 ) + { + /* independent coding*/ + FOR( b = 0; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio_fx[b], MASA2TOTAL_THR_Q30 ) ) + { + index = 0; + move16(); + FOR( i = 0; i < bits_index; i++ ) + { + index = add( shl( index, 1 ), (Word16) bit_stream[( *next_bit_pos )--] ); + } + decode_index_slice_fx( index, ratio_ism_idx[b], nchan_ism, no_levels_ratio_ism ); + IF( GT_16( idx_sep_obj, -1 ) && EQ_16( ratio_ism_idx[b][idx_sep_obj_local], 0 ) ) + { + ( *num_zeros )++; + } + } + ELSE + { + /* distribute evenly the objects */ + distribute_evenly_ism_fx( ratio_ism_idx[b], no_levels_ratio_ism, nchan_ism ); + } + } + } + ELSE + { + /* differential coding */ + index = 0; + move16(); + FOR( i = 0; i < bits_index; i++ ) + { + index = add( shl( index, 1 ), (Word16) bit_stream[( *next_bit_pos )--] ); + } + decode_index_slice_fx( index, ratio_ism_idx[b_signif], nchan_ism, no_levels_ratio_ism ); + IF( GT_16( idx_sep_obj, -1 ) && EQ_16( ratio_ism_idx[b_signif][idx_sep_obj_local], 0 ) ) + { + ( *num_zeros )++; + } + Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); + FOR( b = b_signif + 1; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio_fx[b], MASA2TOTAL_THR_Q30 ) ) + { + ratio_ism_idx[b][nchan_ism - 1] = no_levels_ratio_ism; + move16(); + FOR( i = 0; i < nchan_ism - 1; i++ ) + { + buf = ivas_qmetadata_DecodeExtendedGR( bit_stream, next_bit_pos, 100, 0 ); + IF( EQ_16( buf % 2, 0 ) ) + { + ratio_ism_idx[b][i] = negate( shr( buf, 1 ) ); + move16(); + } + ELSE + { + ratio_ism_idx[b][i] = shr( add( buf, 1 ), 1 ); + move16(); + } + ratio_ism_idx[b][i] = add( ratio_ism_idx[b][i], ratio_ism_idx_ref[i] ); + move16(); + ratio_ism_idx[b][nchan_ism - 1] = sub( ratio_ism_idx[b][nchan_ism - 1], ratio_ism_idx[b][i] ); + move16(); + } + Copy( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); + IF( GT_16( idx_sep_obj, -1 ) && EQ_16( ratio_ism_idx[b][idx_sep_obj_local], 0 ) ) + { + ( *num_zeros )++; + } + } + ELSE + { + /* distribute evenly the objects */ + distribute_evenly_ism_fx( ratio_ism_idx[b], no_levels_ratio_ism, nchan_ism ); + } + } + } + } + ELSE + { + IF( GT_16( numCodingBands, 1 ) ) + { + /* read prediction type */ + differential_subframe = bit_stream[( *next_bit_pos )--]; + move16(); + } + ELSE + { + differential_subframe = 1; + move16(); + } + + IF( EQ_16( *num_zeros, numCodingBands ) ) + { + shift_one = 1; + } + ELSE + { + shift_one = 0; + } + move16(); + + IF( EQ_16( shift_one, 1 ) && EQ_16( nchan_ism, 2 ) ) + { + /* nothing has been sent ; values can be inferred */ + FOR( b = b_signif; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio_fx[b], MASA2TOTAL_THR_Q30 ) ) + { + IF( EQ_16( idx_sep_obj_local, 0 ) ) + { + ratio_ism_idx[b][0] = 0; + move16(); + ratio_ism_idx[b][1] = 7; + move16(); + } + ELSE + { + ratio_ism_idx[b][0] = 7; + move16(); + ratio_ism_idx[b][1] = 0; + move16(); + } + } + } + } + ELSE + { + /* read GR order */ + GR_order = bit_stream[( *next_bit_pos )--]; + move16(); + + FOR( b = b_signif; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio_fx[b], MASA2TOTAL_THR_Q30 ) ) + { + FOR( i = 0; i < nchan_ism - 1 - shift_one; i++ ) + { + buf = ivas_qmetadata_DecodeExtendedGR( bit_stream, next_bit_pos, 100, GR_order ); + IF( EQ_16( buf % 2, 0 ) ) + { + ratio_ism_idx[b][i] = negate( shr( buf, 1 ) ); + move16(); + } + ELSE + { + ratio_ism_idx[b][i] = shr( add( buf, 1 ), 1 ); + move16(); + } + } + + /* insert separated obj */ + IF( shift_one ) + { + FOR( i = nchan_ism - 1; i > idx_sep_obj_local; i-- ) + { + ratio_ism_idx[b][i] = ratio_ism_idx[b][i - 1]; + move16(); + } + ratio_ism_idx[b][idx_sep_obj_local] = 0; /* this is only difference; need to pdate later as well */ + move16(); + } + } + } + IF( differential_subframe ) + { + /* differential to previous subframe */ + FOR( b = b_signif; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio_fx[b], MASA2TOTAL_THR_Q30 ) ) + { + ratio_ism_idx[b][nchan_ism - 1] = no_levels_ratio_ism; + move16(); + FOR( i = 0; i < nchan_ism - 1; i++ ) + { + ratio_ism_idx[b][i] = add( ratio_ism_idx[b][i], ratio_ism_idx_prev_sf[b][i] ); + move16(); + + test(); + IF( NE_16( shift_one, 0 ) && EQ_16( i, idx_sep_obj_local ) ) + { + ratio_ism_idx[b][i] = 0; + move16(); + } + ratio_ism_idx[b][nchan_ism - 1] = sub( ratio_ism_idx[b][nchan_ism - 1], ratio_ism_idx[b][i] ); + } + } + ELSE + { + /* distribute evenly the objects */ + distribute_evenly_ism_fx( ratio_ism_idx[b], no_levels_ratio_ism, nchan_ism ); + } + } + } + ELSE + { + /* difference to previous subband */ + ratio_ism_idx[b_signif][nchan_ism - 1] = no_levels_ratio_ism; + move16(); + + /* first significant subband - differential to previous subframe */ + FOR( i = 0; i < nchan_ism - 1; i++ ) + { + ratio_ism_idx[b_signif][i] = add( ratio_ism_idx[b_signif][i], ratio_ism_idx_prev_sf[b_signif][i] ); + move16(); + + IF( NE_16( shift_one, 0 ) && EQ_16( i, idx_sep_obj_local ) ) + { + ratio_ism_idx[b_signif][i] = 0; + move16(); + } + ratio_ism_idx[b_signif][nchan_ism - 1] = sub( ratio_ism_idx[b_signif][nchan_ism - 1], ratio_ism_idx[b_signif][i] ); + move16(); + } + + /* rest of subbands differential to previous subband */ + Copy( ratio_ism_idx[b_signif], ratio_ism_idx_ref, nchan_ism ); + FOR( b = b_signif + 1; b < numCodingBands; b++ ) + { + IF( LT_32( masa_to_total_energy_ratio_fx[b], MASA2TOTAL_THR_Q30 ) ) + { + ratio_ism_idx[b][nchan_ism - 1] = no_levels_ratio_ism; + move16(); + + FOR( i = 0; i < nchan_ism - 1; i++ ) + { + ratio_ism_idx[b][i] = add( ratio_ism_idx[b][i], ratio_ism_idx_ref[i] ); + move16(); + + test(); + IF( NE_16( shift_one, 0 ) && EQ_16( i, idx_sep_obj_local ) ) + { + ratio_ism_idx[b][i] = 0; + move16(); + } + ratio_ism_idx[b][nchan_ism - 1] = sub( ratio_ism_idx[b][nchan_ism - 1], ratio_ism_idx[b][i] ); + move16(); + } + Copy( ratio_ism_idx[b], ratio_ism_idx_ref, nchan_ism ); + } + ELSE + { + /* distribute evenly the objects */ + distribute_evenly_ism_fx( ratio_ism_idx[b], no_levels_ratio_ism, nchan_ism ); + } + } + } + } + } + + return; + } +} +#endif static void decode_ism_ratios( uint16_t *bit_stream, /* i : bitstream */ @@ -3547,6 +4005,89 @@ static void decode_ism_ratios( return; } +#ifdef IVAS_FLOAT_FIXED +static void decode_ism_ratios_fx( + UWord16 *bit_stream, /* i : bitstream */ + Word16 *next_bit_pos, /* i/o: position in bitstream */ + const Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : masa_to_total energy ratios */ + Word32 ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* o : ISM ratios */ + const Word16 n_ism, /* i : number of objects */ + const Word16 nbands, /* i : number of subbands */ + const Word16 numSf, /* i : number of subframes */ + const Word16 idx_separated_object /* i : index of separated object */ +) +{ + Word16 sf, band; + Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + Word16 ratio_ism_idx_prev_sf[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + Word32 tmp32_fx; + Word16 num_zeros; + num_zeros = 0; + move16(); + + /* hQMetaData->q_direction->cfg.nblocks; */ + FOR ( sf = 0; sf < numSf; sf++ ) + { + /* read ism ratio indexes */ + read_ism_ratio_index_fx( ratio_ism_idx, n_ism, nbands, sf, ratio_ism_idx_prev_sf, bit_stream, next_bit_pos, masa_to_total_energy_ratio_fx[sf], idx_separated_object, &num_zeros ); + /* save previous subframe index values */ + IF ( LT_16( sf, sub( numSf, 1 ) ) ) + { + FOR ( band = 0; band < nbands; band++ ) + { + Copy( ratio_ism_idx[band], ratio_ism_idx_prev_sf[band], n_ism ); + } + } + + /* reconstructed values */ + FOR( band = 0; band < nbands; band++ ) + { + reconstruct_ism_ratios_fx( ratio_ism_idx[band], n_ism, STEP_PARAM_ISM_POW_RATIO_NBITS_Q15, ratio_ism[sf][band]); + } + + test(); + IF ( GT_16( n_ism, 2 ) && ( EQ_16( idx_separated_object, sub(n_ism, 1)) ) ) + { + /* rotate */ + FOR ( band = 0; band < nbands; band++ ) + { + IF ( LT_32( masa_to_total_energy_ratio_fx[sf][band], MASA2TOTAL_THR_Q30 ) ) + { + tmp32_fx = ratio_ism[sf][band][n_ism - 1]; + move32(); + ratio_ism[sf][band][n_ism - 1] = ratio_ism[sf][band][0]; + move32(); + ratio_ism[sf][band][0] = tmp32_fx; + move32(); + } + } + } + + IF ( EQ_16( nbands, 1) ) + { + FOR ( band = 1; band < 5; band++ ) + { + Copy32( ratio_ism[sf][0], ratio_ism[sf][band], n_ism ); + } + } + } + + IF ( EQ_16( numSf, 1 ) ) + { + FOR ( sf = 1; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + FOR ( band = 0; band < nbands; band++ ) + { + Copy32(ratio_ism[0][band], ratio_ism[sf][band], n_ism ); + } + } + } + + return; +} + +#endif + static int16_t ivas_decode_masaism_metadata( IVAS_QMETADATA_HANDLE hQMetaData, @@ -3562,9 +4103,6 @@ static int16_t ivas_decode_masaism_metadata( { int16_t sf, band, dir, nbands, nblocks, obj, i; float energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; -#ifdef IVAS_FLOAT_FIXED - Word32 energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; -#endif int16_t *band_mapping; int16_t b; int16_t bits_ism[MAX_NUM_OBJECTS], index; @@ -3580,15 +4118,13 @@ static int16_t ivas_decode_masaism_metadata( /* Read MASA-to-total energy ratios */ #ifdef IVAS_FLOAT_FIXED - Word16 q = 25; - - ivas_omasa_decode_masa_to_total_fx( bit_stream, next_bit_pos, hMasaIsmData->masa_to_total_energy_ratio_fx, nbands, nblocks, &q ); + ivas_omasa_decode_masa_to_total_fx( bit_stream, next_bit_pos, hMasaIsmData->masa_to_total_energy_ratio_fx, nbands, nblocks ); FOR( int k = 0; k < (nblocks != 1 ? nblocks : MAX_PARAM_SPATIAL_SUBFRAMES); k++ ) { FOR( int j = 0; j < (nbands != 1 ? nbands : MASA_FREQUENCY_BANDS); j++ ) { - hMasaIsmData->masa_to_total_energy_ratio[k][j] = (float) hMasaIsmData->masa_to_total_energy_ratio_fx[k][j] / (float) ( 1 << q ); + hMasaIsmData->masa_to_total_energy_ratio[k][j] = (float) hMasaIsmData->masa_to_total_energy_ratio_fx[k][j] / (float) ( 1u << 30 ); } } #else @@ -3616,22 +4152,7 @@ static int16_t ivas_decode_masaism_metadata( } /* read ISM metadata */ -#ifdef IVAS_FLOAT_FIXED - for ( int lp = 0; lp < MAX_PARAM_SPATIAL_SUBFRAMES; lp++ ) - { - for ( int lp2 = 0; lp2 < MASA_FREQUENCY_BANDS; lp2++ ) - { - hMasaIsmData->masa_to_total_energy_ratio_fx[lp][lp2] = (Word32) ( hMasaIsmData->masa_to_total_energy_ratio[lp][lp2] * ( 1u << 30 ) ); - for ( int lp3 = 0; lp3 < MAX_NUM_OBJECTS; lp3++ ) - { - energy_ratio_ism_fx[lp][lp2][lp3] = (Word32) ( energy_ratio_ism[lp][lp2][lp3] * ( 1u << 30 ) ); - } - } - } - calculate_nbits_meta_fx( nchan_ism, energy_ratio_ism_fx, hMasaIsmData->masa_to_total_energy_ratio_fx, nblocks, nbands, bits_ism, idx_separated_object, ism_imp ); -#else calculate_nbits_meta( nchan_ism, energy_ratio_ism, hMasaIsmData->masa_to_total_energy_ratio, nblocks, nbands, bits_ism, idx_separated_object, ism_imp ); -#endif for ( obj = 0; obj < nchan_ism; obj++ ) { index = 0; @@ -3649,8 +4170,8 @@ static int16_t ivas_decode_masaism_metadata( { index = ( index << 1 ) + bit_stream[( *next_bit_pos )--]; } - deindex_spherical_component( index, &azimuth, &elevation, &idx_az, &idx_el, bits_ism[obj], MC_LS_SETUP_INVALID ); + deindex_spherical_component( index, &azimuth, &elevation, &idx_az, &idx_el, bits_ism[obj], MC_LS_SETUP_INVALID ); if ( azimuth * hMasaIsmData->q_azimuth_old[obj] > 0 ) { delta_phi = 180.0f / (float) ( no_phi_masa[bits_ism[obj] - 1][idx_el] ); /* 360/2*/ @@ -3731,3 +4252,207 @@ static int16_t ivas_decode_masaism_metadata( return ( nb_bits_read - *next_bit_pos ); } + +#ifdef IVAS_FLOAT_FIXED +static Word16 ivas_decode_masaism_metadata_fx( + IVAS_QMETADATA_HANDLE hQMetaData, + MASA_DECODER_HANDLE hMasa, + MASA_ISM_DATA_HANDLE hMasaIsmData, + const Word16 nchan_ism, + UWord16 *bit_stream, + Word16 *next_bit_pos, + const Word16 idx_separated_object, + const Word16 ism_imp, + const Word16 dirac_bs_md_write_idx, + const Word16 dirac_md_buffer_length ) +{ + Word16 sf, band, dir, nbands, nblocks, obj, i; + Word32 energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + Word16 *band_mapping; + Word16 b; + Word16 bits_ism[MAX_NUM_OBJECTS], index; + UWord16 idx_el, idx_az; + Word32 azimuth, elevation; + Word16 nb_bits_read; + Word32 delta_phi; + Word16 meta_write_index; + + nb_bits_read = *next_bit_pos; + move16(); + nbands = hQMetaData->q_direction->cfg.nbands; + move16(); + nblocks = hQMetaData->q_direction->cfg.nblocks; + move16(); + + /* Read MASA-to-total energy ratios */ + ivas_omasa_decode_masa_to_total_fx( bit_stream, next_bit_pos, hMasaIsmData->masa_to_total_energy_ratio_fx, nbands, nblocks ); + + IF( GT_16( nchan_ism, 1 ) ) + { + /* read ISM ratios */ + decode_ism_ratios_fx( bit_stream, next_bit_pos, hMasaIsmData->masa_to_total_energy_ratio_fx, energy_ratio_ism_fx, nchan_ism, nbands, nblocks, idx_separated_object ); + } + ELSE + { + FOR( sf = 0; sf < nblocks; sf++ ) + { + FOR( band = 0; band < nbands; band++ ) + { + energy_ratio_ism_fx[sf][band][0] = ONE_IN_Q30; + move32(); + } + } + } + + /* read ISM metadata */ + calculate_nbits_meta_fx( nchan_ism, energy_ratio_ism_fx, hMasaIsmData->masa_to_total_energy_ratio_fx, nblocks, nbands, bits_ism, idx_separated_object, ism_imp ); + + FOR( obj = 0; obj < nchan_ism; obj++ ) + { + index = 0; + move16(); + IF( LT_16( bits_ism[obj], 8 ) ) /* if low resolution, can look to the past */ + { + /* read if same as previous */ + IF( bit_stream[( *next_bit_pos )--] ) + { + azimuth = hMasaIsmData->q_azimuth_old_fx[obj]; + move32(); + elevation = hMasaIsmData->q_elevation_old_fx[obj]; + move32(); + } + ELSE + { + FOR( i = 0; i < bits_ism[obj]; i++ ) + { + index = add( shl( index, 1 ), (Word16) bit_stream[( *next_bit_pos )--] ); + } + + deindex_spherical_component_fx( index, &azimuth, &elevation, &idx_az, &idx_el, bits_ism[obj], MC_LS_SETUP_INVALID ); + + test(); + test(); + test(); + // if ( azimuth * hMasaIsmData->q_azimuth_old[obj] > 0 ) + IF( ( GT_32( azimuth, 0 ) && GT_32( hMasaIsmData->q_azimuth_old_fx[obj], 0 ) ) || ( LT_32( azimuth, 0 ) && LT_32( hMasaIsmData->q_azimuth_old_fx[obj], 0 ) ) ) + { + Word16 tmp_e; + delta_phi = L_deposit_h( BASOP_Util_Divide1616_Scale( 180, no_phi_masa[bits_ism[obj] - 1][idx_el], &tmp_e ) ); + delta_phi = L_shr( delta_phi, sub( 9, tmp_e ) ); /* to maintain Q22 */ + IF( GT_32( L_sub( azimuth, hMasaIsmData->q_azimuth_old_fx[obj] ), delta_phi ) ) + { + azimuth = L_sub( azimuth, delta_phi ); + } + ELSE + { + IF( GT_32( L_sub( hMasaIsmData->q_azimuth_old_fx[obj], azimuth ), delta_phi ) ) + { + azimuth = L_add( azimuth, delta_phi ); + } + } + } + + hMasaIsmData->q_azimuth_old_fx[obj] = azimuth; + move32(); + hMasaIsmData->q_elevation_old_fx[obj] = elevation; + move32(); + } + } + ELSE + { + FOR( i = 0; i < bits_ism[obj]; i++ ) + { + index = add( shl( index, 1 ), (Word16) bit_stream[( *next_bit_pos )--] ); + } + deindex_spherical_component_fx( index, &azimuth, &elevation, &idx_az, &idx_el, bits_ism[obj], MC_LS_SETUP_INVALID ); + + hMasaIsmData->q_azimuth_old_fx[obj] = azimuth; + hMasaIsmData->q_elevation_old_fx[obj] = elevation; + } + + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + meta_write_index = add( dirac_bs_md_write_idx, sf ) % dirac_md_buffer_length; + + Word16 int_azi = rint_fx( L_shr( azimuth, Q22 - 16 ) ); + Word16 int_ele = rint_fx( L_shr( elevation, Q22 - 16 ) ); + + hMasaIsmData->azimuth_ism[obj][meta_write_index] = int_azi; + move16(); + hMasaIsmData->elevation_ism[obj][meta_write_index] = int_ele; + move16(); + } + } + + /* Modify ISM metadata based on the MASA-to-total energy ratios */ + FOR( sf = 0; sf < nblocks; sf++ ) + { + FOR( band = 0; band < nbands; band++ ) + { + FOR( dir = 0; dir < nchan_ism; dir++ ) + { + energy_ratio_ism_fx[sf][band][dir] = L_shl( Mpy_32_32( energy_ratio_ism_fx[sf][band][dir], L_sub( ONE_IN_Q30, hMasaIsmData->masa_to_total_energy_ratio_fx[sf][band] ) ), 1 ); // Q30 + Q30 - 31 = Q29 + 1 = Q30 + move32(); + } + } + } + + /* Set data to struct in bins */ + band_mapping = hMasa->data.band_mapping; + move16(); + FOR( band = 0; band < hMasa->config.numCodingBands; ++band ) + { + FOR( b = MASA_band_grouping_24[band_mapping[band]]; b < MASA_band_grouping_24[band_mapping[band + 1]]; ++b ) + { + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; ++sf ) + { + IF( EQ_16( nblocks, 1 ) ) + { + i = 0; + move16(); + } + ELSE + { + i = sf; + move16(); + } + + meta_write_index = ( add( dirac_bs_md_write_idx, sf ) ) % dirac_md_buffer_length; + + FOR( dir = 0; dir < nchan_ism; dir++ ) + { + hMasaIsmData->energy_ratio_ism_fx[dir][meta_write_index][b] = energy_ratio_ism_fx[i][band][dir]; + move32(); + } + } + } + } + + return sub( nb_bits_read, *next_bit_pos ); +} +#endif + +/* + Fixed point implementation of rint(). +*/ +static Word16 rint_fx( /* returns in Q0 */ + Word32 num /* num in Q0 */ +) +{ + Word32 frac_part = L_abs( num ) & 0x0000FFFF; + Word16 int_part = extract_h( L_abs( num ) ); + Word16 res = int_part; + move16(); + + test(); + test(); + IF( GT_32( frac_part, ONE_IN_Q15 ) || ( EQ_32( frac_part, ONE_IN_Q15 ) && EQ_16( s_and( int_part, 1 ), 1 ) ) ) + { + res = add( res, 1 ); + } + IF( LT_32( num, 0 ) ) + { + res = negate( res ); + } + return res; +} \ No newline at end of file diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 8cf66110a..5a8aac240 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -39,6 +39,7 @@ #include "ivas_rom_com.h" #include "wmc_auto.h" #include "ivas_prot_fx.h" +#include "prot_fx2.h" /*------------------------------------------------------------------------- @@ -96,6 +97,9 @@ ivas_error ivas_omasa_data_open( for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR; sf++ ) { set_zero( hMasaIsmData->energy_ratio_ism[obj_idx][sf], CLDFB_NO_CHANNELS_MAX ); +#ifdef IVAS_FLOAT_FIXED + set32_fx( hMasaIsmData->energy_ratio_ism_fx[obj_idx][sf], 0, CLDFB_NO_CHANNELS_MAX ); +#endif } } set_s( hMasaIsmData->azimuth_separated_ism, 0, MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR ); diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index dc627ef74..48bb3a64a 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -8041,8 +8041,7 @@ void ivas_omasa_decode_masa_to_total_fx( Word16 *index, Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], const Word16 nbands, - const Word16 nblocks, - Word16 *q ) + const Word16 nblocks) { Word16 i, j, k; Word16 q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; @@ -8101,8 +8100,9 @@ void ivas_omasa_decode_masa_to_total_fx( { FOR( j = 0; j < nbands; j++ ) { - masa_to_total_energy_ratio_fx[i][j] = L_max( 0, L_shl( q_dct_data_fx[k], *q - 25 ) ); - masa_to_total_energy_ratio_fx[i][j] = L_min( 1 << *q, masa_to_total_energy_ratio_fx[i][j] ); + //masa_to_total_energy_ratio_fx[i][j] = L_max( 0, L_shl( q_dct_data_fx[k], *q - 25 ) ); + //masa_to_total_energy_ratio_fx[i][j] = L_min( 1 << *q, masa_to_total_energy_ratio_fx[i][j] ); + masa_to_total_energy_ratio_fx[i][j] = L_max( 0, L_shr(L_shl_sat(q_dct_data_fx[k], 31 - 25), 1) ); // Q30 k++; } } diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 692603a1a..ec070d505 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -957,9 +957,12 @@ typedef struct ivas_masa_ism_data_structure int16_t azimuth_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; int16_t elevation_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR]; float energy_ratio_ism[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR][CLDFB_NO_CHANNELS_MAX]; +#ifdef IVAS_FLOAT_FIXED + Word32 energy_ratio_ism_fx[MAX_NUM_OBJECTS][MAX_PARAM_SPATIAL_SUBFRAMES + DELAY_MASA_PARAM_DEC_SFR][CLDFB_NO_CHANNELS_MAX]; // Q30 +#endif float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; #ifdef IVAS_FLOAT_FIXED - Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; // Q30 #endif int16_t azimuth_ism_edited[MAX_NUM_OBJECTS]; int16_t elevation_ism_edited[MAX_NUM_OBJECTS]; @@ -971,6 +974,10 @@ typedef struct ivas_masa_ism_data_structure float q_azimuth_old[MAX_NUM_OBJECTS]; float q_elevation_old[MAX_NUM_OBJECTS]; +#ifdef IVAS_FLOAT_FIXED + Word32 q_azimuth_old_fx[MAX_NUM_OBJECTS]; + Word32 q_elevation_old_fx[MAX_NUM_OBJECTS]; +#endif float ismPreprocMatrix[2][2][CLDFB_NO_CHANNELS_MAX]; uint8_t objectsMoved; -- GitLab