From fd9abf41d9d27558ee2dc4ec57595b2e62d89b37 Mon Sep 17 00:00:00 2001 From: Sandesh Venkatesh Date: Mon, 9 Sep 2024 16:48:34 +0530 Subject: [PATCH] Fixed implementation for ivas_signaling_enc and signaling_enc_secondary --- lib_com/ivas_prot.h | 18 ++++ lib_enc/ivas_core_enc.c | 2 +- lib_enc/ivas_decision_matrix_enc.c | 157 +++++++++++++++++++++++++++++ lib_enc/ivas_stereo_td_enc.c | 58 +++++++++++ 4 files changed, 234 insertions(+), 1 deletion(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 7990ecedf..1d2056c8c 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -792,6 +792,15 @@ void ivas_decision_matrix_enc( const int16_t last_element_mode /* i : last element mode */ ); +#ifdef IVAS_FLOAT_FIXED +void ivas_signaling_enc_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ + const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo */ +); +#else void ivas_signaling_enc( Encoder_State *st, /* i/o: encoder state structure */ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ @@ -799,6 +808,7 @@ void ivas_signaling_enc( const int16_t tdm_SM_flag, /* i : channel combination scheme flag in TD stereo */ const int16_t tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo*/ ); +#endif // IVAS_FLOAT_FIXED void ivas_decision_matrix_dec( Decoder_State *st, /* i/o: decoder state structure */ @@ -2783,11 +2793,19 @@ void tdm_configure_enc( const int16_t nb_bits_metadata /* i : number of metadata bits */ ); +#ifdef IVAS_FLOAT_FIXED +ivas_error signaling_enc_secondary_fx( + Encoder_State *st, /* i/o: Encoder structure */ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag OR LRTD primary channel */ + const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag*/ +); +#else ivas_error signaling_enc_secondary( Encoder_State *st, /* i/o: Encoder structure */ const int16_t tdm_SM_flag, /* i : channel combination scheme flag */ const int16_t tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag */ ); +#endif void tdm_bit_alloc( const int16_t ivas_format, /* i : IVAS format */ diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index 37b321bb5..f6fdae4e4 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -237,7 +237,7 @@ ivas_error ivas_core_enc( if ( !MCT_flag || ( MCT_flag && cpe_id == 0 ) ) { - ivas_signaling_enc( st, MCT_flag, element_brate, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag ); + ivas_signaling_enc_fx( st, MCT_flag, element_brate, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag ); } /*---------------------------------------------------------------------* diff --git a/lib_enc/ivas_decision_matrix_enc.c b/lib_enc/ivas_decision_matrix_enc.c index 867d937c8..a8f4d8aa1 100644 --- a/lib_enc/ivas_decision_matrix_enc.c +++ b/lib_enc/ivas_decision_matrix_enc.c @@ -346,6 +346,162 @@ void ivas_decision_matrix_enc( * write signaling information of SCE/CPE mode into the bitstream *---------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +void ivas_signaling_enc_fx( + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const Word32 element_brate, /* i : element bitrate */ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag in TD stereo OR LRTD primary channel */ + const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag in TD stereo */ +) +{ + Word16 ind; + BSTR_ENC_HANDLE hBstr = st->hBstr; + + test(); + test(); + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) && EQ_16( st->idchan, 1 ) ) + { + /* minimal signaling for the secondary channel, most of the parameters are deduced from the primary channel */ + signaling_enc_secondary_fx( st, tdm_SM_or_LRTD_Pri, tdm_Pitch_reuse_flag ); + } + ELSE IF( EQ_16( st->element_mode, IVAS_SCE ) && st->low_rate_mode ) + { + /* ISM Low-rate mode -> do nothing -> always WB, ACELP core, IC coder_type */ + } + ELSE IF( ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) && EQ_16( st->idchan, 1 ) ) || LE_32( st->core_brate, SID_2k40 ) ) + { + /* do nothing */ + } + ELSE + { + IF( st->idchan == 0 ) + { + /*-------------------------------------------------------------------------- + * Write element mode info + *--------------------------------------------------------------------------*/ + + test(); + test(); + IF( ( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && !MCT_flag ) /* note: in MCT, the MDCT stereo is used exclusively */ + { + ind = sub( st->element_mode, IVAS_CPE_DFT ); + push_indice( hBstr, IND_SMODE, ind, NBITS_ELEMENT_MODE ); + } + + /*-------------------------------------------------------------------------- + * Write band-width info + *--------------------------------------------------------------------------*/ + + test(); + test(); + test(); + test(); + IF( EQ_16( st->element_mode, IVAS_SCE ) && LT_32( element_brate, MIN_BRATE_SWB_SCE ) ) + { + /* only WB is supported */ + } + ELSE IF( ( LT_32( element_brate, MIN_BRATE_FB_STEREO ) && !st->is_ism_format ) || + ( LT_32( element_brate, MIN_BRATE_FB_ISM ) && st->is_ism_format ) ) + { + /* WB and SWB are supported */ + ind = sub( st->bwidth, WB ); + push_indice( hBstr, IND_BWIDTH, ind, 1 ); + } + ELSE + { + /* WB, SWB and FB are supported */ + push_indice( hBstr, IND_BWIDTH, st->bwidth, NBITS_BWIDTH ); + } + + IF( NE_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + /*-------------------------------------------------------------------------- + * Write ACELP/MDCT core selection bit + *--------------------------------------------------------------------------*/ + + test(); + IF( EQ_16( st->element_mode, IVAS_CPE_TD ) || GE_32( st->total_brate, STEREO_TCX_MIN_RATE ) ) + { + IF( EQ_16( st->core, ACELP_CORE ) ) + { + push_indice( hBstr, IND_CORE, 0, 1 ); + } + ELSE + { + push_indice( hBstr, IND_CORE, 1, 1 ); + } + } + + /*-------------------------------------------------------------------------- + * Write core dependent signaling + *--------------------------------------------------------------------------*/ + + IF( EQ_16( st->core, ACELP_CORE ) ) + { + IF( LT_32( element_brate, FRMT_SHP_MIN_BRATE_IVAS ) ) + { + push_indice( hBstr, IND_ACELP_SIGNALLING, st->coder_type, 3 ); + } + ELSE + { + /* write coder type */ + push_indice( hBstr, IND_ACELP_SIGNALLING, st->coder_type, 3 ); + + /* write sharpening flag */ + push_indice( hBstr, IND_SHARP_FLAG, st->sharpFlag, 1 ); + } + + /* write extension layer flag to distinguish between TBE (0) and BWE (1) */ + IF( st->extl_brate > 0 ) + { + test(); + test(); + test(); + test(); + IF( EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) + { + push_indice( hBstr, IND_BWE_FLAG, 0, 1 ); + } + ELSE IF( EQ_16( st->extl, WB_BWE ) || EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) ) + { + push_indice( hBstr, IND_BWE_FLAG, 1, 1 ); + } + } + } + ELSE /* MDCT core */ + { + /* write TCX/HQ selection flag */ + IF( EQ_16( st->core, HQ_CORE ) ) + { + push_indice( hBstr, IND_MDCT_CORE, 0, 1 ); + } + ELSE /* TCX20/TCX10 core */ + { + push_indice( hBstr, IND_MDCT_CORE, 1, 1 ); + } + + IF( EQ_16( st->core, HQ_CORE ) ) + { + IF( EQ_16( st->last_core, ACELP_CORE ) ) + { + push_indice( hBstr, IND_HQ_SWITCHING_FLG, 1, 1 ); + } + ELSE + { + push_indice( hBstr, IND_HQ_SWITCHING_FLG, 0, 1 ); + } + } + } + } /* element_mode != IVAS_CPE_MDCT */ + } + } + + return; +} +#else void ivas_signaling_enc( Encoder_State *st, /* i/o: encoder state structure */ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ @@ -485,3 +641,4 @@ void ivas_signaling_enc( return; } +#endif diff --git a/lib_enc/ivas_stereo_td_enc.c b/lib_enc/ivas_stereo_td_enc.c index ce1a4ff8f..56123bcc9 100644 --- a/lib_enc/ivas_stereo_td_enc.c +++ b/lib_enc/ivas_stereo_td_enc.c @@ -638,6 +638,63 @@ void tdm_configure_enc( * Signalling of the secondary channel *-------------------------------------------------------------------*/ +#ifdef IVAS_FLOAT_FIXED +ivas_error signaling_enc_secondary_fx( + Encoder_State *st, /* i/o: Encoder structure */ + const Word16 tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag OR LRTD primary channel */ + const Word16 tdm_Pitch_reuse_flag /* i : primary channel pitch reuse flag*/ +) +{ + Word16 ind; + BSTR_ENC_HANDLE hBstr = st->hBstr; + ivas_error error; + + error = IVAS_ERR_OK; + move32(); + + /* The secondary channel band-witdh is always the same as the primary channel bandwidth */ + + ind = st->coder_type; + move16(); + IF( EQ_16( tdm_Pitch_reuse_flag, 1 ) ) /* possible only for bitrate <= 24400 */ + { + ind = 3; + move16(); + } + ELSE IF( EQ_16( st->coder_type, GENERIC ) ) + { + ind = 2; + move16(); + } + ELSE IF( EQ_16( st->coder_type, AUDIO ) ) + { + ind = sub( ind, 2 ); + } + + ind = shl( ind, 1 ); + ind = add( ind, tdm_SM_or_LRTD_Pri ); /* addition of the channel combination scheme flag value or the LRTD primary channel*/ + push_indice( hBstr, IND_STEREO_2ND_CODER_T, ind, TDM_SECONDARY_SIGNALLING ); + + /* write extension layer flag to distinguish between TBE (0) and BWE (1) */ + IF( st->extl_brate > 0 ) + { + test(); + test(); + test(); + test(); + IF( EQ_16( st->extl, WB_TBE ) || EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) + { + push_indice( hBstr, IND_BWE_FLAG, 0, 1 ); + } + ELSE IF( EQ_16( st->extl, WB_BWE ) || EQ_16( st->extl, SWB_BWE ) || EQ_16( st->extl, FB_BWE ) ) + { + push_indice( hBstr, IND_BWE_FLAG, 1, 1 ); + } + } + + return error; +} +#else ivas_error signaling_enc_secondary( Encoder_State *st, /* i/o: Encoder structure */ const int16_t tdm_SM_or_LRTD_Pri, /* i : channel combination scheme flag OR LRTD primary channel */ @@ -685,6 +742,7 @@ ivas_error signaling_enc_secondary( return error; } +#endif // IVAS_FLOAT_FIXED /*-------------------------------------------------------------------* * Function tdm_downmix_plain() -- GitLab