diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index ad871926d001f44a3bea01b9766aeedc512c44ec..4722f322d204a56678e7fa0ce92235d73dcd9d07 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -656,6 +656,13 @@ void ivas_renderer_select( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#ifdef NONBE_1303_REND_GRANULARITY +/*! r: secondary binaural renderer type */ +RENDERER_TYPE ivas_renderer_secondary_select( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +); + +#endif ivas_error ivas_mc_enc_config( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); @@ -885,10 +892,16 @@ TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode( /*! r: render granularity */ int16_t ivas_jbm_dec_get_render_granularity( +#ifdef NONBE_1303_REND_GRANULARITY + const RENDERER_TYPE renderer_type, /* i : renderer type */ + const RENDERER_TYPE renderer_type_sec, /* i : secondary renderer type */ + const int32_t output_Fs /* i : sampling rate */ +#else const RENDERER_TYPE rendererType, /* i : renderer type */ const IVAS_FORMAT ivas_format, /* i : ivas format */ const MC_MODE mc_mode, /* i : MC mode */ const int32_t output_Fs /* i : sampling rate */ +#endif ); ivas_error ivas_jbm_dec_tc_buffer_open( diff --git a/lib_com/options.h b/lib_com/options.h index 407614837e04745d61938600c955880a086bf850..8c8a3c2aabac6b00ea6baef0fba470a10e56e23e 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -181,6 +181,7 @@ #define NONBE_1296_TDREND_ITD_OUT_OF_BOUNDS_ACCESS /* Eri: issue 1296: ITD resampling can occasionally read out of bounds, especially when the requested subframes are short (1.25 ms). Seen for headtracking+JBM. */ #define NONBE_1303_GRANULARITY_OSBA_REND /* VA: issue 1303: Correctly set the granularity in OSBA, Disc mode, and BINAURAL_ROOM_REVERB output */ #define NONBE_1118_EVS_LR_HQ_BITERROR /* VA: issue 1118: fix EVS decoder crash in LR-HQ in case of bit errors */ +#define NONBE_1303_REND_GRANULARITY /* VA: issue 1303: Renderer granularity revision */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 74ea4a34b8efb8c6418870932c36436d71f91531..aac6720870adeffc57f7256c376e544e8dfb385b 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -2126,6 +2126,7 @@ ivas_error ivas_init_decoder( return error; } } +#ifndef NONBE_1303_REND_GRANULARITY granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels( st_ivas ); @@ -2134,6 +2135,7 @@ ivas_error ivas_init_decoder( { return error; } +#endif } else if ( st_ivas->renderer_type == RENDERER_MC ) { @@ -2166,6 +2168,7 @@ ivas_error ivas_init_decoder( } st_ivas->binaural_latency_ns = st_ivas->hCrendWrapper->binaural_latency_ns; +#ifndef NONBE_1303_REND_GRANULARITY if ( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX ) ) { @@ -2189,6 +2192,7 @@ ivas_error ivas_init_decoder( return error; } } +#endif } if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) @@ -2203,7 +2207,7 @@ ivas_error ivas_init_decoder( if ( st_ivas->hOutSetup.output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) { - if ( ( error = ivas_reverb_open( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_reverb_open( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, output_Fs ) ) != IVAS_ERR_OK ) { return error; } @@ -2382,12 +2386,18 @@ ivas_error ivas_init_decoder( *-----------------------------------------------------------------*/ if ( st_ivas->hTcBuffer == NULL ) - { /* no module has yet open the TC buffer, open a default one */ +#ifdef NONBE_1303_REND_GRANULARITY + granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, ivas_renderer_secondary_select( st_ivas ), output_Fs ); + n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels( st_ivas ); + + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, ivas_jbm_dec_get_tc_buffer_mode( st_ivas ), n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, granularity ) ) != IVAS_ERR_OK ) +#else n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels( st_ivas ); if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, ivas_jbm_dec_get_tc_buffer_mode( st_ivas ), n_channels_transport_jbm, n_channels_transport_jbm, n_channels_transport_jbm, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 0438755a31f1aa7e7b7f0e00118af8da5573b71b..e7c793caf3b12202f04b08b34f54f605491ebd19 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -122,6 +122,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); } +#ifndef NONBE_1303_REND_GRANULARITY /* JBM: when granularity goes down (e.g. Discrete ISM with TD Obj Renderer -> ParamISM with binaural fastconv render what still fits in the new granularity */ tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); @@ -138,7 +139,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( return error; } } - +#endif if ( st_ivas->ism_mode != last_ism_mode ) { /* EFAP handle */ @@ -306,7 +307,9 @@ static ivas_error ivas_ism_bitrate_switching_dec( tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); tc_nchan_allocate_new = tc_nchan_tc_new; tc_nchan_full_new = tc_nchan_tc_new; - +#ifdef NONBE_1303_REND_GRANULARITY + tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); +#endif if ( st_ivas->ism_mode == ISM_MODE_PARAM && ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) { diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index df1be1d5b1bb3a8a83cbc8f357960e9b281e8a19..93202b94cf4be011f19d3dce226026341ba3ad90 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -403,7 +403,11 @@ ivas_error ivas_param_ism_dec_open( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { +#ifdef NONBE_1303_REND_GRANULARITY + int16_t i, granularity; +#else int16_t i; +#endif PARAM_ISM_DEC_HANDLE hParamIsmDec; IVAS_OUTPUT_SETUP hOutSetup; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; @@ -539,6 +543,9 @@ ivas_error ivas_param_ism_dec_open( st_ivas->hParamIsmDec = hParamIsmDec; st_ivas->hSpatParamRendCom = hSpatParamRendCom; +#ifdef NONBE_1303_REND_GRANULARITY + granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs ); +#endif if ( st_ivas->renderer_type != RENDERER_MONO_DOWNMIX && st_ivas->renderer_type != RENDERER_DISABLE ) { @@ -578,7 +585,11 @@ ivas_error ivas_param_ism_dec_open( if ( st_ivas->hTcBuffer == NULL ) { +#ifdef NONBE_1303_REND_GRANULARITY + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, granularity ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, nchan_full, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -591,7 +602,11 @@ ivas_error ivas_param_ism_dec_open( if ( st_ivas->hTcBuffer == NULL ) { int16_t nchan_to_allocate = st_ivas->hDecoderConfig->nchan_out; +#ifdef NONBE_1303_REND_GRANULARITY + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_BUFFER, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 648f6a10608c3daa120a5b5949cfb4d5b1997303..669fa5f43cccef7640a65a36186365a5e520533a 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -2091,6 +2091,31 @@ static void ivas_jbm_dec_copy_tc( /*! r: render granularity */ int16_t ivas_jbm_dec_get_render_granularity( +#ifdef NONBE_1303_REND_GRANULARITY + const RENDERER_TYPE renderer_type, /* i : renderer type */ + const RENDERER_TYPE renderer_type_sec, /* i : secondary renderer type */ + const int32_t output_Fs /* i : sampling rate */ +) +{ + int16_t render_granularity; + + if ( renderer_type == RENDERER_BINAURAL_OBJECTS_TD || /* TD renderer */ + renderer_type == RENDERER_BINAURAL_MIXER_CONV || renderer_type == RENDERER_BINAURAL_MIXER_CONV_ROOM || /* Crend */ + renderer_type_sec == RENDERER_BINAURAL_OBJECTS_TD /* TD rend as a secondary renderer -> set the common granularity for both renderers */ + ) + { + /* 5 ms granularity */ + render_granularity = NS2SA( output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); + } + else + { + /* 1.25 ms granularity */ + render_granularity = NS2SA( output_Fs, CLDFB_SLOT_NS ); + } + + return render_granularity; +} +#else const RENDERER_TYPE rendererType, /* i : renderer type */ const IVAS_FORMAT ivas_format, /* i : ivas format */ const MC_MODE mc_mode, /* i : MC mode */ @@ -2117,6 +2142,7 @@ int16_t ivas_jbm_dec_get_render_granularity( return render_granularity; } +#endif /*--------------------------------------------------------------------------* diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 48c6f455718cf29ae43dd9ffdceb831e28e3cc58..62e711718a6791a1936b064fc67314703101e66c 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -696,6 +696,9 @@ ivas_error ivas_masa_dec_open( if ( st_ivas->hTcBuffer == NULL && st_ivas->renderer_type != RENDERER_DISABLE && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC ) { int16_t nchan_to_allocate, nchan_transport; +#ifdef NONBE_1303_REND_GRANULARITY + int16_t granularity; +#endif TC_BUFFER_MODE buffer_mode; buffer_mode = TC_BUFFER_MODE_RENDERER; @@ -727,7 +730,13 @@ ivas_error ivas_masa_dec_open( nchan_to_allocate++; } +#ifdef NONBE_1303_REND_GRANULARITY + granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); + + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_transport, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_transport, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -1474,7 +1483,11 @@ ivas_error ivas_masa_dec_reconfigure( TC_BUFFER_MODE buffer_mode_new; int16_t n_samples_granularity; +#ifdef NONBE_1303_REND_GRANULARITY + n_samples_granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, ivas_renderer_secondary_select( st_ivas ), st_ivas->hDecoderConfig->output_Fs ); +#else n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); +#endif buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); tc_nchan_transport = ivas_jbm_dec_get_num_tc_channels( st_ivas ); @@ -1489,9 +1502,11 @@ ivas_error ivas_masa_dec_reconfigure( { tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS; } +#ifndef NONBE_1303_REND_GRANULARITY if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ + if ( n_samples_granularity > st_ivas->hTcBuffer->n_samples_granularity ) { if ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) @@ -1507,6 +1522,7 @@ ivas_error ivas_masa_dec_reconfigure( /* flush already done in IVAS_DEC_ReadFormat() */ } } +#endif } else if ( st_ivas->nchan_transport == 1 && ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) { diff --git a/lib_dec/ivas_mc_param_dec.c b/lib_dec/ivas_mc_param_dec.c index e97adc27d1b5bf41b8bcae7fea8f723f0d39c078..048f26e3793a5c1faf855fc2717e2339acfaa2eb 100644 --- a/lib_dec/ivas_mc_param_dec.c +++ b/lib_dec/ivas_mc_param_dec.c @@ -437,6 +437,9 @@ ivas_error ivas_param_mc_dec_open( if ( hParamMC->synthesis_conf != PARAM_MC_SYNTH_MONO_STEREO ) { int16_t n_cldfb_slots; +#ifdef NONBE_1303_REND_GRANULARITY + int16_t granularity; +#endif n_cldfb_slots = DEFAULT_JBM_CLDFB_TIMESLOTS; if ( st_ivas->hDecoderConfig->Opt_tsm ) @@ -457,7 +460,13 @@ ivas_error ivas_param_mc_dec_open( if ( st_ivas->hTcBuffer == NULL ) { +#ifdef NONBE_1303_REND_GRANULARITY + granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs ); + + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, granularity ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, nchan_transport, nchan_transport, 0, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index 26a5124783e4fea8c45a2a06bd22006080e12d87..81bd4023a4042ed86b75f0dfc67e49ec93243a91 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -374,6 +374,9 @@ ivas_error ivas_mc_paramupmix_dec_open( { int16_t nchan_to_allocate; int16_t nchan_tc; +#ifdef NONBE_1303_REND_GRANULARITY + int16_t granularity; +#endif TC_BUFFER_MODE buffer_mode; buffer_mode = TC_BUFFER_MODE_RENDERER; @@ -391,7 +394,13 @@ ivas_error ivas_mc_paramupmix_dec_open( nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS; } +#ifdef NONBE_1303_REND_GRANULARITY + granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs ); + + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 164a245eaa14315eba30633741fe98e15e0fea72..0ec1514eaa2dba6ce76c52c619c7e2cd9166b3b1 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -793,9 +793,11 @@ static ivas_error ivas_mc_dec_reconfig( } } +#ifndef NONBE_1303_REND_GRANULARITY /* JBM: when granularity goes down (e.g. MCT with CREND -> ParamMC with binaural fastconv render what still fits in the new granularity */ tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); + if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { /* flush already done in IVAS_DEC_ReadFormat() */ @@ -808,7 +810,7 @@ static ivas_error ivas_mc_dec_reconfig( return error; } } - +#endif if ( st_ivas->mc_mode == MC_MODE_MCT ) { st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ) ); @@ -1295,6 +1297,9 @@ static ivas_error ivas_mc_dec_reconfig( tc_nchan_tc_new = ivas_jbm_dec_get_num_tc_channels( st_ivas ); tc_nchan_allocate_new = tc_nchan_tc_new; tc_nchan_full_new = tc_nchan_tc_new; +#ifdef NONBE_1303_REND_GRANULARITY + tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, st_ivas->hDecoderConfig->output_Fs ); +#endif if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index d20c793304375637482876b13bec1ea478696f82..d64720c44aff588c5735770a9ec2d8106d5367ee 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -61,9 +61,13 @@ ivas_error ivas_td_binaural_open( num_src = st_ivas->nchan_ism; } +#ifdef NONBE_1303_REND_GRANULARITY + if ( st_ivas->hHrtfTD == NULL && st_ivas->hDecoderConfig->Opt_HRTF_binary ) +#else if ( st_ivas->hHrtfTD == NULL && st_ivas->hDecoderConfig->Opt_HRTF_binary && ( st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #1202 ) +#endif { return IVAS_ERROR( IVAS_ERR_INTERNAL, "HRTF binary file present but not used in TD renderer" ); } diff --git a/lib_dec/ivas_output_config.c b/lib_dec/ivas_output_config.c index ac06064065adf793661d74449a5524a64fac188f..305d99ef994f9720defb93e4d00454a5223658ff 100644 --- a/lib_dec/ivas_output_config.c +++ b/lib_dec/ivas_output_config.c @@ -479,3 +479,36 @@ void ivas_renderer_select( return; } + + +#ifdef NONBE_1303_REND_GRANULARITY +/*-------------------------------------------------------------------------* + * ivas_renderer_secondary_select() + * + * Select IVAS secondary binaural renderer (used in combine formats) + *-------------------------------------------------------------------------*/ + +/*! r: secondary binaural renderer type */ +RENDERER_TYPE ivas_renderer_secondary_select( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +) +{ + RENDERER_TYPE renderer_type; + AUDIO_CONFIG output_config; + + /* disabled by default */ + renderer_type = RENDERER_DISABLE; + output_config = st_ivas->hDecoderConfig->output_config; + + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->ism_mode == ISM_MASA_MODE_DISC && output_config == IVAS_AUDIO_CONFIG_BINAURAL ) + { + renderer_type = RENDERER_BINAURAL_OBJECTS_TD; + } + else if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC && ( output_config == IVAS_AUDIO_CONFIG_BINAURAL || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) + { + renderer_type = RENDERER_BINAURAL_OBJECTS_TD; + } + + return renderer_type; +} +#endif diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 4bb13325b20bbaa5125e582abb59385038a46f54..3ef82c883e39bf72c665fc62166d9bc01907d77c 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -163,6 +163,7 @@ ivas_error ivas_sba_dec_reconfigure( /* we may need to flush only for binaural and OSBA and TSM */ if ( st_ivas->ivas_format == SBA_ISM_FORMAT && ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { +#ifndef NONBE_1303_REND_GRANULARITY RENDERER_TYPE renderer_type_new; int16_t sba_order_internal; @@ -197,7 +198,11 @@ ivas_error ivas_sba_dec_reconfigure( } } +#endif /* determine new granularity */ +#ifdef NONBE_1303_REND_GRANULARITY + granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, ivas_renderer_secondary_select( st_ivas ), st_ivas->hDecoderConfig->output_Fs ); +#else granularity_new = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /* this will change anyway only with binaural */ @@ -205,7 +210,19 @@ ivas_error ivas_sba_dec_reconfigure( { granularity_new *= JBM_CLDFB_SLOTS_IN_SUBFRAME; } +#endif +#ifdef NONBE_1303_REND_GRANULARITY + if ( granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) + { + /* make sure the changed number of slots in the last subframe is not lost in the following steps */ + if ( st_ivas->hSpatParamRendCom != NULL ) + { + st_ivas->hSpatParamRendCom->subframe_nbslots[st_ivas->hSpatParamRendCom->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; + } + st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; + } +#else /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */ if ( granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { @@ -225,6 +242,7 @@ ivas_error ivas_sba_dec_reconfigure( } st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; } +#endif } /* save old */ diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index e984b9251c4485b22093acaefd410df653c7e726..205bc77859b29600c31d51af54718c96006e863c 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -228,8 +228,10 @@ ivas_error ivas_spar_dec_open( nchan_to_allocate += st_ivas->nchan_ism; } +#ifndef NONBE_1303_REND_GRANULARITY granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); +#endif if ( ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO ) ) { if ( ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->ism_mode == ISM_SBA_MODE_DISC && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO ) ) @@ -249,6 +251,11 @@ ivas_error ivas_spar_dec_open( nchan_to_allocate = 2 * BINAURAL_CHANNELS; } +#ifdef NONBE_1303_REND_GRANULARITY + granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, ivas_renderer_secondary_select( st_ivas ), output_Fs ); + + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK ) +#else if ( st_ivas->ivas_format == SBA_ISM_FORMAT && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL && st_ivas->ism_mode == ISM_SBA_MODE_DISC ) @@ -258,6 +265,7 @@ ivas_error ivas_spar_dec_open( } if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_dec/lib_dec.c b/lib_dec/lib_dec.c index 52c50f0140496d590077f5157aad63e11f2b3475..dbc389ccdf8e23c1f95492abf8a0e202fbce3f7c 100644 --- a/lib_dec/lib_dec.c +++ b/lib_dec/lib_dec.c @@ -902,6 +902,49 @@ ivas_error IVAS_DEC_FeedFrame_Serial( return IVAS_ERR_OK; } +#ifdef NONBE_1303_REND_GRANULARITY + +/*---------------------------------------------------------------------* + * renderer_type_to_mode() + * + * Convert (codec library) renderer type to (API public) binaural renderer mode + *---------------------------------------------------------------------*/ + +/*! r: binaural renderer mode (API type) */ +static IVAS_BIN_RENDERER_TYPE renderer_type_to_mode( + const RENDERER_TYPE renderer_type /* i : renderer type (codec library type) */ +) +{ + IVAS_BIN_RENDERER_TYPE binaural_renderer; + + switch ( renderer_type ) + { + case RENDERER_BINAURAL_OBJECTS_TD: + binaural_renderer = IVAS_BIN_RENDERER_TYPE_TDREND; + break; + case RENDERER_BINAURAL_MIXER_CONV: + case RENDERER_BINAURAL_MIXER_CONV_ROOM: + binaural_renderer = IVAS_BIN_RENDERER_TYPE_CREND; + break; + case RENDERER_BINAURAL_FASTCONV: + binaural_renderer = IVAS_BIN_RENDERER_TYPE_FASTCONV; + break; + case RENDERER_BINAURAL_FASTCONV_ROOM: + binaural_renderer = IVAS_BIN_RENDERER_TYPE_FASTCONV; + break; + case RENDERER_BINAURAL_PARAMETRIC: + case RENDERER_BINAURAL_PARAMETRIC_ROOM: + binaural_renderer = IVAS_BIN_RENDERER_TYPE_PARAMBIN; + break; + default: + binaural_renderer = IVAS_BIN_RENDERER_TYPE_NONE; + break; + } + + return binaural_renderer; +} + +#endif /*---------------------------------------------------------------------* * IVAS_DEC_ReadFormat( ) @@ -925,7 +968,11 @@ ivas_error IVAS_DEC_ReadFormat( MC_MODE mc_mode_old; int16_t nchan_transport_old; AUDIO_CONFIG intern_config_old, transport_config_old, output_config; +#ifdef NONBE_1303_REND_GRANULARITY + RENDERER_TYPE renderer_type_old, renderer_type_sec_new, renderer_type_sec_old; +#else RENDERER_TYPE renderer_type_old; +#endif if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { @@ -940,6 +987,9 @@ ivas_error IVAS_DEC_ReadFormat( intern_config_old = st_ivas->intern_config; transport_config_old = st_ivas->transport_config; renderer_type_old = st_ivas->renderer_type; +#ifdef NONBE_1303_REND_GRANULARITY + renderer_type_sec_old = ivas_renderer_secondary_select( st_ivas ); +#endif output_config = st_ivas->hDecoderConfig->output_config; @@ -961,8 +1011,15 @@ ivas_error IVAS_DEC_ReadFormat( return ( IVAS_ERROR( IVAS_ERR_INVALID_INPUT_FORMAT, "IVAS format switching is not allowed." ) ); } + /* Select binaural renderer */ ivas_renderer_select( st_ivas ); +#ifdef NONBE_1303_REND_GRANULARITY + *binaural_renderer = renderer_type_to_mode( st_ivas->renderer_type ); + /* Select secondary binaural renderer (used in combine formats) */ + renderer_type_sec_new = ivas_renderer_secondary_select( st_ivas ); + *binaural_renderer_sec = renderer_type_to_mode( renderer_type_sec_new ); +#else switch ( st_ivas->renderer_type ) { case RENDERER_BINAURAL_OBJECTS_TD: @@ -992,7 +1049,9 @@ ivas_error IVAS_DEC_ReadFormat( { *binaural_renderer_sec = IVAS_BIN_RENDERER_TYPE_TDREND; } +#endif + /* select HRTF audio configuration to load the right HRTF set for the external binary file */ *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_INVALID; if ( *binaural_renderer == IVAS_BIN_RENDERER_TYPE_FASTCONV ) { @@ -1040,6 +1099,38 @@ ivas_error IVAS_DEC_ReadFormat( } } +#ifdef NONBE_1303_REND_GRANULARITY + /* JBM: compensate when binaural renderer granularity changes (happens in bitrate switching) */ + if ( st_ivas->ini_active_frame > 0 && st_ivas->hDecoderConfig->Opt_tsm && + ( ( renderer_type_old != st_ivas->renderer_type ) || + ( renderer_type_sec_old != renderer_type_sec_new ) ) ) + { + int16_t tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, renderer_type_sec_new, st_ivas->hDecoderConfig->output_Fs ); + + st_ivas->nchan_transport = nchan_transport_old; + + if ( st_ivas->hTcBuffer == NULL ) + { + return IVAS_ERR_UNEXPECTED_NULL_POINTER; + } + + /* when granularity goes down, render what still fits in the new granularity */ + if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &st_ivas->hIntSetup, mc_mode_old, ism_mode_old, &hIvasDec->nSamplesFlushed, pcm_type_API_to_internal( hIvasDec->pcmType ), hIvasDec->flushbuffer ) ) != IVAS_ERR_OK ) + { + return error; + } + } + /* when granularity goes up, discard samples at the beginning of the frame */ + else if ( tc_granularity_new > st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#else #ifdef NONBE_FIX_1297_SPAR_JBM_MEM_SAN if ( ( renderer_type_old != st_ivas->renderer_type && renderer_type_old != RENDERER_DISABLE ) || ( st_ivas->ini_active_frame > 0 && @@ -1054,6 +1145,7 @@ ivas_error IVAS_DEC_ReadFormat( render what still fits in the new granularity */ int16_t tc_granularity_new = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs ); st_ivas->nchan_transport = nchan_transport_old; + if ( tc_granularity_new < st_ivas->hTcBuffer->n_samples_granularity ) { if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &st_ivas->hIntSetup, mc_mode_old, ism_mode_old, &hIvasDec->nSamplesFlushed, pcm_type_API_to_internal( hIvasDec->pcmType ), hIvasDec->flushbuffer ) ) != IVAS_ERR_OK ) @@ -1061,6 +1153,7 @@ ivas_error IVAS_DEC_ReadFormat( return error; } } +#endif } } @@ -2928,9 +3021,13 @@ ivas_error IVAS_DEC_HRTF_binary_close( if ( st_ivas->hDecoderConfig->Opt_HRTF_binary && st_ivas->ini_frame > 0 ) { +#ifdef NONBE_1303_REND_GRANULARITY + if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) +#else if ( !( binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_TDREND || binaural_renderer_old == IVAS_BIN_RENDERER_TYPE_DEFAULT ) && ( hIvasDec->st_ivas->ivas_format != SBA_ISM_FORMAT ) // ToDo: temporary hack to avoid ASAN errors -> see issue #1202 ) +#endif { ivas_HRTF_binary_close( &st_ivas->hHrtfTD ); } diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index c5810cb6d3f60c77a872dee496c0397576d33f45..3be1a116d7a5543c6ead08e89245837286259547 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -151,6 +151,12 @@ ivas_error ivas_dirac_dec_init_binaural_data( num_poses = st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses; } +#ifdef NONBE_1303_REND_GRANULARITY + output_Fs = st_ivas->hDecoderConfig->output_Fs; + nBins = st_ivas->hSpatParamRendCom->num_freq_bands; + renderer_type = st_ivas->renderer_type; + +#endif for ( pos_idx = 0; pos_idx < num_poses; pos_idx++ ) { hDiracDecBin = st_ivas->hDiracDecBin[pos_idx]; @@ -169,10 +175,11 @@ ivas_error ivas_dirac_dec_init_binaural_data( hDiracDecBin->phHrtfParambin = NULL; } +#ifndef NONBE_1303_REND_GRANULARITY output_Fs = st_ivas->hDecoderConfig->output_Fs; nBins = st_ivas->hSpatParamRendCom->num_freq_bands; renderer_type = st_ivas->renderer_type; - +#endif for ( j = 0; j < BINAURAL_CHANNELS; j++ ) { for ( k = 0; k < BINAURAL_CHANNELS + MAX_NUM_OBJECTS; k++ ) @@ -324,11 +331,15 @@ ivas_error ivas_dirac_dec_init_binaural_data( nchan_to_allocate = BINAURAL_CHANNELS + st_ivas->nchan_ism; } +#ifdef NONBE_1303_REND_GRANULARITY + n_samples_granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, ivas_renderer_secondary_select( st_ivas ), output_Fs ); +#else n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ } +#endif if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, ivas_jbm_dec_get_num_tc_channels( st_ivas ), nchan_to_allocate, nchan_to_allocate, n_samples_granularity ) ) != IVAS_ERR_OK ) {