diff --git a/lib_com/bitstream.c b/lib_com/bitstream.c index 761ad816bd70d18428620baf60fb15728db107c6..d221b9cf92ee46aec7477a53760820a4ccea9ade 100644 --- a/lib_com/bitstream.c +++ b/lib_com/bitstream.c @@ -1820,7 +1820,11 @@ ivas_error preview_indices( break; } } +#ifdef ALIGN_SID_SIZE + else if ( total_brate == IVAS_SID_5k2 ) +#else else if ( total_brate == IVAS_SID_4k4 ) +#endif { /* read SID format */ st_ivas->sid_format = 0; @@ -1884,6 +1888,7 @@ ivas_error preview_indices( return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Invalid value %c found in SID format field.", st_ivas->sid_format ); } } +#ifndef ALIGN_SID_SIZE else if ( total_brate == IVAS_SID_5k ) { /* SBA SID frame */ @@ -1892,6 +1897,7 @@ ivas_error preview_indices( st_ivas->sba_mode = SBA_MODE_SPAR; st_ivas->element_mode_init = IVAS_SCE; } +#endif /* only read element mode from active frames */ if ( is_DTXrate( total_brate ) == 0 ) @@ -2063,6 +2069,9 @@ ivas_error read_indices( } else if ( k == SIZE_IVAS_BRATE_TBL ) { +#ifdef ALIGN_SID_SIZE + return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error, illegal bitrate (%d) in the G.192 frame ! Exiting ! \n", total_brate ); +#else /*temp change for SPAR DTX*/ if ( total_brate == IVAS_SID_5k ) { @@ -2072,6 +2081,7 @@ ivas_error read_indices( { return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error, illegal bitrate (%d) in the G.192 frame ! Exiting ! \n", total_brate ); } +#endif } else { @@ -2965,4 +2975,18 @@ void evs_dec_previewFrame( } +#ifdef ALIGN_SID_SIZE +void dtx_read_padding_bits( + DEC_CORE_HANDLE st, + int16_t num_bits ) +{ + /* TODO: temporary hack, need to decide what to do with core-coder bitrate */ + int32_t tmp; + tmp = st->total_brate; + st->total_brate = st->total_brate + num_bits * FRAMES_PER_SEC; + get_next_indice( st, num_bits ); + st->total_brate = tmp; +} +#endif + #undef WMC_TOOL_MAN diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index bcc293a940c1ba9e66acd72fa3237af6a4bdb819..2c3f901324b4a2803bd96712ae19d4460a838b75 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -195,9 +195,12 @@ typedef enum /*----------------------------------------------------------------------------------* * IVAS Bitrates *----------------------------------------------------------------------------------*/ - +#ifdef ALIGN_SID_SIZE +#define IVAS_SID_5k2 5200 /* SID frame bitrate */ +#else #define IVAS_SID_4k4 4400 /* SID frame bitrate */ #define IVAS_SID_5k 5000 /* SBA SID frame bitrate */ +#endif #define IVAS_13k2 13200 #define IVAS_16k4 16400 #define IVAS_24k4 24400 @@ -215,8 +218,13 @@ typedef enum #define IVAS_BRATE_MAX IVAS_512k +#ifdef ALIGN_SID_SIZE +#define SIZE_IVAS_BRATE_TBL 16 +#define IVAS_NUM_ACTIVE_BRATES (SIZE_IVAS_BRATE_TBL - 2) +#else #define SIZE_IVAS_BRATE_TBL 17 #define IVAS_NUM_ACTIVE_BRATES (SIZE_IVAS_BRATE_TBL - 3) +#endif /*----------------------------------------------------------------------------------* * IVAS modes : IVAS SCE, IVAS CPE modes (DFT, TD, MDCT stereo) diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 872c9bbba45c49be5076a7485fe1b393a9ac3e99..80ca92e18cf62d1436825b9e650004e797e7198c 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -323,7 +323,11 @@ ivas_error ivas_dirac_sba_config( if ( sba_mode == SBA_MODE_SPAR ) { /*map the bitrate for SID frame*/ +#ifdef ALIGN_SID_SIZE + if ( sba_total_brate == IVAS_SID_5k2 ) +#else if ( sba_total_brate == IVAS_SID_5k ) +#endif { if ( *element_mode == IVAS_SCE ) { @@ -420,11 +424,19 @@ ivas_error ivas_dirac_sba_config( return error; } +#ifdef ALIGN_SID_SIZE + if ( sba_total_brate > IVAS_SID_5k2 ) +#else if ( sba_total_brate > IVAS_SID_4k4 ) +#endif { *nchan_transport = ivas_dirac_getNumTransportChannels( sba_total_brate, sba_order, sba_planar ); } +#ifdef ALIGN_SID_SIZE + else if ( sba_total_brate == IVAS_SID_5k2 ) +#else else if ( sba_total_brate == IVAS_SID_4k4 ) +#endif { switch ( *element_mode ) { diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index e32e7bff9650b99b4ddbc15b1b3a4a9b010a686f..87981b316e34de2cc1bff517928633e81bc3d411 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -2773,8 +2773,12 @@ void reset_metadata_spatial( int32_t *total_brate, /* o : total bitrate */ const int32_t core_brate, /* i : core bitrate */ const int16_t nb_bits_metadata, /* i : number of meatdata bits */ +#ifndef ALIGN_SID_SIZE const SBA_MODE sba_mode, /* i : SBA mode */ const int16_t element_mode /* i : element mode */ +#else + const SBA_MODE sba_mode /* i : SBA mode */ +#endif ); /*! r: number of bits written */ @@ -5463,4 +5467,11 @@ float rand_triangular_signed( /* clang-format on */ +#ifdef ALIGN_SID_SIZE +void dtx_read_padding_bits( + DEC_CORE_HANDLE st, + int16_t num_bits +); +#endif + #endif /* IVAS_PROT_H */ diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 4ab1a1d927a073b4a26549eefb43954a6c656fd7..4a82259296911c7f7f86eb8ebe60207f4fb1591a 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -49,7 +49,11 @@ const int32_t ivas_brate_tbl[SIZE_IVAS_BRATE_TBL] = { +#ifdef ALIGN_SID_SIZE + FRAME_NO_DATA, IVAS_SID_5k2, +#else FRAME_NO_DATA, IVAS_SID_4k4, IVAS_SID_5k, +#endif IVAS_13k2, IVAS_16k4, IVAS_24k4, IVAS_32k, IVAS_48k, IVAS_64k, IVAS_80k, IVAS_96k, IVAS_128k, IVAS_160k, IVAS_192k, IVAS_256k, IVAS_384k, IVAS_512k diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index 46f6b3dc41abd557c621d4494e581cfb13c9449a..4955f9f9e2d60c27e34312a2a2a6e09a16731418 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -311,7 +311,11 @@ void ivas_spar_config( const int16_t sid_format /* i : IVAS format indicator from SID frame */ ) { +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate == IVAS_SID_5k2 ) +#else if ( ivas_total_brate == IVAS_SID_5k ) +#endif { if ( sid_format == SID_SBA_1TC ) { @@ -333,7 +337,11 @@ void ivas_spar_config( if ( *nchan_transport == 1 ) { /* map SPAR SID bitrate to SPAR active bitrate */ +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate == IVAS_SID_5k2 ) +#else if ( ivas_total_brate == IVAS_SID_5k ) +#endif { ivas_total_brate = IVAS_32k; } @@ -422,7 +430,11 @@ int16_t ivas_get_spar_num_TCs( { int16_t table_idx, nchan_transport; +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate == IVAS_SID_5k2 ) +#else if ( ivas_total_brate == IVAS_SID_5k ) +#endif { nchan_transport = 1; } diff --git a/lib_com/ivas_stereo_dft_com.c b/lib_com/ivas_stereo_dft_com.c index 918fd27b356378a66a9e3a414d6affe2520f2ec7..7de3144f633d12f64fa801e8e0d2b05050e0f450 100644 --- a/lib_com/ivas_stereo_dft_com.c +++ b/lib_com/ivas_stereo_dft_com.c @@ -82,7 +82,11 @@ void stereo_dft_config( hConfig->res_cod_mode = STEREO_DFT_RES_COD_OFF; } } +#ifdef ALIGN_SID_SIZE + else if ( brate == IVAS_SID_5k2 ) +#else else if ( brate == IVAS_SID_4k4 ) +#endif { *bits_frame_nominal = SID_2k40 / FRAMES_PER_SEC; if ( hConfig != NULL ) diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index 079af159bc453e57fa0d0ba2621421c195c7dadd..6b0c0eb297376589341ea72a8fce06e5db9f3a1e 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -1172,8 +1172,12 @@ int16_t is_SIDrate( if ( ( ivas_total_brate == SID_1k75 ) || ( ivas_total_brate == SID_2k40 ) || +#ifdef ALIGN_SID_SIZE + ( ivas_total_brate == IVAS_SID_5k2 ) ) +#else ( ivas_total_brate == IVAS_SID_4k4 ) || ( ivas_total_brate == IVAS_SID_5k ) ) +#endif { sid_rate_flag = 1; } diff --git a/lib_com/options.h b/lib_com/options.h index 43a77742341ce0fb1c9cc36be918856812d694c4..c27d1aa3eb4a910baf1d06216734dcefc1eb242a 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -156,11 +156,10 @@ #define FIX_I74_BW_LIMITATION_ALT /* issue 74: Propagate bitrate induced BW limitation to hEncoderConfig. Ensures BE between explicit BW limitation using "-max_band " and BW limited by bitrate; alternative fix */ #define FIX_I74_CLEANING /* issue 74: remove redundant function call in ivas_cpe_enc() */ - -/* NTT switches */ - #define SPAR_SCALING_HARMONIZATION /* issue 80: Changes to harmonize scaling in spar */ +#define ALIGN_SID_SIZE /* Issue 111: make all DTX modes use one SID frame bitrate (5.2 kbps) */ + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index 7951f10d549e02e623e314e855da1e7a2a06769b..5c601c5825375bca56befc276bdec8d527b8d506 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -125,7 +125,11 @@ ivas_error acelp_core_dec( error = IVAS_ERR_OK; +#ifdef ALIGN_SID_SIZE + if ( st->element_mode == IVAS_CPE_MDCT && nchan_out == 1 && st->idchan == 1 && last_element_brate <= IVAS_SID_5k2 ) +#else if ( st->element_mode == IVAS_CPE_MDCT && nchan_out == 1 && st->idchan == 1 && last_element_brate <= IVAS_SID_4k4 ) +#endif { /* In MDCT-Stereo DTX with mono output, we can skip CNG for the second channel, except for the first inactive frame following an active period */ return error; diff --git a/lib_dec/core_switching_dec.c b/lib_dec/core_switching_dec.c index 61537f76e3ca0527eddc7b64bdc52c65e3860584..e8c74bc2ef0a84893a5e25c2b784136b682827b5 100644 --- a/lib_dec/core_switching_dec.c +++ b/lib_dec/core_switching_dec.c @@ -1048,7 +1048,11 @@ void bw_switching_pre_proc( if ( st->element_mode > EVS_MONO ) { +#ifdef ALIGN_SID_SIZE + if ( st->core == ACELP_CORE && !( st->bfi == 1 && st->con_tcx == 1 ) && st->hBWE_FD != NULL && !( st->core_brate <= SID_2k40 && st->element_mode == IVAS_CPE_DFT && nchan_out == 2 ) && !( st->element_mode == IVAS_CPE_MDCT && nchan_out == 1 && st->idchan == 1 && last_element_brate <= IVAS_SID_5k2 ) ) +#else if ( st->core == ACELP_CORE && !( st->bfi == 1 && st->con_tcx == 1 ) && st->hBWE_FD != NULL && !( st->core_brate <= SID_2k40 && st->element_mode == IVAS_CPE_DFT && nchan_out == 2 ) && !( st->element_mode == IVAS_CPE_MDCT && nchan_out == 1 && st->idchan == 1 && last_element_brate <= IVAS_SID_4k4 ) ) +#endif { /* Calculate tilt of the ACELP core synthesis - needed in SWB BWE decoding */ calc_tilt_bwe( old_syn_12k8_16k, &st->tilt_wb, st->L_frame ); diff --git a/lib_dec/fd_cng_dec.c b/lib_dec/fd_cng_dec.c index 4f0e8574f0f03df649898d994f875bab35ce1b8c..974d046368d5d5f31edd11f30bfb2cb0b89946fa 100644 --- a/lib_dec/fd_cng_dec.c +++ b/lib_dec/fd_cng_dec.c @@ -2099,6 +2099,10 @@ void FdCngDecodeMDCTStereoSID( msvq_dec( cdk_37bits_ivas, NULL, NULL, stages, N, FD_CNG_maxN_37bits, indices, ms_ptr[ch], NULL ); } +#ifdef ALIGN_SID_SIZE + dtx_read_padding_bits( sts[1], ( IVAS_SID_5k2 - 4400 ) / FRAMES_PER_SEC ); +#endif + if ( sts[0]->hFdCngDec->hFdCngCom->no_side_flag ) { set_zero( ms_ptr[1], NPART ); @@ -2122,7 +2126,11 @@ void FdCngDecodeMDCTStereoSID( lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac ); } +#ifdef ALIGN_SID_SIZE + if ( hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_SID_5k2 ) +#else if ( hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_SID_4k4 ) +#endif { /* create proper M noise shape in channel zero after gains have been applied */ for ( p = 0; p < N; p++ ) diff --git a/lib_dec/ivas_cpe_dec.c b/lib_dec/ivas_cpe_dec.c index 680839e121f50051d2a042095e7730ed7d05959f..313e0d6172d0a1ea572c92aa89520a7170f8f180 100644 --- a/lib_dec/ivas_cpe_dec.c +++ b/lib_dec/ivas_cpe_dec.c @@ -160,14 +160,22 @@ ivas_error ivas_cpe_dec( if ( hCPE->element_mode != IVAS_CPE_MDCT && ( hCPE->element_brate != hCPE->last_element_brate || hCPE->last_element_mode != hCPE->element_mode || sts[0]->ini_frame == 0 || ( ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) { +#ifdef ALIGN_SID_SIZE + if ( st_ivas->hQMetaData != NULL && ivas_total_brate > IVAS_SID_5k2 ) +#else if ( st_ivas->hQMetaData != NULL && ivas_total_brate > IVAS_SID_4k4 ) +#endif { stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, st_ivas->hQMetaData->bits_frame_nominal * FRAMES_PER_SEC, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } else { /* Note: This only works for stereo operation. If DTX would be applied for multiple CPEs a different bitrate signaling is needed */ +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate <= IVAS_SID_5k2 ) +#else if ( ivas_total_brate <= IVAS_SID_4k4 ) +#endif { stereo_dft_config( hCPE->hStereoDft == NULL ? NULL : hCPE->hStereoDft->hConfig, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); } @@ -203,7 +211,11 @@ ivas_error ivas_cpe_dec( /* Update DFT Stereo memories */ stereo_dft_dec_update( hCPE->hStereoDft, output_frame, 0 ); +#ifdef ALIGN_SID_SIZE + if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_5k2 ) +#else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_4k4 ) +#endif { if ( ivas_total_brate == FRAME_NO_DATA ) { @@ -220,13 +232,21 @@ ivas_error ivas_cpe_dec( nb_bits = (int16_t) ( ( hCPE->element_brate ) / FRAMES_PER_SEC - 0.8f * sts[0]->bits_frame_nominal ); sts[1]->bit_stream = sts[0]->bit_stream + ivas_total_brate / FRAMES_PER_SEC - 1 - nb_bits_metadata; +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate == IVAS_SID_5k2 ) +#else if ( ivas_total_brate == IVAS_SID_4k4 ) +#endif { nb_bits -= SID_FORMAT_NBITS; sts[1]->bit_stream -= SID_FORMAT_NBITS; } +#ifdef ALIGN_SID_SIZE + if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_5k2 ) +#else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_4k4 ) +#endif { sts[0]->total_brate = hCPE->element_brate; /* Only mono downmix was transmitted in this case */ } @@ -266,7 +286,11 @@ ivas_error ivas_cpe_dec( /* this is just for initialization, the true values of "total_brate" and "bits_frame_channel" are set later */ for ( n = 0; n < n_channels; n++ ) { +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate == IVAS_SID_5k2 ) +#else if ( ivas_total_brate == IVAS_SID_4k4 || ivas_total_brate == IVAS_SID_5k ) +#endif { sts[n]->total_brate = SID_2k40; @@ -283,7 +307,11 @@ ivas_error ivas_cpe_dec( if ( !st_ivas->hMCT ) { +#ifdef ALIGN_SID_SIZE + if ( st_ivas->ivas_format == SBA_FORMAT && ivas_total_brate == IVAS_SID_5k2 ) +#else if ( st_ivas->ivas_format == SBA_FORMAT && ivas_total_brate == IVAS_SID_5k ) +#endif { for ( n = 0; n < n_channels; n++ ) { @@ -587,7 +615,11 @@ ivas_error create_cpe_dec( hCPE->nchan_out = min( CPE_CHANNELS, st_ivas->hDecoderConfig->nchan_out ); } +#ifdef ALIGN_SID_SIZE + if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_5k2 ) +#else if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_4k4 ) +#endif { hCPE->nchan_out = 1; } @@ -923,7 +955,11 @@ static void read_stereo_mode_and_bwidth( * BFI or NO_DATA frame: Use stereo parameters from last (active) frame *-----------------------------------------------------------------*/ +#ifdef ALIGN_SID_SIZE + if ( st_ivas->bfi || st_ivas->hDecoderConfig->ivas_total_brate < IVAS_SID_5k2 ) +#else if ( st_ivas->bfi || st_ivas->hDecoderConfig->ivas_total_brate < IVAS_SID_4k4 ) +#endif { hCPE->element_mode = hCPE->last_element_mode; @@ -933,7 +969,11 @@ static void read_stereo_mode_and_bwidth( * SID frame: get element mode from SID side info *-----------------------------------------------------------------*/ +#ifdef ALIGN_SID_SIZE + else if ( st_ivas->hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 ) +#else else if ( st_ivas->hDecoderConfig->ivas_total_brate == IVAS_SID_4k4 || st_ivas->hDecoderConfig->ivas_total_brate == IVAS_SID_5k ) +#endif { switch ( st_ivas->sid_format ) { diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index 22f841728edc1f64d2f9dba56fd1bf75159f6405..ff6df585efddee1f76b3b81e98436d218780ada3 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -290,8 +290,11 @@ ivas_error ivas_dec( nchan_remapped = CPE_CHANNELS; ivas_sba_dirac_stereo_dec( st_ivas, output, output_frame ); } - else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && - ( ivas_total_brate > IVAS_SID_4k4 || ( ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE > 0 && st_ivas->hCPE[0]->nchan_out == 1 ) ) ) +#ifdef ALIGN_SID_SIZE + else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ( ivas_total_brate > IVAS_SID_5k2 || ( ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE > 0 && st_ivas->hCPE[0]->nchan_out == 1 ) ) ) +#else + else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ( ivas_total_brate > IVAS_SID_4k4 || ( ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE > 0 && st_ivas->hCPE[0]->nchan_out == 1 ) ) ) +#endif { nchan_remapped = 1; /* Only one channel transported */ } @@ -575,7 +578,11 @@ ivas_error ivas_dec( st_ivas->ini_frame++; } +#ifdef ALIGN_SID_SIZE + if ( st_ivas->ini_active_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && ivas_total_brate > IVAS_SID_5k2 ) /* needed in MASA decoder in case the first active frame is BFI, and there were SID-frames decoded before */ +#else if ( st_ivas->ini_active_frame < MAX_FRAME_COUNTER && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && ivas_total_brate > IVAS_SID_4k4 ) /* needed in MASA decoder in case the first active frame is BFI, and there were SID-frames decoded before */ +#endif { st_ivas->ini_active_frame++; } diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index 8dd47fe77488228f8b98db3008ad465ee2871fe2..162002852b00b71c83d712dac0772086f5731525 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -190,7 +190,11 @@ ivas_error ivas_dirac_dec_config( } nchan_transport = st_ivas->nchan_transport; +#ifdef ALIGN_SID_SIZE + if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_5k2 ) +#else if ( st_ivas->ivas_format == MASA_FORMAT && ivas_total_brate < MASA_STEREO_MIN_BITRATE && ivas_total_brate > IVAS_SID_4k4 ) +#endif { nchan_transport = 1; } @@ -1280,7 +1284,11 @@ void ivas_dirac_dec_read_BS( int16_t next_bit_pos_orig; *nb_bits = 0; +#ifdef ALIGN_SID_SIZE + if ( !st->bfi && ivas_total_brate > IVAS_SID_5k2 ) +#else if ( !st->bfi && ivas_total_brate > IVAS_SID_4k4 ) +#endif { next_bit_pos_orig = st->next_bit_pos; st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 ); @@ -1289,14 +1297,19 @@ void ivas_dirac_dec_read_BS( b = st->bit_stream[( st->next_bit_pos )--]; ( *nb_bits )++; +#ifndef ALIGN_SID_SIZE if ( sba_mode == SBA_MODE_SPAR ) { + if ( ivas_total_brate == IVAS_SID_5k ) { b = 1; } } else +#else + if ( sba_mode != SBA_MODE_SPAR ) +#endif { assert( ( b == 0 ) || ( hQMetaData->q_direction[0].cfg.start_band > 0 ) ); } @@ -1384,12 +1397,23 @@ void ivas_dirac_dec_read_BS( st->next_bit_pos = next_bit_pos_orig; } +#ifdef ALIGN_SID_SIZE + else if ( !st->bfi && ivas_total_brate == IVAS_SID_5k2 ) +#else else if ( !st->bfi && ivas_total_brate == IVAS_SID_4k4 ) +#endif { next_bit_pos_orig = st->next_bit_pos; /* subtract mode signaling bits, since bitstream was moved after mode reading */ st->next_bit_pos = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 - SID_FORMAT_NBITS ); +#ifdef ALIGN_SID_SIZE + /* 1 bit flag for SPAR/DirAC, already read in read format function */ + b = st->bit_stream[( st->next_bit_pos )--]; + ( *nb_bits )++; + hQMetaData->sba_inactive_mode = 1; + orig_dirac_bands = hQMetaData->q_direction[0].cfg.nbands; +#endif /* if we start with a SID frame, we need to init the azi/ele arrays.*/ if ( st->ini_frame == 0 ) @@ -1404,8 +1428,39 @@ void ivas_dirac_dec_read_BS( } } +#ifdef ALIGN_SID_SIZE + *nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT, sba_mode ); + + if ( sba_mode == SBA_MODE_SPAR ) + { + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].azimuth[i] = hQMetaData->q_direction[0].band_data[1].azimuth[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].elevation[i] = hQMetaData->q_direction[0].band_data[1].elevation[0]; + hQMetaData->q_direction[0].band_data[orig_dirac_bands - 1].energy_ratio[i] = hQMetaData->q_direction[0].band_data[1].energy_ratio[0]; + } + for ( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( j = orig_dirac_bands - 2; j >= 0; j-- ) + { + hQMetaData->q_direction[0].band_data[j].azimuth[i] = hQMetaData->q_direction[0].band_data[0].azimuth[0]; + hQMetaData->q_direction[0].band_data[j].elevation[i] = hQMetaData->q_direction[0].band_data[0].elevation[0]; + hQMetaData->q_direction[0].band_data[j].energy_ratio[i] = hQMetaData->q_direction[0].band_data[0].energy_ratio[0]; + } + } + + hQMetaData->q_direction->cfg.nbands = orig_dirac_bands; + } + else + { + *nb_bits += SID_FORMAT_NBITS; + } +#else *nb_bits += ivas_qmetadata_dec_sid_decode( hQMetaData, st->bit_stream, &( st->next_bit_pos ), 0, NULL, SBA_FORMAT, SBA_MODE_DIRAC ); + *nb_bits += SID_FORMAT_NBITS; +#endif + st->next_bit_pos = next_bit_pos_orig; } @@ -1451,7 +1506,11 @@ void ivas_qmetadata_to_dirac( q_direction = &( hQMetaData->q_direction[0] ); hDirAC->numSimultaneousDirections = hQMetaData->no_directions; +#ifdef ALIGN_SID_SIZE + if ( hMasa != NULL && ivas_total_brate > IVAS_SID_5k2 ) +#else if ( hMasa != NULL && ivas_total_brate > IVAS_SID_4k4 ) +#endif { band_mapping = hMasa->data.band_mapping; @@ -1527,7 +1586,11 @@ void ivas_qmetadata_to_dirac( nbands = hDirAC->band_grouping[hDirAC->hConfig->nbands]; band_grouping = hDirAC->band_grouping; +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate <= IVAS_SID_5k2 && sba_mode != SBA_MODE_SPAR ) +#else if ( ivas_total_brate <= IVAS_SID_4k4 && sba_mode != SBA_MODE_SPAR ) +#endif { /* SID/zero-frame: 1 direction, 5 bands, nblocks re-generated out of SID decoder*/ start_band = 0; @@ -1623,7 +1686,11 @@ void ivas_qmetadata_to_dirac( ele = min( 90, ele ); ele = max( -90, ele ); +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL ) +#else if ( ivas_total_brate > IVAS_SID_4k4 && q_direction->coherence_band_data != NULL ) +#endif { hDirAC->spreadCoherence[tmp_write_idx_band][b] = q_direction->coherence_band_data[qBand_idx].spread_coherence[block] / 255.0f; } @@ -1632,7 +1699,11 @@ void ivas_qmetadata_to_dirac( hDirAC->spreadCoherence[tmp_write_idx_band][b] = 0.0f; } +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate > IVAS_SID_5k2 && q_direction->coherence_band_data != NULL ) +#else if ( ivas_total_brate > IVAS_SID_4k4 && q_direction->coherence_band_data != NULL ) +#endif { hDirAC->surroundingCoherence[tmp_write_idx_band][b] = hQMetaData->surcoh_band_data[qBand_idx].surround_coherence[0] / 255.0f; } diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 87b48cd0d897783610979384798c7a5882e2fcc9..d0f4e7ceb1b40ef3c45ab4959966c3d03f2a8b2d 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -103,7 +103,7 @@ ivas_error ivas_dec_setup( /* read the number of objects */ st_ivas->nchan_transport = 1; num_obj = 1; - k = ( int16_t )( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); + k = (int16_t) ( ( ivas_total_brate / FRAMES_PER_SEC ) - 1 ); while ( st_ivas->bit_stream[k] && num_obj < MAX_NUM_OBJECTS ) { num_obj++; @@ -126,7 +126,11 @@ ivas_error ivas_dec_setup( st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->sba_order ); num_bits_read += SBA_ORDER_BITS; +#ifdef ALIGN_SID_SIZE + if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate && ivas_total_brate > IVAS_SID_5k2 ) +#else if ( st_ivas->ini_frame > 0 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate && ivas_total_brate > IVAS_SID_4k4 ) +#endif { if ( ( error = ivas_sba_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) { @@ -154,7 +158,11 @@ ivas_error ivas_dec_setup( if ( st_ivas->ini_frame > 0 ) { /* reconfigure in case a change of operation mode is detected */ +#ifdef ALIGN_SID_SIZE + if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) ) +#else if ( ( ivas_total_brate > IVAS_SID_4k4 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) ) +#endif { if ( st_ivas->ini_active_frame == 0 && ivas_total_brate != FRAME_NO_DATA && ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->nCPE == 1 ) { @@ -213,7 +221,11 @@ ivas_error ivas_dec_setup( } } } +#ifdef ALIGN_SID_SIZE + else if ( ivas_total_brate == IVAS_SID_5k2 ) +#else else if ( ivas_total_brate == IVAS_SID_4k4 || ivas_total_brate == IVAS_SID_5k ) +#endif { switch ( st_ivas->sid_format ) { @@ -349,7 +361,11 @@ static ivas_error ivas_read_format( break; } } +#ifdef ALIGN_SID_SIZE + else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_5k2 ) +#else else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_4k4 ) +#endif { /* read IVAS format in SID frame */ idx = 0; @@ -402,14 +418,37 @@ static ivas_error ivas_read_format( return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Invalid value %c found in SID format field.", st_ivas->sid_format ); } +#ifdef ALIGN_SID_SIZE + if ( st_ivas->ivas_format == SBA_FORMAT ) + { + int16_t tc_mode_offset; + tc_mode_offset = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 ); + idx = st_ivas->bit_stream[tc_mode_offset]; + // TBD: needs more work for HOA + if ( st_ivas->sba_analysis_order == 0 ) + { + st_ivas->sba_analysis_order = 1; + } + if ( idx == 1 ) + { + st_ivas->sba_mode = SBA_MODE_SPAR; + } + else + { + st_ivas->sba_mode = SBA_MODE_DIRAC; + } + } +#endif + /* reset bitstream handle to avoid BER detection after reading the 2400 kbps for ch0 */ st_ivas->bit_stream += ( *num_bits_read ); ( *num_bits_read ) = 0; } +#ifndef ALIGN_SID_SIZE else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_5k ) { int16_t tc_mode_offset; - tc_mode_offset = ( int16_t )( ivas_total_brate / FRAMES_PER_SEC - 1 ); + tc_mode_offset = (int16_t) ( ivas_total_brate / FRAMES_PER_SEC - 1 ); idx = st_ivas->bit_stream[tc_mode_offset]; // TBD: needs more work for HOA @@ -433,6 +472,7 @@ static ivas_error ivas_read_format( st_ivas->element_mode_init = IVAS_CPE_MDCT; } } +#endif else { /* In SID/NO_DATA frames, use the previous frame IVAS format */ @@ -870,7 +910,7 @@ ivas_error ivas_init_decoder( st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); - ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, ( int16_t )( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + ivas_dirac_config_bands( band_grouping, IVAS_MAX_NUM_BANDS, (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0 ); } } diff --git a/lib_dec/ivas_ism_metadata_dec.c b/lib_dec/ivas_ism_metadata_dec.c index 9d940705f3ca7467b5eeedecdca94f327a04ccfc..dee9b6489f52ee915d1dce489ff3d3a72569daf3 100644 --- a/lib_dec/ivas_ism_metadata_dec.c +++ b/lib_dec/ivas_ism_metadata_dec.c @@ -78,7 +78,11 @@ ivas_error ivas_ism_metadata_dec( wmops_sub_start( "ism_meta_dec" ); +#ifdef ALIGN_SID_SIZE + if ( ism_total_brate == IVAS_SID_5k2 || ism_total_brate == FRAME_NO_DATA ) +#else if ( ism_total_brate == IVAS_SID_4k4 || ism_total_brate == FRAME_NO_DATA ) +#endif { /* no metadata decoding in CNG */ for ( ch = 0; ch < *nchan_transport; ch++ ) @@ -87,7 +91,11 @@ ivas_error ivas_ism_metadata_dec( } /* set padding bits as metadata bits to keep later bitrate checks valid */ +#ifdef ALIGN_SID_SIZE + nb_bits_metadata[0] = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC; +#else nb_bits_metadata[0] = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC; +#endif #ifdef DEBUGGING /* sanity check */ diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 108d4068452309a13a8768da2a142432e974dbc7..d394c3c72949329d3f7f260814ae9e2c425cb675 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1027,7 +1027,11 @@ ivas_error ivas_ism_dec_config( /* store last frame ISM mode */ last_ism_mode = st_ivas->ism_mode; +#ifdef ALIGN_SID_SIZE + if ( !st_ivas->bfi && ivas_total_brate != IVAS_SID_5k2 && ivas_total_brate != FRAME_NO_DATA ) +#else if ( !st_ivas->bfi && ivas_total_brate != IVAS_SID_4k4 && ivas_total_brate != FRAME_NO_DATA ) +#endif { /* select ISM format mode */ st_ivas->ism_mode = ivas_ism_mode_select( num_obj, ivas_total_brate ); @@ -1052,7 +1056,11 @@ ivas_error ivas_ism_dec_config( } } } +#ifdef ALIGN_SID_SIZE + else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_5k2 ) +#else else if ( !st_ivas->bfi && ivas_total_brate == IVAS_SID_4k4 ) +#endif { st_ivas->nchan_transport = num_obj; } diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 91b79a614eaaef7db892df265c1b0e081c58fafc..b4aa18f2a17a0beeb1cdca50f972a8b37e46003a 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -115,7 +115,11 @@ ivas_error ivas_masa_decode( *nb_bits_read = 0; next_bit_pos_orig = st->next_bit_pos; +#ifdef ALIGN_SID_SIZE + if ( masa_brate == IVAS_SID_5k2 ) +#else if ( masa_brate == IVAS_SID_4k4 ) +#endif { st->next_bit_pos = (int16_t) ( ( masa_brate / FRAMES_PER_SEC ) - 1 - SID_FORMAT_NBITS ); } @@ -124,7 +128,11 @@ ivas_error ivas_masa_decode( st->next_bit_pos = (int16_t) ( ( masa_brate / FRAMES_PER_SEC ) - 1 ); } +#ifdef ALIGN_SID_SIZE + if ( !st->bfi && ivas_total_brate > IVAS_SID_5k2 ) +#else if ( !st->bfi && ivas_total_brate > IVAS_SID_4k4 ) +#endif { if ( !( ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA ) ) { @@ -216,7 +224,11 @@ ivas_error ivas_masa_decode( replicate_subframes( hQMetaData ); } } +#ifdef ALIGN_SID_SIZE + else if ( !st->bfi && ivas_format == MASA_FORMAT && ivas_total_brate == IVAS_SID_5k2 ) +#else else if ( !st->bfi && ivas_format == MASA_FORMAT && ivas_total_brate == IVAS_SID_4k4 ) +#endif { if ( hQMetaData->q_direction == NULL ) { @@ -229,7 +241,11 @@ ivas_error ivas_masa_decode( ivas_masa_set_elements( ivas_total_brate, st_ivas->mc_mode, st_ivas->nchan_transport, hQMetaData, &st_ivas->element_mode_init, &st_ivas->nSCE, &st_ivas->nCPE ); +#ifdef ALIGN_SID_SIZE + hQMetaData->metadata_max_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC; +#else hQMetaData->metadata_max_bits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC; +#endif if ( ( error = ivas_qmetadata_allocate_memory( hQMetaData, 5, 1, 0 ) ) != IVAS_ERR_OK ) { @@ -285,7 +301,11 @@ ivas_error ivas_masa_decode( { st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = ivas_total_brate < MASA_STEREO_MIN_BITRATE ? 1 : 0; +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate <= IVAS_SID_5k2 ) +#else if ( ivas_total_brate <= IVAS_SID_4k4 ) +#endif { st_ivas->hCPE[0]->hStereoDft->hConfig->force_mono_transmission = 0; } @@ -295,11 +315,19 @@ ivas_error ivas_masa_decode( { st_ivas->hCPE[0]->hCoreCoder[0]->masa_sid_format = 0; +#ifdef ALIGN_SID_SIZE + if ( st_ivas->hDecoderConfig->last_ivas_total_brate <= IVAS_SID_5k2 ) +#else if ( st_ivas->hDecoderConfig->last_ivas_total_brate <= IVAS_SID_4k4 ) +#endif { st_ivas->hCPE[0]->hCoreCoder[0]->masa_sid_format = 1; +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate >= IVAS_SID_5k2 ) +#else if ( ivas_total_brate >= IVAS_SID_4k4 ) +#endif { st_ivas->hCPE[0]->element_brate = ivas_total_brate; } @@ -479,7 +507,11 @@ void ivas_masa_prerender( const int16_t output_frame /* i : output frame length per channel */ ) { +#ifdef ALIGN_SID_SIZE + if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nchan_transport == 2 && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_5k2 ) +#else if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->nchan_transport == 2 && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_4k4 ) +#endif { if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) { diff --git a/lib_dec/ivas_output_init.c b/lib_dec/ivas_output_init.c index af74b7571c31ac73d73441469b87e9d37dd7cf58..e1d96ff57d8924f6225f1e4ebd0ea1d05daf6595 100644 --- a/lib_dec/ivas_output_init.c +++ b/lib_dec/ivas_output_init.c @@ -530,7 +530,11 @@ void ivas_renderer_select( { *renderer_type = RENDERER_DISABLE; } +#ifdef ALIGN_SID_SIZE + else if ( ( st_ivas->ivas_format == MASA_FORMAT && output_config == AUDIO_CONFIG_MONO && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_5k2 ) ) +#else else if ( ( st_ivas->ivas_format == MASA_FORMAT && output_config == AUDIO_CONFIG_MONO && st_ivas->hDecoderConfig->ivas_total_brate < MASA_STEREO_MIN_BITRATE && st_ivas->hDecoderConfig->ivas_total_brate > IVAS_SID_4k4 ) ) +#endif { *renderer_type = RENDERER_DISABLE; } diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 2270d32eba2a7a0f78a265d116fe4f6515e17c26..15f33799d6db0a11a0b6be5b8b72720991ebe135 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -721,17 +721,32 @@ int16_t ivas_qmetadata_dec_sid_decode( { if ( sba_mode == SBA_MODE_SPAR ) { +#ifdef ALIGN_SID_SIZE + /* TODO: still use old sid frame size to keep bitexactness */ + metadata_sid_bits = (int16_t) ( 5000 /*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * 18 ) - 1; /* -1 for inactive mode header bit*/ +#else metadata_sid_bits = (int16_t) ( IVAS_SID_5k - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * 18 ) - 1; /* -1 for inactive mode header bit*/ +#endif } else { /* keep 13.2 and 16.4 sid bitrate as 4.4 kbps for now*/ +#ifdef ALIGN_SID_SIZE + /* TODO: still use old sid frame size to keep bitexactness */ + metadata_sid_bits = ( 4400 /*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#else metadata_sid_bits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#endif } } else { +#ifdef ALIGN_SID_SIZE + /* TODO: still use old sid frame size to keep bitexactness */ + metadata_sid_bits = ( 4400 /*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#else metadata_sid_bits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#endif } start_index = *index; @@ -850,6 +865,20 @@ int16_t ivas_qmetadata_dec_sid_decode( } } } +#ifdef ALIGN_SID_SIZE + /* TODO: temporary hack to keep BE */ + if ( ivas_format == SBA_FORMAT ) + { + if ( sba_mode != SBA_MODE_SPAR ) + { + metadata_sid_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - 1; /* -1 for spar/dirac indicator*/ + } + } + else + { + metadata_sid_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + } +#endif /*Read filling bits*/ while ( start_index - *index < metadata_sid_bits ) diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 2eebf6967a7353ffd6e68cd4d8304353501e28cb..204b91b89dfdb44cf5a4f1d0bdd8e76d6b60ed13 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -523,8 +523,11 @@ ivas_error ivas_sba_dec_reconfigure( } } - if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && - ( last_ivas_total_brate > IVAS_SID_4k4 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) +#ifdef ALIGN_SID_SIZE + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_5k2 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) +#else + if ( st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_SBA_LINEAR_DEC && ( last_ivas_total_brate > IVAS_SID_4k4 || nchan_transport != nchan_transport_old ) && ( st_ivas->sba_mode != SBA_MODE_SPAR ) ) +#endif { if ( st_ivas->hDirAC != NULL ) { @@ -896,7 +899,11 @@ ivas_error ivas_sba_dec_reconfigure( } /* special case, if the decoder goes from 1TC DTX to 2TC active frame (in case the bitstream started with an SBA SID frame), allocate DTX memories */ +#ifdef ALIGN_SID_SIZE + if ( last_ivas_total_brate <= IVAS_SID_5k2 && st_ivas->nCPE >= 1 ) +#else if ( last_ivas_total_brate <= IVAS_SID_4k4 && st_ivas->nCPE >= 1 ) +#endif { if ( ( error = initMdctStereoDtxData( st_ivas->hCPE[0] ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index 5b83a41f8155b3d71f251ef8ab96a0561de2502c..b3a73706df11a9f1d72428aae1e7bcf4852cb34f 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -82,7 +82,11 @@ ivas_error ivas_sce_dec( *-----------------------------------------------------------------*/ /* set total_brate - needed in DTX */ +#ifdef ALIGN_SID_SIZE + if ( !st_ivas->bfi && ( ivas_total_brate == IVAS_SID_5k2 ) ) +#else if ( !st_ivas->bfi && ( ivas_total_brate == IVAS_SID_4k4 || ivas_total_brate == IVAS_SID_5k ) ) +#endif { st->total_brate = ivas_total_brate - nb_bits_metadata * FRAMES_PER_SEC; assert( st->total_brate == SID_2k40 && "SCE SID must be 2.4kbps!" ); @@ -91,7 +95,11 @@ ivas_error ivas_sce_dec( { st->total_brate = ivas_total_brate; } +#ifdef ALIGN_SID_SIZE + else if ( !st_ivas->bfi && ( last_ivas_total_brate <= SID_2k40 || last_ivas_total_brate == IVAS_SID_5k2 ) ) +#else else if ( !st_ivas->bfi && ( last_ivas_total_brate <= SID_2k40 || last_ivas_total_brate == IVAS_SID_4k4 ) ) +#endif { st->total_brate = hSCE->element_brate - nb_bits_metadata * FRAMES_PER_SEC; } @@ -161,7 +169,11 @@ ivas_error ivas_sce_dec( } /* set "total_brate" */ +#ifdef ALIGN_SID_SIZE + if ( !st_ivas->bfi && ( ivas_total_brate == IVAS_SID_5k2 ) ) +#else if ( !st_ivas->bfi && ( ivas_total_brate == IVAS_SID_4k4 || ivas_total_brate == IVAS_SID_5k ) ) +#endif { st->total_brate = ivas_total_brate - nb_bits_metadata * FRAMES_PER_SEC; } diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index 493ca539a0a0d7452eb486b98fb0a807468ba294..2e48c11745802f409b34bc2085df6f8e8e7b2c46 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -241,6 +241,12 @@ ivas_error ivas_spar_dec( next_bit_pos_orig = st0->next_bit_pos; last_bit_pos = (int16_t) ( ( hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 ); +#ifdef ALIGN_SID_SIZE + if ( !st0->bfi && hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 ) + { + last_bit_pos -= SID_FORMAT_NBITS; + } +#endif nb_bits_read_orig = *nb_bits_read; last_bit_pos -= nb_bits_read_orig; @@ -260,6 +266,17 @@ ivas_error ivas_spar_dec( st0->bit_stream = bit_stream_orig; st0->next_bit_pos = next_bit_pos_orig; +#ifdef ALIGN_SID_SIZE + if ( !st0->bfi && hDecoderConfig->ivas_total_brate == IVAS_SID_5k2 ) + { + int16_t zero_pad_bits; + *nb_bits_read += SID_FORMAT_NBITS; + zero_pad_bits = (int16_t) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - *nb_bits_read; + assert( zero_pad_bits <= 1 ); + *nb_bits_read += zero_pad_bits; + } +#endif + wmops_sub_end(); return error; @@ -628,7 +645,11 @@ static void ivas_spar_dec_MD( if ( ivas_total_brate > FRAME_NO_DATA && !bfi ) { +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate > IVAS_SID_5k2 ) +#else if ( ivas_total_brate > IVAS_SID_5k ) +#endif { ivas_parse_spar_header( hDecoderConfig->ivas_total_brate, sba_order, st0, &table_idx ); @@ -662,7 +683,11 @@ static void ivas_spar_dec_MD( * Read AGC bits *---------------------------------------------------------------------*/ +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate > IVAS_SID_5k2 && !bfi && hSpar->hMdDec->dtx_vad ) +#else if ( ivas_total_brate > IVAS_SID_5k && !bfi && hSpar->hMdDec->dtx_vad ) +#endif { hSpar->AGC_flag = get_next_indice( st0, 1 ); @@ -673,7 +698,11 @@ static void ivas_spar_dec_MD( * MD smoothing *---------------------------------------------------------------------*/ +#ifdef ALIGN_SID_SIZE + if ( st0->m_old_frame_type == ZERO_FRAME && ivas_total_brate == IVAS_SID_5k2 && st0->prev_bfi == 0 && hSpar->hMdDec->spar_md_cfg.nchan_transport == 1 ) +#else if ( st0->m_old_frame_type == ZERO_FRAME && ivas_total_brate == IVAS_SID_5k && st0->prev_bfi == 0 && hSpar->hMdDec->spar_md_cfg.nchan_transport == 1 ) +#endif { ivas_spar_setup_md_smoothing( hSpar->hMdDec, num_bands_out ); } diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c index 36954e110caf1cbbe74632e639a39e52ec504709..f4ac432bf4b40cce9f16b961c36f8e82854d8895 100644 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -1448,7 +1448,11 @@ static void ivas_spar_dec_parse_md_bs( if ( hMdDec->spar_md_cfg.gen_bs == 1 ) { +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate > IVAS_SID_5k2 ) +#else if ( ivas_total_brate > IVAS_SID_5k ) +#endif { if ( hMdDec->spar_md_cfg.quant_strat_bits > 0 ) { diff --git a/lib_dec/ivas_stereo_cng_dec.c b/lib_dec/ivas_stereo_cng_dec.c index 05e9222ddbde2aa767c01199a1fe420d083448fa..fea12053c3434b33cb37ac49ddca29c76f20b4f1 100644 --- a/lib_dec/ivas_stereo_cng_dec.c +++ b/lib_dec/ivas_stereo_cng_dec.c @@ -90,7 +90,12 @@ void stereo_dft_dec_sid_coh( int16_t bits_tmp; int16_t b; +#ifdef ALIGN_SID_SIZE + /* TODO: still use old number of bits to keep bitexactness in output */ + nr_of_sid_stereo_bits = ( 4400/*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#else nr_of_sid_stereo_bits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#endif /* If the coherence is not encoded due to lack of bits set alpha to zero which leads to that the coherence */ /* from the previous frame is used. */ @@ -173,6 +178,9 @@ void stereo_dft_dec_sid_coh( ( *nb_bits )++; } +#ifdef ALIGN_SID_SIZE + dtx_read_padding_bits( st, ( IVAS_SID_5k2 - 4400 ) / FRAMES_PER_SEC ); +#endif return; } @@ -653,9 +661,17 @@ void stereo_dtf_cng( hCPE->hStereoCng->nr_dft_frames++; } +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate <= IVAS_SID_5k2 ) +#else if ( ivas_total_brate <= IVAS_SID_4k4 ) +#endif { +#ifdef ALIGN_SID_SIZE + if ( hCPE->hStereoCng->nr_sid_frames < SID_INIT && ivas_total_brate == IVAS_SID_5k2 ) +#else if ( hCPE->hStereoCng->nr_sid_frames < SID_INIT && ivas_total_brate == IVAS_SID_4k4 ) +#endif { hCPE->hStereoCng->nr_sid_frames++; } @@ -707,7 +723,11 @@ void stereo_cng_dec_update( if ( hCPE->element_mode == IVAS_CPE_DFT ) { +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate == IVAS_SID_5k2 || ivas_total_brate == FRAME_NO_DATA ) +#else if ( ivas_total_brate == IVAS_SID_4k4 || ivas_total_brate == FRAME_NO_DATA ) +#endif { hCPE->hStereoCng->prev_sid_nodata = 1; } diff --git a/lib_dec/ivas_stereo_dft_dec.c b/lib_dec/ivas_stereo_dft_dec.c index 074efaa1a262340aa39753d0dfff02cea7b18abe..b0db814511f00e57be52c8e1c6d793918f493735 100644 --- a/lib_dec/ivas_stereo_dft_dec.c +++ b/lib_dec/ivas_stereo_dft_dec.c @@ -1746,7 +1746,11 @@ void stereo_dft_dec_read_BS( * Initialization *-----------------------------------------------------------------*/ +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate == IVAS_SID_5k2 ) +#else if ( ivas_total_brate == IVAS_SID_4k4 ) +#endif { if ( ivas_format == MASA_FORMAT ) { @@ -1760,7 +1764,11 @@ void stereo_dft_dec_read_BS( hStereoDft->frame_nodata = 0; hStereoDft->frame_sid_nodata = 1; hStereoDft->frame_sid = 1; +#ifdef ALIGN_SID_SIZE + *nb_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#else *nb_bits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#endif } } else if ( ivas_total_brate == FRAME_NO_DATA ) @@ -1803,7 +1811,11 @@ void stereo_dft_dec_read_BS( k_offset = STEREO_DFT_OFFSET; N_div = STEREO_DFT_NBDIV; +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate > IVAS_SID_5k2 ) +#else if ( ivas_total_brate > IVAS_SID_4k4 ) +#endif { mvr2r( hStereoDft->side_gain + 2 * STEREO_DFT_BAND_MAX, sg_tmp, STEREO_DFT_BAND_MAX ); mvr2r( hStereoDft->res_pred_gain + 2 * STEREO_DFT_BAND_MAX, res_pred_gain_tmp, STEREO_DFT_BAND_MAX ); @@ -1893,7 +1905,11 @@ void stereo_dft_dec_read_BS( fprintf( pF, "ITD: %d ", hStereoDft->hConfig->itd_mode ); #endif +#ifdef ALIGN_SID_SIZE + if ( !( ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_5k2 ) ) +#else if ( !( ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_4k4 ) ) +#endif { /*------------------------------------------------------------------* * read Side gains @@ -1974,7 +1990,11 @@ void stereo_dft_dec_read_BS( #endif } } +#ifdef ALIGN_SID_SIZE + else if ( *nb_bits <= ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - STEREO_DFT_ITD_MODE_NBITS - STEREO_DFT_SID_ITD_NBITS - 1 - SID_FORMAT_NBITS ) ) +#else else if ( *nb_bits <= ( ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - STEREO_DFT_ITD_MODE_NBITS - STEREO_DFT_SID_ITD_NBITS - 1 - SID_FORMAT_NBITS ) ) +#endif { itd_mode = get_next_indice( st, STEREO_DFT_ITD_MODE_NBITS ); ( *nb_bits ) += STEREO_DFT_ITD_MODE_NBITS; /*ITD mode flag: 1bit*/ @@ -2016,7 +2036,11 @@ void stereo_dft_dec_read_BS( stereo_dft_dequantize_ipd( &ind1_ipd[0], hStereoDft->gipd + ( k + k_offset ), 1, STEREO_DFT_GIPD_NBITS ); } } +#ifdef ALIGN_SID_SIZE + else if ( *nb_bits <= ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS - SID_FORMAT_NBITS ) ) +#else else if ( *nb_bits <= ( ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS - SID_FORMAT_NBITS ) ) +#endif { /* SID frame, only read IPD only if enough bits left in bitstream */ hStereoDft->no_ipd_flag = st->bit_stream[nb]; @@ -2177,7 +2201,11 @@ void stereo_dft_dec_read_BS( #endif } +#ifdef ALIGN_SID_SIZE + if ( !( ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_5k2 ) ) +#else if ( !( ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_4k4 ) ) +#endif { if ( hStereoDft->side_gain_flag_1 != 2 ) { @@ -2185,7 +2213,11 @@ void stereo_dft_dec_read_BS( } } +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate > IVAS_SID_5k2 ) +#else if ( ivas_total_brate > IVAS_SID_4k4 ) +#endif { hStereoDft->recovery_flg = stereo_dft_sg_recovery( hStereoDft ); @@ -2252,12 +2284,20 @@ void stereo_dft_dec_read_BS( #endif } +#ifdef ALIGN_SID_SIZE + if ( hStereoDft->frame_sid && !( ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_5k2 ) ) +#else if ( hStereoDft->frame_sid && !( ivas_format == MASA_FORMAT && ivas_total_brate <= IVAS_SID_4k4 ) ) +#endif { stereo_dft_dec_sid_coh( st, hStereoDft->nbands, coh, nb_bits ); } +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate == IVAS_SID_5k2 && ivas_format != MASA_FORMAT ) +#else if ( ivas_total_brate == IVAS_SID_4k4 && ivas_format != MASA_FORMAT ) +#endif { *nb_bits = (int16_t) ( ( element_brate - SID_2k40 ) / FRAMES_PER_SEC ); /* => hCPE->hCoreCoder[0]->total_brate = SID_2k40; */ } diff --git a/lib_dec/ivas_stereo_mdct_stereo_dec.c b/lib_dec/ivas_stereo_mdct_stereo_dec.c index 064784e7055282c764629b4a3a5236480f4a9beb..10b9688be297aedef6a09bfbb0f5dc92c2e18f85 100644 --- a/lib_dec/ivas_stereo_mdct_stereo_dec.c +++ b/lib_dec/ivas_stereo_mdct_stereo_dec.c @@ -559,13 +559,21 @@ void updateBuffersForDmxMdctStereo( sts[1] = hCPE->hCoreCoder[1]; /* synch buffers for inactive frames, but not for transition frames */ +#ifdef ALIGN_SID_SIZE + if ( hCPE->last_element_brate <= IVAS_SID_5k2 ) +#else if ( hCPE->last_element_brate <= IVAS_SID_4k4 ) +#endif { mvr2r( output[0], output[1], output_frame ); mvr2r( synth[0], synth[1], output_frame ); } +#ifdef ALIGN_SID_SIZE + if ( hCPE->element_brate == IVAS_SID_5k2 && hCPE->last_element_brate > IVAS_SID_5k2 ) +#else if ( hCPE->element_brate == IVAS_SID_4k4 && hCPE->last_element_brate > IVAS_SID_4k4 ) +#endif { /* in the first SID frame after an active frame, create mid noise shape here, in SID frames that follow inactive frames, it is done directly in the SID decoding since the mid shape is being used in CNG then */ for ( int16_t p = 0; p < sts[0]->hFdCngDec->hFdCngCom->npart; p++ ) @@ -575,7 +583,11 @@ void updateBuffersForDmxMdctStereo( } /* for transition of active->inactive frame, apply passive downmix on buffers */ +#ifdef ALIGN_SID_SIZE + if ( hCPE->last_element_brate <= IVAS_SID_5k2 ) +#else if ( hCPE->last_element_brate <= IVAS_SID_4k4 ) +#endif { delta = 1; if ( output_frame == L_FRAME16k ) @@ -641,13 +653,21 @@ void applyDmxMdctStereo( fade = 1.f; dmx_len = output_frame; +#ifdef ALIGN_SID_SIZE + if ( hCPE->last_element_brate <= IVAS_SID_5k2 ) +#else if ( hCPE->last_element_brate <= IVAS_SID_4k4 ) +#endif { crossfade_len = NS2SA( hCPE->hCoreCoder[0]->output_Fs, IVAS_DEC_DELAY_NS - DELAY_CLDFB_NS ); step /= crossfade_len; } /* for first inactive CNG frame after active decoding we have to do a fade-OUT FROM the passive DMX */ +#ifdef ALIGN_SID_SIZE + else if ( hCPE->element_brate <= IVAS_SID_5k2 && hCPE->last_element_brate > IVAS_SID_5k2 ) +#else else if ( hCPE->element_brate <= IVAS_SID_4k4 && hCPE->last_element_brate > IVAS_SID_4k4 ) +#endif { crossfade_len = output_frame / 4; step /= -crossfade_len; diff --git a/lib_dec/ivas_stereo_switching_dec.c b/lib_dec/ivas_stereo_switching_dec.c index b2b788956922c6ef04ee9a07cf9fda9f6a818e35..80736dd425c13b05baa2fb0d917bd32095faec12 100644 --- a/lib_dec/ivas_stereo_switching_dec.c +++ b/lib_dec/ivas_stereo_switching_dec.c @@ -832,7 +832,11 @@ ivas_error stereo_memory_dec( if ( ivas_format == STEREO_FORMAT && hCPE->element_mode == IVAS_CPE_MDCT ) { +#ifdef ALIGN_SID_SIZE + if ( hCPE->element_brate <= MAX_MDCT_ITD_BRATE && ivas_total_brate > IVAS_SID_5k2 ) +#else if ( hCPE->element_brate <= MAX_MDCT_ITD_BRATE && ivas_total_brate > IVAS_SID_4k4 ) +#endif { if ( hCPE->hStereoMdct->use_itd == 0 ) { @@ -852,13 +856,21 @@ ivas_error stereo_memory_dec( else { /* de-allocate TCA data structure */ +#ifdef ALIGN_SID_SIZE + if ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate > IVAS_SID_5k2 && hCPE->hStereoTCA != NULL ) +#else if ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate > IVAS_SID_4k4 && hCPE->hStereoTCA != NULL ) +#endif { count_free( hCPE->hStereoTCA ); hCPE->hStereoTCA = NULL; hCPE->hStereoMdct->use_itd = 0; } +#ifdef ALIGN_SID_SIZE + else if ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate <= IVAS_SID_5k2 ) +#else else if ( hCPE->hStereoMdct->use_itd == 1 && ivas_total_brate <= IVAS_SID_4k4 ) +#endif { hCPE->hStereoMdct->itd = 0.0f; } @@ -1011,7 +1023,11 @@ void synchro_synthesis( if ( use_cldfb_for_last_dft ) { +#ifdef ALIGN_SID_SIZE + if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_TD && ( ivas_total_brate > IVAS_SID_5k2 || hCPE->nchan_out == 2 ) ) +#else if ( hCPE->element_mode == IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_TD && ( ivas_total_brate > IVAS_SID_4k4 || hCPE->nchan_out == 2 ) ) +#endif { stereo_tca_scale_R_channel( hCPE, output[0], output_frame ); } @@ -1349,7 +1365,11 @@ void stereo_switching_dec( mvr2r( hCPE->input_mem[n], hCPE->output_mem[n], dft32ms_ovl ); } +#ifdef ALIGN_SID_SIZE + if ( ivas_total_brate > IVAS_SID_5k2 || n == 0 || hCPE->last_element_mode != IVAS_CPE_TD || hCPE->nchan_out == 1 ) +#else if ( ivas_total_brate > IVAS_SID_4k4 || n == 0 || hCPE->last_element_mode != IVAS_CPE_TD || hCPE->nchan_out == 1 ) +#endif { for ( i = 0; i < dft32ms_ovl; i++ ) { @@ -1423,7 +1443,11 @@ void stereo_switching_dec( /* no secondary channel in the previous frame -> memory resets */ if ( hCPE->element_mode > IVAS_CPE_DFT && hCPE->last_element_mode == IVAS_CPE_DFT ) { +#ifdef ALIGN_SID_SIZE + if ( hCPE->last_element_brate <= IVAS_SID_5k2 && hCPE->nchan_out == 2 ) +#else if ( hCPE->last_element_brate <= IVAS_SID_4k4 && hCPE->nchan_out == 2 ) +#endif { /* reset CLDFB memories */ cldfb_reset_memory( sts[0]->cldfbAna ); diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index f4566b4c50dda38fe749405b45f9a0a283ee5d43..52e54a56637df576519cf2d86452673ef8142ed9 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -1167,7 +1167,11 @@ static bool isSidFrame( { return true; /* EVS SID */ } +#ifdef ALIGN_SID_SIZE + else if ( size == IVAS_SID_5k2 / FRAMES_PER_SEC ) +#else else if ( size == IVAS_SID_4k4 / FRAMES_PER_SEC ) +#endif { return true; /* IVAS SID */ } diff --git a/lib_enc/fd_cng_enc.c b/lib_enc/fd_cng_enc.c index c2dfb1969f421564dbdf51aad67fbeb1802d62b2..670a202df221bf594b739c9f07bbfbeeb048f82d 100644 --- a/lib_enc/fd_cng_enc.c +++ b/lib_enc/fd_cng_enc.c @@ -1128,6 +1128,11 @@ void FdCngEncodeMDCTStereoSID( push_indice( sts[ch]->hBstr, IND_ENERGY, gain_idx[ch], 7 ); } +#ifdef ALIGN_SID_SIZE + /* pad with zeros to reach common SID frame size */ + push_indice( sts[1]->hBstr, IND_ENERGY, 0, ( IVAS_SID_5k2 - 4400 ) / FRAMES_PER_SEC ); +#endif + return; } diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 2ee9f7b71f336070148e7ad996136627d7e0818f..df94fe44ab0fd946240b6ea93cbac7636ff28cf6 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -462,7 +462,11 @@ ivas_error ivas_cpe_enc( { if ( hCPE->element_mode == IVAS_CPE_DFT || hCPE->element_mode == IVAS_CPE_TD ) { +#ifdef ALIGN_SID_SIZE + reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata, st_ivas->sba_mode ); +#else reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata, st_ivas->sba_mode, hCPE->element_mode ); +#endif } } @@ -474,7 +478,11 @@ ivas_error ivas_cpe_enc( /* Reset metadata */ if ( sts[0]->cng_sba_flag || ( ivas_format == SBA_FORMAT && st_ivas->sba_mode == SBA_MODE_SPAR ) ) { +#ifdef ALIGN_SID_SIZE + reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata, st_ivas->sba_mode ); +#else reset_metadata_spatial( ivas_format, hCPE->hMetaData, hCPE->element_brate, &tmp, sts[0]->core_brate, nb_bits_metadata, st_ivas->sba_mode, hCPE->element_mode ); +#endif } } @@ -543,7 +551,11 @@ ivas_error ivas_cpe_enc( * Write IVAS format signaling in SID frames *----------------------------------------------------------------*/ +#ifdef ALIGN_SID_SIZE + if ( sts[0]->core_brate == SID_2k40 ) +#else if ( sts[0]->core_brate == SID_2k40 && ( ivas_format != SBA_FORMAT || st_ivas->sba_mode != SBA_MODE_SPAR ) ) +#endif { ivas_write_format_sid( ivas_format, hCPE->element_mode, sts[0]->hBstr ); } @@ -562,7 +574,11 @@ ivas_error ivas_cpe_enc( /* Reconfigure DFT Stereo for inactive frames */ if ( sts[0]->core_brate == SID_2k40 ) { +#ifdef ALIGN_SID_SIZE + stereo_dft_config( hCPE->hStereoDft->hConfig, IVAS_SID_5k2, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); +#else stereo_dft_config( hCPE->hStereoDft->hConfig, IVAS_SID_4k4, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal ); +#endif } else { @@ -606,7 +622,11 @@ ivas_error ivas_cpe_enc( if ( sts[0]->core_brate == FRAME_NO_DATA || sts[0]->core_brate == SID_2k40 ) { +#ifdef ALIGN_SID_SIZE + assert( ( nb_bits <= ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS ) ) && "Stereo DFT CNG: bit budget is violated" ); +#else assert( ( nb_bits <= ( ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS ) ) && "Stereo DFT CNG: bit budget is violated" ); +#endif } else { diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 557cb109ca235e2c84ba3c72cf9d63831e12b447..754aa6d57ccc49dfcff7e62e07e1daaab2c3a1ae 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -429,6 +429,10 @@ void ivas_dirac_enc( } else { +#ifdef ALIGN_SID_SIZE + /*indicate whether SPAR or DiRAC mode*/ + push_next_indice( hMetaData, 0, 1 ); +#endif /* encode SID parameters */ ivas_qmetadata_enc_sid_encode( hMetaData, hQMetaData, -1, SBA_FORMAT, diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index 2653829d13c272352c4bd2cdc383d40d955aff16..2433c01802e67a6a828d0c22792bdcb5f0a70eae 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -214,7 +214,11 @@ ivas_error ivas_ism_enc( ivas_write_format_sid( st_ivas->hEncoderConfig->ivas_format, IVAS_SCE, st->hBstr ); /* write unused bits */ +#ifdef ALIGN_SID_SIZE + nBits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#else nBits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#endif while ( nBits > 0 ) { i = min( nBits, 16 ); diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 613d59f1be0cc5fb73c11db07fe88f944b8e7d05..6042c9e10a44a08e2e69f2097152658845c5633e 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -684,17 +684,32 @@ void ivas_qmetadata_enc_sid_encode( { if ( sba_mode == SBA_MODE_SPAR ) { +#ifdef ALIGN_SID_SIZE + /* TODO: still use old sid frame size to keep bitexactness */ + metadata_sid_bits = (int16_t) ( 5000 /*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - 1; /* -1 for inactive mode header bit*/ +#else metadata_sid_bits = (int16_t) ( IVAS_SID_5k - SID_2k40 ) / FRAMES_PER_SEC - ( SPAR_DTX_BANDS * SPAR_SID_BITS_TAR_PER_BAND ) - 1; /* -1 for inactive mode header bit*/ +#endif } else { /* keep 13.2 and 16.4 SID bitrate as 4.4 kbps for now*/ +#ifdef ALIGN_SID_SIZE + /* TODO: still use old sid frame size to keep bitexactness */ + metadata_sid_bits = ( 4400 /*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#else metadata_sid_bits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#endif } } else { +#ifdef ALIGN_SID_SIZE + /* TODO: still use old sid frame size to keep bitexactness */ + metadata_sid_bits = ( 4400 /*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#else metadata_sid_bits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#endif } #ifdef DEBUG_MODE_QMETADATA @@ -873,6 +888,22 @@ void ivas_qmetadata_enc_sid_encode( } #endif +#ifdef ALIGN_SID_SIZE + /* TODO: temporary to keep BE */ + if ( ivas_format == SBA_FORMAT ) + { + if ( sba_mode != SBA_MODE_SPAR ) + { + /* keep 13.2 and 16.4 SID bitrate as 4.4 kbps for now*/ + metadata_sid_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - 1; /* -1 for spar/dirac indicator*/ + } + } + else + { + metadata_sid_bits = ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + } +#endif + /* fill bits*/ assert( ( hMetaData->nb_bits_tot - bit_pos_start ) <= metadata_sid_bits && "Too many written bits!" ); while ( ( hMetaData->nb_bits_tot - bit_pos_start ) < metadata_sid_bits ) @@ -896,11 +927,18 @@ void reset_metadata_spatial( int32_t *total_brate, /* o : total bitrate */ const int32_t core_brate, /* i : core bitrate */ const int16_t nb_bits_metadata, /* i : number of meatdata bits */ - const SBA_MODE sba_mode, /* i : SBA mode */ - const int16_t element_mode /* i : element mode */ +#ifndef ALIGN_SID_SIZE + const SBA_MODE sba_mode, /* i : SBA mode */ + const int16_t element_mode /* i : element mode */ +#else + const SBA_MODE sba_mode /* i : SBA mode */ +#endif ) { int16_t i, next_ind_sid, last_ind_sid; +#ifdef ALIGN_SID_SIZE + int16_t metadata_sid_bits; +#endif if ( core_brate == SID_2k40 || core_brate == FRAME_NO_DATA ) { @@ -909,6 +947,14 @@ void reset_metadata_spatial( if ( sba_mode == SBA_MODE_SPAR ) { assert( hMetaData->ind_list[0].nb_bits == 1 ); +#ifdef ALIGN_SID_SIZE + hMetaData->ind_list[0].value = 1; + metadata_sid_bits = (int16_t) ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; + while ( hMetaData->nb_bits_tot < metadata_sid_bits ) + { + push_next_indice( hMetaData, 0, 1 ); /*fill bit*/ + } +#else if ( element_mode > IVAS_SCE ) { hMetaData->ind_list[0].value = 1; @@ -917,6 +963,7 @@ void reset_metadata_spatial( { hMetaData->ind_list[0].value = 0; } +#endif } else { @@ -946,7 +993,11 @@ void reset_metadata_spatial( hMetaData->ind_list[i].nb_bits = -1; } hMetaData->last_ind = hMetaData->next_ind; +#ifdef ALIGN_SID_SIZE + assert( ( hMetaData->nb_bits_tot == ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS ) && "Problem of SID metadata in SCE" ); +#else assert( ( hMetaData->nb_bits_tot == ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS ) && "Problem of SID metadata in SCE" ); +#endif } } else diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 942dd14c999b07d44c2e8608ce33633d630a90ea..1657665f99d5780f62202fea80198bf01ebe1b6a 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -199,14 +199,20 @@ ivas_error ivas_sce_enc( * Reset metadata *----------------------------------------------------------------*/ - reset_metadata_spatial( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata, st_ivas->sba_mode, - IVAS_SCE ); +#ifdef ALIGN_SID_SIZE + reset_metadata_spatial( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata, st_ivas->sba_mode ); +#else + reset_metadata_spatial( ivas_format, hSCE->hMetaData, hSCE->element_brate, &st->total_brate, st->core_brate, nb_bits_metadata, st_ivas->sba_mode, IVAS_SCE ); +#endif /*----------------------------------------------------------------* * Write IVAS format signaling in SID frames *----------------------------------------------------------------*/ - +#ifdef ALIGN_SID_SIZE + if ( st->core_brate == SID_2k40 ) +#else if ( st->core_brate == SID_2k40 && ( ivas_format != SBA_FORMAT || st_ivas->sba_mode != SBA_MODE_SPAR ) ) +#endif { ivas_write_format_sid( ivas_format, IVAS_SCE, st->hBstr ); } diff --git a/lib_enc/ivas_stereo_cng_enc.c b/lib_enc/ivas_stereo_cng_enc.c index 860cdbe88ffb782420c8c41456c4abc816e40aa8..5db60b5238def40094c2e0e15630cde942c0f500 100644 --- a/lib_enc/ivas_stereo_cng_enc.c +++ b/lib_enc/ivas_stereo_cng_enc.c @@ -148,7 +148,12 @@ void stereo_dft_enc_sid_coh( int16_t alpha_level; int16_t n; +#ifdef ALIGN_SID_SIZE + /* TODO: still use old number of bits to keep bitexactness in output */ + nr_of_sid_stereo_bits = ( 4400/*IVAS_SID_5k2*/ - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#else nr_of_sid_stereo_bits = ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS; +#endif zeropad = 0; /* Encode coherence vector. Find best fixed predictor by minimizing prediction error on input vector. @@ -303,6 +308,10 @@ void stereo_dft_enc_sid_coh( ( *nb_bits )++; } +#ifdef ALIGN_SID_SIZE + push_next_indice( hBstr, zeropad, ( IVAS_SID_5k2 - 4400 ) / FRAMES_PER_SEC ); +#endif + return; } diff --git a/lib_enc/ivas_stereo_dft_enc.c b/lib_enc/ivas_stereo_dft_enc.c index 2e81bd99bcad47a9a72316bfe147e37fcf423664..402003be6c9a761bdc37efe439e3ee24a009e925 100644 --- a/lib_enc/ivas_stereo_dft_enc.c +++ b/lib_enc/ivas_stereo_dft_enc.c @@ -2317,7 +2317,11 @@ void stereo_dft_enc_write_BS( { stereo_dft_enc_sid_calc_coh( hStereoDft, hCPE->hStereoCng->coh_crossfade, &hCPE->hStereoCng->td_active, &hCPE->hStereoCng->first_SID, cohBand ); +#ifdef ALIGN_SID_SIZE + if ( *nb_bits <= ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_ITD_MODE_NBITS - STEREO_DFT_SID_ITD_NBITS - 1 ) ) +#else if ( *nb_bits <= ( ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_ITD_MODE_NBITS - STEREO_DFT_SID_ITD_NBITS - 1 ) ) +#endif { if ( hStereoDft->hItd->itd[k_offset] != 0 ) { @@ -2393,7 +2397,11 @@ void stereo_dft_enc_write_BS( nb += STEREO_DFT_GIPD_NBITS; } } +#ifdef ALIGN_SID_SIZE + else if ( *nb_bits <= ( ( IVAS_SID_5k2 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS ) ) +#else else if ( *nb_bits <= ( ( IVAS_SID_4k4 - SID_2k40 ) / FRAMES_PER_SEC - SID_FORMAT_NBITS - STEREO_DFT_FLAG_BITS - STEREO_DFT_SID_GIPD_NBITS ) ) +#endif { push_indice( hBstr, IND_STEREO_DFT_NO_IPD_FLAG, hStereoDft->no_ipd_flag, STEREO_DFT_FLAG_BITS ); nb += STEREO_DFT_FLAG_BITS; /*IPD mode flag: 1bit*/