diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 5656733f5fba82fea64beb74fd318aca2070b095..543c0adc9d22fb4a43179f6ecd86c6ac1ad95757 100755 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -294,6 +294,14 @@ ivas_error ivas_init_decoder( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC +ivas_error ivas_output_buff_dec( + float *p_output_f[], /* i/o: output audio buffers */ + const int16_t nchan_out_buff_old, /* i : previous frame number of output channels*/ + const int16_t nchan_out_buff /* i : number of output channels */ +); +#endif + ivas_error stereo_dmx_evs_init_encoder( STEREO_DMX_EVS_ENC_HANDLE *hStereoDmxEVS, /* o : Stereo downmix for EVS encoder handle */ const int32_t input_Fs /* i : input sampling rate */ diff --git a/lib_com/options.h b/lib_com/options.h old mode 100755 new mode 100644 index 6d9a3633600ff18dc1766fd63cfa299d4e574928..73464a5c15775ad0ef096fa1aab4107a78d6cf3e --- a/lib_com/options.h +++ b/lib_com/options.h @@ -186,7 +186,7 @@ #define NONBE_FIX_826_JBM_MASA_CNA_CNG /* FhG: issue #826: Resolve "JBM MASA: CNA and CNG not in sync with non-JBM decoding" */ #define NONBE_FIX_835_JBM_PARAMUPMIX_HEADROT /* FhG: issue #835: Resolve "JBM: ParamUpmix head rotation broken" */ #define NONBE_FIX_838_CRASH_24_4_WB /* FhG: Issue 838: fix encoder crashes for Unified Stereo and MASA 2 TC at 24.4 kbps WB due to missing IGF (re-) allocation */ - +#define NONBE_FIX_839_MC_RS_CHANNEL_ALLOC /* FhG: Issues #839: problems with reallocation of the channels on the heap in case of MC RS */ /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_dec/ivas_ism_dec.c b/lib_dec/ivas_ism_dec.c index 39c7c667d94a3ada19c3546151d218b06a1384a7..5378cdf66659c6a4f094c96c141852558bd1fe37 100644 --- a/lib_dec/ivas_ism_dec.c +++ b/lib_dec/ivas_ism_dec.c @@ -67,7 +67,11 @@ static ivas_error ivas_ism_bitrate_switching_dec( int16_t tc_nchan_tc_new; int16_t tc_nchan_allocate_new; int16_t tc_granularity_new; +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + int16_t nchan_out_buff, nchan_out_buff_old; +#else int16_t ch, nchan_out_buff, nchan_out_buff_old; +#endif AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; RENDERER_TYPE renderer_type_old; @@ -81,7 +85,11 @@ static ivas_error ivas_ism_bitrate_switching_dec( st_ivas->ism_mode = last_ism_mode; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); st_ivas->ism_mode = ism_mode; +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); +#else nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); +#endif if ( ( error = ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->nchan_ism, NULL, 0, NULL, NULL, element_brate_tmp, NULL, NULL, 0 ) ) != IVAS_ERR_OK ) { @@ -331,6 +339,14 @@ static ivas_error ivas_ism_bitrate_switching_dec( if ( !st_ivas->hDecoderConfig->Opt_5ms ) { +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + 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; + } +#else nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); if ( nchan_out_buff > nchan_out_buff_old ) @@ -352,6 +368,7 @@ static ivas_error ivas_ism_bitrate_switching_dec( st_ivas->p_output_f[ch] = NULL; } } +#endif } /*-----------------------------------------------------------------* diff --git a/lib_dec/ivas_mc_paramupmix_dec.c b/lib_dec/ivas_mc_paramupmix_dec.c index df15270c8bc023a9c32a3478c4a9e839758dcaf9..b4c8b39a08b98b73b8b403951f30c12172e47a8d 100644 --- a/lib_dec/ivas_mc_paramupmix_dec.c +++ b/lib_dec/ivas_mc_paramupmix_dec.c @@ -443,7 +443,11 @@ void ivas_mc_paramupmix_dec( } } +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + for ( ch = first_empty_channel; ch < ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); ch++ ) +#else for ( ch = first_empty_channel; ch < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); ch++ ) +#endif { set_f( output_f[ch], 0.0f, output_frame ); } diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index cb51ee7f69d8ff7d51979105356fb931aacd02fc..8243c1971009709595dbacfa7e95fda4ab40ce20 100755 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -731,12 +731,16 @@ static ivas_error ivas_mc_dec_reconfig( int16_t tc_granularity_new; AUDIO_CONFIG intern_config_old; IVAS_OUTPUT_SETUP hIntSetupOld; +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + int16_t nchan_out_buff_old, nchan_out_buff; +#endif error = IVAS_ERR_OK; - ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; nchan_transport_old = st_ivas->nchan_transport; - +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); +#endif last_mc_mode = ivas_mc_mode_select( ivas_mc_map_output_config_to_mc_ls_setup( st_ivas->transport_config ), st_ivas->hDecoderConfig->last_ivas_total_brate ); /* NB: this assumes that LS config remains the same between frames */ /* we have to temporally set the current mc_mode back to the previous one to make sure the following call to @@ -1386,5 +1390,46 @@ static ivas_error ivas_mc_dec_reconfig( } } +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + /*-----------------------------------------------------------------* + * floating-point output audio buffers + *-----------------------------------------------------------------*/ + + if ( !st_ivas->hDecoderConfig->Opt_5ms ) + { +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + 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; + } +#else + int16_t nchan_out_buff, ch; + nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); + + if ( nchan_out_buff > nchan_out_buf_old ) + { + for ( ch = nchan_out_buf_old; ch < nchan_out_buff; ch++ ) + { + /* note: these are intra-frame heap memories */ + if ( ( st_ivas->p_output_f[ch] = (float *) malloc( ( 48000 / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL ) /* note: 32000 == max internal sampling rate */ + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); + } + } + } + else + { + for ( ch = nchan_out_buff; ch < nchan_out_buf_old; ch++ ) + { + free( st_ivas->p_output_f[ch] ); + st_ivas->p_output_f[ch] = NULL; + } + } +#endif + } +#endif + return error; } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index b6846dfe933f7c6d8cf992d382e19c71b5749a96..adb1597cfd6aa582d0519d7d46ad0e7064dcf5e8 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -180,7 +180,11 @@ ivas_error ivas_omasa_dec_config( ivas_format_orig = st_ivas->ivas_format; st_ivas->ivas_format = st_ivas->last_ivas_format; ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ); +#else nchan_out_buff_old = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); +#endif st_ivas->ivas_format = ivas_format_orig; @@ -414,6 +418,14 @@ ivas_error ivas_omasa_dec_config( if ( !st_ivas->hDecoderConfig->Opt_5ms ) { +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + 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; + } +#else nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); if ( nchan_out_buff > nchan_out_buff_old ) @@ -435,6 +447,7 @@ ivas_error ivas_omasa_dec_config( st_ivas->p_output_f[k] = NULL; } } +#endif } } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 7bdba95d8e51e636042cfd7aa1ee024c37c5178c..a88e1b408a9b119fe803a58b0c12d637cdcc3039 100755 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -121,7 +121,11 @@ ivas_error ivas_sba_dec_reconfigure( int32_t ivas_total_brate; int32_t last_ivas_total_brate; int16_t num_channels, num_md_sub_frames; +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + int16_t nchan_out_buff, nchan_out_buff_old; +#else int16_t ch, nchan_out_buff, nchan_out_buff_old; +#endif int16_t sba_analysis_order_old; #ifdef JBM_FOR_OSBA int16_t sba_analysis_order_old_flush; @@ -736,6 +740,12 @@ ivas_error ivas_sba_dec_reconfigure( { nchan_out_buff = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC + if ( ( error = ivas_output_buff_dec( st_ivas->p_output_f, nchan_out_buff_old, nchan_out_buff ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( nchan_out_buff > nchan_out_buff_old ) { for ( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) @@ -755,6 +765,7 @@ ivas_error ivas_sba_dec_reconfigure( st_ivas->p_output_f[ch] = NULL; } } +#endif } return error; diff --git a/lib_rend/ivas_output_init.c b/lib_rend/ivas_output_init.c index 9ffa67978c534915ac128e72b5798e80d98b935b..9b3b55e20d6a00f7a32621b662246e1c981c62f1 100644 --- a/lib_rend/ivas_output_init.c +++ b/lib_rend/ivas_output_init.c @@ -409,3 +409,43 @@ int16_t ivas_get_nchan_buffers_dec( return nchan_out_buff; } + + +#ifdef NONBE_FIX_839_MC_RS_CHANNEL_ALLOC +/*-------------------------------------------------------------------* + * ivas_output_buff_dec() + * + * Allocate/reallocate output audio buffers + *-------------------------------------------------------------------*/ + +ivas_error ivas_output_buff_dec( + float *p_output_f[], /* i/o: output audio buffers */ + const int16_t nchan_out_buff_old, /* i : previous frame number of output channels */ + const int16_t nchan_out_buff /* i : number of output channels */ +) +{ + int16_t ch; + + if ( nchan_out_buff > nchan_out_buff_old ) + { + for ( ch = nchan_out_buff_old; ch < nchan_out_buff; ch++ ) + { + /* 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 */ + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point output audio buffer!\n" ) ); + } + } + } + else + { + for ( ch = nchan_out_buff; ch < nchan_out_buff_old; ch++ ) + { + free( p_output_f[ch] ); + p_output_f[ch] = NULL; + } + } + + return IVAS_ERR_OK; +} +#endif