diff --git a/lib_com/options.h b/lib_com/options.h index f7ce57b4bd84da56978a12bce145bb8628992ae5..740ae294eb5289c6721be57ea985e192fc7f96a5 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -162,6 +162,8 @@ #define TMP_FIX_1119_SPLIT_RENDERING_VOIP /* FhG: Add error check for unsupported config: split rendering with VoIP mode */ #define FIX_1314_STEREO_TO_EXT /* VA: issue 1314: set RENDERER_DISABLE for stereo to EXT output */ #define FIX_1320_STACK_CPE_DECODER /* VA: issue 1320: Optimize the stack memory consumption in the CPE decoder */ +#define FIX_NCHAN_BUFFERS /* VA: issue 1322: Correct the number of float buffers (channels) at the decoder */ +#define FIX_RENDERER_STACK /* VA: issue 1322: reduction of renderers' buffers size */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/ivas_dirac_dec.c b/lib_dec/ivas_dirac_dec.c index cfc4b0bc308c94f2b0cb9fc2f994a0f89d8ca291..d7ee741ca92779ce12569c703cd48c2df3dbef41 100644 --- a/lib_dec/ivas_dirac_dec.c +++ b/lib_dec/ivas_dirac_dec.c @@ -1554,7 +1554,12 @@ void ivas_dirac_dec_render( uint16_t slot_size, n_samples_sf, ch, nchan_intern; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; float *output_f_local[MAX_OUTPUT_CHANNELS]; +#ifdef FIX_RENDERER_STACK + float *p_output_f[MAX_OUTPUT_CHANNELS]; + float output_f_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; +#else float output_f_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; +#endif hSpatParamRendCom = st_ivas->hSpatParamRendCom; @@ -1565,7 +1570,11 @@ void ivas_dirac_dec_render( for ( ch = 0; ch < nchan_intern; ch++ ) { output_f_local[ch] = output_f_local_buff[ch]; +#ifdef FIX_RENDERER_STACK + p_output_f[ch] = output_f[ch]; +#else set_zero( output_f_local_buff[ch], nSamplesAsked ); +#endif } slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); @@ -1587,16 +1596,29 @@ void ivas_dirac_dec_render( for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { ivas_dirac_dec_render_sf( st_ivas, output_f_local, nchan_transport, NULL, NULL ); + n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size; + for ( ch = 0; ch < nchan_intern; ch++ ) { +#ifdef FIX_RENDERER_STACK + /* move to output */ + if ( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( st_ivas->hDirACRend->hOutSetup.separateChannelIndex == ch || st_ivas->hDirACRend->hOutSetup.separateChannelIndex + 1 == ch ) ) ) + { + mvr2r( output_f_local_buff[ch], p_output_f[ch], n_samples_sf ); + } + + p_output_f[ch] += n_samples_sf; +#else output_f_local[ch] += n_samples_sf; +#endif } /* update combined orientation access index */ ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); } +#ifndef FIX_RENDERER_STACK for ( ch = 0; ch < nchan_intern; ch++ ) { if ( !( ( st_ivas->hDirACRend->hOutSetup.separateChannelEnabled ) && ( st_ivas->hDirACRend->hOutSetup.separateChannelIndex == ch || st_ivas->hDirACRend->hOutSetup.separateChannelIndex + 1 == ch ) ) ) @@ -1604,7 +1626,7 @@ void ivas_dirac_dec_render( mvr2r( output_f_local_buff[ch], output_f[ch], *nSamplesRendered ); } } - +#endif if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots ) { if ( st_ivas->hDirAC->hConfig->dec_param_estim == 1 ) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 0d3610065b7597d8d40e52eb6a0179075f70b516..f59064bbb8d7266f6d1d84bfa7ea3fe7c876cff6 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -487,7 +487,7 @@ ivas_error ivas_dec_setup( } /*-------------------------------------------------------------------* - * Read other signling (ISM/MC mode, number of channels, etc.) + * Read other signaling (ISM/MC mode, number of channels, etc.) *-------------------------------------------------------------------*/ if ( is_DTXrate( ivas_total_brate ) == 0 ) @@ -2378,7 +2378,12 @@ ivas_error ivas_init_decoder( * Allocate floating-point output audio buffers *-----------------------------------------------------------------*/ +#ifdef FIX_NCHAN_BUFFERS + k = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + for ( n = 0; n < k; n++ ) +#else for ( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) +#endif { /* note: these are intra-frame heap memories */ if ( ( st_ivas->p_output_f[n] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index e752c91c40e3f13e7c9c653519664f871a6faa79..649cb15bbb728f44030211f2d3037b037063f539 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -821,7 +821,12 @@ void ivas_jbm_dec_feed_tc_to_renderer( p_data_f[n] = &st_ivas->p_output_f[n][0]; } +#ifdef FIX_NCHAN_BUFFERS + ch = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + for ( n = 0; n < ch; n++ ) +#else for ( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) +#endif { hTcBuffer->tc[n] = st_ivas->p_output_f[n]; /* note: buffers needed in the TD decorellator */ } @@ -2178,7 +2183,6 @@ ivas_error ivas_jbm_dec_tc_buffer_reconfigure( hTcBuffer = st_ivas->hTcBuffer; - /* if granularity changes, adapt subframe_nb_slots */ if ( n_samples_granularity != hTcBuffer->n_samples_granularity ) { diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 34d528b0e3d8687e9f6a0ee67a505b3505aed97e..560cb474b44caba8f44008c4cb6c12f02f2ae546 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1320,6 +1320,9 @@ ivas_error ivas_masa_dec_reconfigure( Decoder_State **sts; int32_t ivas_total_brate, last_ivas_total_brate; int16_t numCldfbAnalyses_old, numCldfbSyntheses_old; +#ifdef FIX_NCHAN_BUFFERS + int16_t nchan_out_buff_old, nchan_out_buff; +#endif ivas_error error; int16_t pos_idx; int32_t ism_total_brate; @@ -1327,6 +1330,10 @@ ivas_error ivas_masa_dec_reconfigure( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; +#ifdef FIX_NCHAN_BUFFERS + nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); + +#endif /* Copy state to TC buffer if granularity matches and we are not in OMASA EXT rendering mode */ if ( st_ivas->hSpatParamRendCom != NULL && st_ivas->hSpatParamRendCom->slot_size == st_ivas->hTcBuffer->n_samples_granularity && st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_EXTERNAL ) { @@ -1490,7 +1497,15 @@ ivas_error ivas_masa_dec_reconfigure( } else { +#ifdef FIX_NCHAN_BUFFERS + tc_nchan_to_allocate = BINAURAL_CHANNELS; + if ( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr ) + { + tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS; + } +#else tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS; +#endif } } else if ( st_ivas->nchan_transport == 1 && ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirACRend->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) ) @@ -1530,6 +1545,21 @@ ivas_error ivas_masa_dec_reconfigure( } } +#ifdef FIX_NCHAN_BUFFERS + /*-----------------------------------------------------------------* + * floating-point output audio buffers + *-----------------------------------------------------------------*/ + + if ( st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format == MASA_FORMAT ) /* note: switching with OMASA is addressed in ivas_omasa_dec_config() */ + { + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } + } + +#endif return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 3300eb7965b34dcf949d2370339bcd3b357db8ac..4097c4d71db24f000c37e72cb0bd390e64609055 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -1279,7 +1279,19 @@ static ivas_error ivas_mc_dec_reconfig( if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { +#ifdef FIX_NCHAN_BUFFERS + tc_nchan_allocate_new = BINAURAL_CHANNELS; + if ( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr ) + { + tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; + } + else if ( st_ivas->hOutSetup.separateChannelEnabled ) + { + tc_nchan_allocate_new++; + } +#else tc_nchan_allocate_new = 2 * BINAURAL_CHANNELS; +#endif tc_nchan_full_new = tc_nchan_allocate_new; } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index ade8e11b020756b9b0dff0cec52800e2410b7335..de0e9444c671a23d6fd4e5fef33e310519e2ce66 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -704,6 +704,20 @@ ivas_error ivas_sba_dec_render( nchan_internal = ivas_sba_get_nchan_metadata( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); nchan_out = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; +#ifdef FIX_NCHAN_BUFFERS + if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + nchan_out = max( nchan_internal, st_ivas->hDecoderConfig->nchan_out ); + + if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_EXTERNAL ) + { + nchan_out = max( nchan_internal, st_ivas->hDecoderConfig->nchan_out - st_ivas->nchan_ism ); + } + } + + nchan_out = min( nchan_out, ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); + +#endif #ifdef DEBUGGING assert( hSpar ); #endif diff --git a/lib_rend/ivas_crend.c b/lib_rend/ivas_crend.c index fde81489512622a108605b02a7cd1e15bac97a42..6872f4d945de9ba602b6e552f85989619f97ab47 100644 --- a/lib_rend/ivas_crend.c +++ b/lib_rend/ivas_crend.c @@ -1501,8 +1501,13 @@ static ivas_error ivas_rend_crendConvolver( const float *pFreq_filt_re, *pFreq_filt_im; float *pFreq_buf_re = NULL, *pFreq_buf_im = NULL; float *pFreq_buf2_re = NULL, *pFreq_buf2_im = NULL; +#ifdef FIX_RENDERER_STACK + float pOut[2 /*Re,Im*/ * L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; + float tmp_out_re[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES], tmp_out_im[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; +#else float pOut[L_FRAME48k * 2]; float tmp_out_re[L_FRAME48k], tmp_out_im[L_FRAME48k]; +#endif CREND_HANDLE hCrend; ivas_error error; @@ -1708,7 +1713,12 @@ ivas_error ivas_rend_crendProcessSubframe( int16_t subframe_idx, subframe_len; int16_t nchan_out, nchan_in, ch, first_sf, last_sf, slot_size, slots_to_render; float *tc_local[MAX_OUTPUT_CHANNELS]; +#ifdef FIX_RENDERER_STACK + float *p_output[BINAURAL_CHANNELS]; + float pcm_tmp[BINAURAL_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES]; +#else float pcm_tmp[BINAURAL_CHANNELS][L_FRAME48k]; +#endif float *p_pcm_tmp[BINAURAL_CHANNELS]; IVAS_REND_AudioConfigType inConfigType; ivas_error error; @@ -1747,6 +1757,9 @@ ivas_error ivas_rend_crendProcessSubframe( for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { p_pcm_tmp[ch] = pcm_tmp[ch]; +#ifdef FIX_RENDERER_STACK + p_output[ch] = output[ch]; +#endif } if ( hTcBuffer != NULL ) @@ -1827,10 +1840,12 @@ ivas_error ivas_rend_crendProcessSubframe( { tc_local[ch] += subframe_len; } +#ifndef FIX_RENDERER_STACK for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { p_pcm_tmp[ch] += subframe_len; } +#endif if ( hTcBuffer != NULL ) { @@ -1842,16 +1857,27 @@ ivas_error ivas_rend_crendProcessSubframe( return IVAS_ERR_INVALID_INPUT_FORMAT; } +#ifdef FIX_RENDERER_STACK + for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) + { + /* move to output */ + mvr2r( pcm_tmp[ch], p_output[ch], subframe_len ); + + p_output[ch] += subframe_len; + } + +#endif /* update combined orientation access index */ ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_len ); } +#ifndef FIX_RENDERER_STACK /* move to output */ for ( ch = 0; ch < nchan_out; ch++ ) { mvr2r( pcm_tmp[ch], output[ch], n_samples_to_render ); } - +#endif if ( hTcBuffer != NULL ) { hTcBuffer->subframes_rendered = last_sf; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index cc1bccb131955da0c19949855baa2db5f55a8f97..6e25b6888d06d4bb69e5eec147f244e80ae14edc 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -318,7 +318,19 @@ ivas_error ivas_dirac_dec_init_binaural_data( int16_t nchan_to_allocate; int16_t n_samples_granularity; +#ifdef FIX_NCHAN_BUFFERS + nchan_to_allocate = BINAURAL_CHANNELS; + if ( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr ) + { + nchan_to_allocate = 2 * BINAURAL_CHANNELS; + } + else if ( st_ivas->hOutSetup.separateChannelEnabled ) + { + nchan_to_allocate++; + } +#else nchan_to_allocate = 2 * BINAURAL_CHANNELS; +#endif if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { nchan_to_allocate = BINAURAL_CHANNELS + st_ivas->nchan_ism; @@ -444,8 +456,10 @@ void ivas_dirac_dec_binaural_render( uint16_t nchan_out; SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; float *output_f_local[MAX_OUTPUT_CHANNELS]; +#ifndef FIX_RENDERER_STACK float output_f_local_buff[MAX_OUTPUT_CHANNELS][L_FRAME48k]; int16_t output_length; +#endif hSpatParamRendCom = st_ivas->hSpatParamRendCom; nchan_out = BINAURAL_CHANNELS; @@ -454,7 +468,11 @@ void ivas_dirac_dec_binaural_render( #endif for ( ch = 0; ch < nchan_out; ch++ ) { +#ifdef FIX_RENDERER_STACK + output_f_local[ch] = output_f[ch]; +#else output_f_local[ch] = output_f_local_buff[ch]; +#endif } slot_size = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); @@ -473,7 +491,9 @@ void ivas_dirac_dec_binaural_render( #ifdef DEBUGGING assert( slots_to_render == 0 ); #endif +#ifndef FIX_RENDERER_STACK output_length = 0; +#endif for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) { int16_t n_samples_sf = slot_size * hSpatParamRendCom->subframe_nbslots[subframe_idx]; @@ -484,17 +504,21 @@ void ivas_dirac_dec_binaural_render( output_f_local[ch] += n_samples_sf; } +#ifndef FIX_RENDERER_STACK output_length += n_samples_sf; +#endif /* update combined orientation access index */ ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf ); } +#ifndef FIX_RENDERER_STACK for ( ch = 0; ch < nchan_out; ch++ ) { mvr2r( output_f_local_buff[ch], output_f[ch], output_length ); } +#endif if ( hSpatParamRendCom->slots_rendered == hSpatParamRendCom->num_slots ) { hSpatParamRendCom->dirac_read_idx = ( hSpatParamRendCom->dirac_read_idx + DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; diff --git a/lib_rend/ivas_output_init.c b/lib_rend/ivas_output_init.c index 1487181715e8f885ac6dda20aafb0fcbf487e6cc..4458e9ea84a6f0a185bf86ba8686247374ead3b8 100644 --- a/lib_rend/ivas_output_init.c +++ b/lib_rend/ivas_output_init.c @@ -271,7 +271,11 @@ int16_t ivas_get_nchan_buffers_dec( output_config = st_ivas->hDecoderConfig->output_config; +#ifdef FIX_NCHAN_BUFFERS + nchan_out_buff = st_ivas->nchan_transport; +#else nchan_out_buff = MAX_OUTPUT_CHANNELS; +#endif if ( st_ivas->ivas_format == MONO_FORMAT ) { @@ -283,6 +287,14 @@ int16_t ivas_get_nchan_buffers_dec( } else if ( st_ivas->ivas_format == ISM_FORMAT ) { +#ifdef FIX_NCHAN_BUFFERS + nchan_out_buff = max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); + + if ( st_ivas->ism_mode == ISM_MODE_PARAM || output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) + { + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); + } +#else nchan_out_buff = st_ivas->nchan_ism; if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) @@ -294,9 +306,16 @@ int16_t ivas_get_nchan_buffers_dec( nchan_out_buff = max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) ); nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) ); } +#endif } else if ( st_ivas->ivas_format == SBA_FORMAT ) { +#ifdef FIX_NCHAN_BUFFERS + int16_t nchan_internal; + nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); + + nchan_out_buff = max( nchan_internal, st_ivas->hDecoderConfig->nchan_out ); +#else int16_t nchan_internal; nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; @@ -311,9 +330,18 @@ int16_t ivas_get_nchan_buffers_dec( nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) ); } nchan_out_buff = max( nchan_out_buff, nchan_internal ); +#endif } else if ( st_ivas->ivas_format == MASA_FORMAT ) { +#ifdef FIX_NCHAN_BUFFERS + nchan_out_buff = max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); + + if ( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr ) + { + nchan_out_buff = 2 * BINAURAL_CHANNELS; + } +#else nchan_out_buff = CPE_CHANNELS; if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) @@ -334,9 +362,13 @@ int16_t ivas_get_nchan_buffers_dec( { nchan_out_buff = st_ivas->nchan_ism + CPE_CHANNELS; } +#endif } else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) { +#ifdef FIX_NCHAN_BUFFERS + nchan_out_buff = max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport + st_ivas->nchan_ism ); +#else nchan_out_buff = st_ivas->nchan_ism + CPE_CHANNELS; if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) @@ -352,9 +384,32 @@ int16_t ivas_get_nchan_buffers_dec( nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) ); } +#endif } else if ( st_ivas->ivas_format == SBA_ISM_FORMAT ) { +#ifdef FIX_NCHAN_BUFFERS + int16_t nchan_internal; + + nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); + + if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC ) + { + nchan_internal += st_ivas->nchan_ism; + } + + if ( st_ivas->hMCT != NULL ) + { + nchan_internal = ( ( nchan_internal + 1 ) >> 1 ) << 1; /* ensure odd number of channels in MCT */ + } + + nchan_out_buff = max( nchan_internal, st_ivas->hDecoderConfig->nchan_out ); + + if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) + { + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); + } +#else int16_t nchan_internal; nchan_internal = ivas_sba_get_nchan_metadata( sba_analysis_order, ivas_total_brate ); nchan_out_buff = st_ivas->nchan_ism + st_ivas->nchan_transport; @@ -392,9 +447,27 @@ int16_t ivas_get_nchan_buffers_dec( nchan_out_buff = max( nchan_out_buff, nchan_internal + st_ivas->nchan_ism ); } nchan_out_buff = min( nchan_out_buff, MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ); +#endif } else if ( st_ivas->ivas_format == MC_FORMAT ) { +#ifdef FIX_NCHAN_BUFFERS + nchan_out_buff = max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); + + if ( st_ivas->hOutSetup.separateChannelEnabled ) + { + nchan_out_buff = max( nchan_out_buff, st_ivas->nchan_transport + 1 ); + } + + if ( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr ) + { + nchan_out_buff = 2 * BINAURAL_CHANNELS; + } + else + { + nchan_out_buff = max( nchan_out_buff, audioCfg2channels( st_ivas->intern_config ) ); + } +#else nchan_out_buff = st_ivas->hDecoderConfig->nchan_out; if ( output_config == IVAS_AUDIO_CONFIG_LS_CUSTOM ) @@ -406,6 +479,7 @@ int16_t ivas_get_nchan_buffers_dec( nchan_out_buff = max( audioCfg2channels( st_ivas->transport_config ), audioCfg2channels( st_ivas->intern_config ) ); nchan_out_buff = max( nchan_out_buff, audioCfg2channels( output_config ) ); } +#endif } if ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) @@ -435,8 +509,16 @@ ivas_error ivas_output_buff_dec( { for ( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) { +#ifdef FIX_NCHAN_BUFFERS +#ifdef DEBUGGING + if ( p_output_f[ch] != NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Memory for floating-point output audio buffer is already allocated!\n" ) ); + } +#endif +#endif /* note: these are intra-frame heap memories */ - if ( ( p_output_f[ch] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) /* note: 32000 == max internal sampling rate */ + if ( ( p_output_f[ch] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); }