From 263409496b46a1cbe693d55ccb82f9e4dc76e53e Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 13 Oct 2022 16:17:10 +0200 Subject: [PATCH 1/5] formatting --- lib_dec/ivas_ism_param_dec.c | 133 +++++++++++++++++------------------ lib_enc/ivas_ism_param_enc.c | 77 ++++++++++---------- 2 files changed, 103 insertions(+), 107 deletions(-) diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index b76c88739d..cde18f55d5 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1004,13 +1004,12 @@ void ivas_param_ism_params_to_masa_param_mapping( } - #ifdef ISM_BITRATE_SWITCHING static ivas_error ivas_ism_format_bitrate_switching( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t last_nchan_trans, /* i : last number of SCE channels in the bitstream */ - const ISM_MODE last_ism_mode, /* i : last ISM mode */ - const int16_t num_obj /* i : number of objects in the bitstream */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t last_nchan_trans, /* i : last number of SCE channels in the bitstream */ + const ISM_MODE last_ism_mode, /* i : last ISM mode */ + const int16_t num_obj /* i : number of objects in the bitstream */ ) { int16_t sce_id; @@ -1019,21 +1018,21 @@ static ivas_error ivas_ism_format_bitrate_switching( error = IVAS_ERR_OK; - ivas_ism_config(st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, num_obj, NULL, NULL, NULL, element_brate_tmp, NULL, NULL); + ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, num_obj, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); - if (st_ivas->nchan_transport > last_nchan_trans) + if ( st_ivas->nchan_transport > last_nchan_trans ) { /* Initialize for new bitrate */ - for (sce_id = 0;sce_id < last_nchan_trans;sce_id++) + for ( sce_id = 0; sce_id < last_nchan_trans; sce_id++ ) { st_ivas->hSCE[sce_id]->element_brate = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport; st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } /* Initialize some memories */ - for (sce_id = last_nchan_trans; sce_id < st_ivas->nchan_transport; sce_id++) + for ( sce_id = last_nchan_trans; sce_id < st_ivas->nchan_transport; sce_id++ ) { - if ((error = create_sce_dec(st_ivas, sce_id, element_brate_tmp[sce_id])) != IVAS_ERR_OK) + if ( ( error = create_sce_dec( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) { return error; } @@ -1042,41 +1041,40 @@ static ivas_error ivas_ism_format_bitrate_switching( else { /* Initialize for new bitrate */ - for (sce_id = 0;sce_id < st_ivas->nchan_transport; sce_id++) + for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) { st_ivas->hSCE[sce_id]->element_brate = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport; st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } /* Destroy the core coder memory */ - for (; sce_id < last_nchan_trans; sce_id++) + for ( ; sce_id < last_nchan_trans; sce_id++ ) { - destroy_sce_dec(st_ivas->hSCE[sce_id]); + destroy_sce_dec( st_ivas->hSCE[sce_id] ); st_ivas->hSCE[sce_id] = NULL; } - } /* destroy the memory of hp20*/ - if (st_ivas->mem_hp20_out != NULL) + if ( st_ivas->mem_hp20_out != NULL ) { - for (sce_id = 0; sce_id < last_nchan_trans; sce_id++) + for ( sce_id = 0; sce_id < last_nchan_trans; sce_id++ ) { - count_free(st_ivas->mem_hp20_out[sce_id]); + count_free( st_ivas->mem_hp20_out[sce_id] ); st_ivas->mem_hp20_out[sce_id] = NULL; } - count_free(st_ivas->mem_hp20_out); + count_free( st_ivas->mem_hp20_out ); st_ivas->mem_hp20_out = NULL; } /* re initialize the memory of hp20 */ /* set number of input channels used for analysis/coding */ - if (st_ivas->nchan_transport > 0) + if ( st_ivas->nchan_transport > 0 ) { - if ((st_ivas->mem_hp20_out = (float **)count_malloc(st_ivas->nchan_transport * sizeof(float *))) == NULL) + if ( ( st_ivas->mem_hp20_out = (float **) count_malloc( st_ivas->nchan_transport * sizeof( float * ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } } else @@ -1084,92 +1082,92 @@ static ivas_error ivas_ism_format_bitrate_switching( st_ivas->mem_hp20_out = NULL; } - for (sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++) + for ( sce_id = 0; sce_id < st_ivas->nchan_transport; sce_id++ ) { - if ((st_ivas->mem_hp20_out[sce_id] = (float *)count_malloc(L_HP20_MEM * sizeof(float))) == NULL) + if ( ( st_ivas->mem_hp20_out[sce_id] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - set_f(st_ivas->mem_hp20_out[sce_id], 0.0f, L_HP20_MEM); + set_f( st_ivas->mem_hp20_out[sce_id], 0.0f, L_HP20_MEM ); } /* Initialize the needed renderer struct and destroy the unnecessary renderer struct */ - + /* select the renderer */ - ivas_renderer_select(st_ivas); - ivas_output_init(&(st_ivas->hIntSetup), st_ivas->intern_config); - if ((st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC) && (st_ivas->ism_mode == ISM_MODE_DISC)) + ivas_renderer_select( st_ivas ); + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config ); + if ( ( st_ivas->renderer_type == RENDERER_SBA_LINEAR_ENC ) && ( st_ivas->ism_mode == ISM_MODE_DISC ) ) { - ivas_output_init(&(st_ivas->hIntSetup), st_ivas->hDecoderConfig->output_config); + ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->hDecoderConfig->output_config ); } - if (st_ivas->ism_mode != last_ism_mode) + if ( st_ivas->ism_mode != last_ism_mode ) { /* EFAP handle */ - efap_free_data(&st_ivas->hEFAPdata); + efap_free_data( &st_ivas->hEFAPdata ); } - - if (st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM) + + if ( st_ivas->ism_mode == ISM_MODE_DISC && last_ism_mode == ISM_MODE_PARAM ) { /* switching from ParamISM to DiscISM */ /* close the ParamISM struct */ - if (st_ivas->hDirAC != NULL) + if ( st_ivas->hDirAC != NULL ) { - ivas_param_ism_dec_close(st_ivas->hDirAC, st_ivas->hDecoderConfig->output_config); + ivas_param_ism_dec_close( st_ivas->hDirAC, st_ivas->hDecoderConfig->output_config ); st_ivas->hDirAC = NULL; } - if (st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL) + if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL ) { /* close the parametric binaural renderer */ - ivas_dirac_dec_close_binaural_data(&st_ivas->hDiracDecBin); + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); /* Open the TD Binaural renderer */ - ivas_td_binaural_open(st_ivas); + ivas_td_binaural_open( st_ivas ); } else { /* close the ISM renderer and reinitialize */ - if (st_ivas->hIsmRendererData != NULL) + if ( st_ivas->hIsmRendererData != NULL ) { - count_free(st_ivas->hIsmRendererData); + count_free( st_ivas->hIsmRendererData ); st_ivas->hIsmRendererData = NULL; } - ivas_ism_renderer_open(st_ivas); + ivas_ism_renderer_open( st_ivas ); } - if (st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM) + if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM ) { /* close the parametric binaural renderer */ - ivas_dirac_dec_close_binaural_data(&st_ivas->hDiracDecBin); + ivas_dirac_dec_close_binaural_data( &st_ivas->hDiracDecBin ); /* Open Crend Binaural renderer */ - ivas_crend_open(st_ivas); + ivas_crend_open( st_ivas ); } } - if (st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC) + if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC ) { /* switching from DiscISM to ParamISM */ /* Initialize the ParamISM struct */ - ivas_param_ism_dec_open(st_ivas); + ivas_param_ism_dec_open( st_ivas ); - if (st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL) + if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL ) { /* open the parametric binaural renderer */ - ivas_dirac_dec_init_binaural_data(st_ivas); + ivas_dirac_dec_init_binaural_data( st_ivas ); /* Close the TD Binaural renderer */ - if (st_ivas->hBinRendererTd != NULL) + if ( st_ivas->hBinRendererTd != NULL ) { - ivas_td_binaural_close(&st_ivas->hBinRendererTd); + ivas_td_binaural_close( &st_ivas->hBinRendererTd ); } - if (st_ivas->hHrtfTD != NULL) + if ( st_ivas->hHrtfTD != NULL ) { st_ivas->hHrtfTD = NULL; } @@ -1177,32 +1175,31 @@ static ivas_error ivas_ism_format_bitrate_switching( else { /* Close the ISM renderer */ - if (st_ivas->hIsmRendererData != NULL) + if ( st_ivas->hIsmRendererData != NULL ) { - count_free(st_ivas->hIsmRendererData); + count_free( st_ivas->hIsmRendererData ); st_ivas->hIsmRendererData = NULL; } } - if (st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM) + if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL_ROOM ) { /* open the parametric binaural renderer */ - ivas_dirac_dec_init_binaural_data(st_ivas); + ivas_dirac_dec_init_binaural_data( st_ivas ); /* close the crend binaural renderer */ - ivas_crend_close(st_ivas); + ivas_crend_close( st_ivas ); - if (st_ivas->hHrtf != NULL) + if ( st_ivas->hHrtf != NULL ) { st_ivas->hHrtf = NULL; } } - } return error; } -#endif +#endif /*------------------------------------------------------------------------- * ivas_ism_dec_config() @@ -1222,22 +1219,22 @@ ivas_error ivas_ism_dec_config( ivas_error error; #ifdef ISM_BITRATE_SWITCHING int16_t last_nchan_trans; -#endif +#endif error = IVAS_ERR_OK; ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* store last frame ISM mode */ - last_ism_mode = st_ivas->ism_mode; + last_ism_mode = st_ivas->ism_mode; #ifdef ISM_BITRATE_SWITCHING /* Assumes that num of input objects are constant */ last_nchan_trans = num_obj; - if (last_ism_mode == ISM_MODE_PARAM) + if ( last_ism_mode == ISM_MODE_PARAM ) { last_nchan_trans = 2; } -#endif +#endif if ( !st_ivas->bfi && ivas_total_brate != IVAS_SID_5k2 && ivas_total_brate != FRAME_NO_DATA ) { @@ -1257,12 +1254,12 @@ ivas_error ivas_ism_dec_config( if ( st_ivas->ini_active_frame != 0 ) { #ifdef ISM_BITRATE_SWITCHING - /* ISM format/bitrate switching */ - if ((st_ivas->hDecoderConfig->last_ivas_total_brate != IVAS_SID_5k2) && (st_ivas->hDecoderConfig->last_ivas_total_brate != FRAME_NO_DATA)) + /* ISM bit-rate switching */ + if ( ( st_ivas->hDecoderConfig->last_ivas_total_brate != IVAS_SID_5k2 ) && ( st_ivas->hDecoderConfig->last_ivas_total_brate != FRAME_NO_DATA ) ) { - if ((st_ivas->ism_mode != last_ism_mode) || (st_ivas->hDecoderConfig->ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate)) + if ( ( st_ivas->ism_mode != last_ism_mode ) || ( st_ivas->hDecoderConfig->ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) ) { - ivas_ism_format_bitrate_switching(st_ivas, last_nchan_trans, last_ism_mode, num_obj); + ivas_ism_format_bitrate_switching( st_ivas, last_nchan_trans, last_ism_mode, num_obj ); st_ivas->nSCE = st_ivas->nchan_transport; } } diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index e8a23d6b39..508f33ab45 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -418,28 +418,27 @@ ivas_error ivas_ism_enc_config( #ifdef ISM_BITRATE_SWITCHING int16_t last_nSCE; int16_t sce_id, n; -#endif +#endif error = IVAS_ERR_OK; last_ism_mode = st_ivas->ism_mode; #ifdef ISM_BITRATE_SWITCHING last_nSCE = st_ivas->nSCE; -#endif +#endif /* select ISM format mode */ st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate ); #ifdef ISM_BITRATE_SWITCHING - /* ISM format switching */ - if ( (st_ivas->ism_mode != last_ism_mode) || (st_ivas->hEncoderConfig->ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate) ) + /* ISM bit-rate switching */ + if ( ( st_ivas->ism_mode != last_ism_mode ) || ( st_ivas->hEncoderConfig->ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) ) { int32_t element_brate_tmp[MAX_NUM_OBJECTS]; - Indice *ind_list_sce; /* list of indices */ - Indice *ind_list_metadata; /* list of indices */ + Indice *ind_list_sce, *ind_list_metadata; /* Reset and Initialize */ - if (st_ivas->ism_mode == ISM_MODE_PARAM) + if ( st_ivas->ism_mode == ISM_MODE_PARAM ) { st_ivas->nchan_transport = 2; } @@ -451,14 +450,14 @@ ivas_error ivas_ism_enc_config( st_ivas->nSCE = st_ivas->nchan_transport; st_ivas->nCPE = 0; - ivas_ism_config(st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, NULL, NULL, element_brate_tmp, NULL, NULL); + ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); - if (st_ivas->nSCE > last_nSCE) + if ( st_ivas->nSCE > last_nSCE ) { /* Reconfigure the core coders */ - for (sce_id = 0; sce_id < last_nSCE; sce_id++) + for ( sce_id = 0; sce_id < last_nSCE; sce_id++ ) { - copy_encoder_config(st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0); + copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); st_ivas->hSCE[sce_id]->element_brate = st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport; st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } @@ -467,79 +466,79 @@ ivas_error ivas_ism_enc_config( ind_list_sce = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list; ind_list_metadata = st_ivas->hSCE[0]->hMetaData->ind_list; - for (sce_id = last_nSCE; sce_id < st_ivas->nSCE; sce_id++) + for ( sce_id = last_nSCE; sce_id < st_ivas->nSCE; sce_id++ ) { /* Initialize the Core Coder */ - if ((error = create_sce_enc(st_ivas, sce_id, element_brate_tmp[sce_id])) != IVAS_ERR_OK) + if ( ( error = create_sce_enc( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) { return error; } /* prepare bitstream buffers */ - st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list_sce + (sce_id * MAX_NUM_INDICES); - reset_indices_enc(st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES); + st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->ind_list = ind_list_sce + ( sce_id * MAX_NUM_INDICES ); + reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, MAX_NUM_INDICES ); - st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata + (sce_id * MAX_BITS_METADATA); - reset_indices_enc(st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA); + st_ivas->hSCE[sce_id]->hMetaData->ind_list = ind_list_metadata + ( sce_id * MAX_BITS_METADATA ); + reset_indices_enc( st_ivas->hSCE[sce_id]->hMetaData, MAX_BITS_METADATA ); } } else { /* Reconfigure the Core Coders */ - for (sce_id = 0; sce_id < st_ivas->nSCE; sce_id++) + for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ ) { - copy_encoder_config(st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0); + copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); st_ivas->hSCE[sce_id]->element_brate = st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport; st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } /* Delete the extra memory */ - for (sce_id = st_ivas->nSCE; sce_id < last_nSCE; sce_id++) + for ( sce_id = st_ivas->nSCE; sce_id < last_nSCE; sce_id++ ) { - if (st_ivas->hSCE[sce_id] != NULL) + if ( st_ivas->hSCE[sce_id] != NULL ) { - destroy_sce_enc(st_ivas->hSCE[sce_id]); + destroy_sce_enc( st_ivas->hSCE[sce_id] ); st_ivas->hSCE[sce_id] = NULL; } } } - if ((st_ivas->ism_mode == ISM_MODE_PARAM) && (last_ism_mode == ISM_MODE_DISC)) + if ( ( st_ivas->ism_mode == ISM_MODE_PARAM ) && ( last_ism_mode == ISM_MODE_DISC ) ) { /* Initialize the memory used by ParamISM when switch to Param ISM from Disc ISM */ - if ((error = ivas_param_ism_enc_open(st_ivas)) != IVAS_ERR_OK) + if ( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; } } - if ((st_ivas->ism_mode == ISM_MODE_DISC) && (last_ism_mode == ISM_MODE_PARAM)) + if ( ( st_ivas->ism_mode == ISM_MODE_DISC ) && ( last_ism_mode == ISM_MODE_PARAM ) ) { /* Reset the memory used by ParamISM when switch to Disc ISM */ - ivas_param_ism_enc_close(st_ivas->hDirAC, st_ivas->hEncoderConfig->input_Fs); + ivas_param_ism_enc_close( st_ivas->hDirAC, st_ivas->hEncoderConfig->input_Fs ); } /* destroy the memory of hp20*/ - if (st_ivas->mem_hp20_in != NULL) + if ( st_ivas->mem_hp20_in != NULL ) { - for (sce_id = 0; sce_id < last_nSCE; sce_id++) + for ( sce_id = 0; sce_id < last_nSCE; sce_id++ ) { - count_free(st_ivas->mem_hp20_in[sce_id]); + count_free( st_ivas->mem_hp20_in[sce_id] ); st_ivas->mem_hp20_in[sce_id] = NULL; } - count_free(st_ivas->mem_hp20_in); + count_free( st_ivas->mem_hp20_in ); st_ivas->mem_hp20_in = NULL; } /* re initialize the memory of hp20 */ /* set number of input channels used for analysis/coding */ - n = getNumChanAnalysis(st_ivas); + n = getNumChanAnalysis( st_ivas ); - if (n > 0) + if ( n > 0 ) { - if ((st_ivas->mem_hp20_in = (float **)count_malloc(n * sizeof(float *))) == NULL) + if ( ( st_ivas->mem_hp20_in = (float **) count_malloc( n * sizeof( float * ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } } else @@ -547,14 +546,14 @@ ivas_error ivas_ism_enc_config( st_ivas->mem_hp20_in = NULL; } - for (sce_id = 0; sce_id < n; sce_id++) + for ( sce_id = 0; sce_id < n; sce_id++ ) { - if ((st_ivas->mem_hp20_in[sce_id] = (float *)count_malloc(L_HP20_MEM * sizeof(float))) == NULL) + if ( ( st_ivas->mem_hp20_in[sce_id] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) { - return (IVAS_ERROR(IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n")); + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); } - set_f(st_ivas->mem_hp20_in[sce_id], 0.0f, L_HP20_MEM); + set_f( st_ivas->mem_hp20_in[sce_id], 0.0f, L_HP20_MEM ); } } #else @@ -564,7 +563,7 @@ ivas_error ivas_ism_enc_config( /*ivas_ism_dec_reconfigure( st_ivas );*/ return IVAS_ERROR( IVAS_ERR_RECONFIGURE_NOT_SUPPORTED, "Error: ISM format switching not supported yet!!!\n\n" ); } -#endif +#endif return error; } -- GitLab From 5f3531bdbfa66a0aeb2f055749303de84cde79dd Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 13 Oct 2022 16:31:13 +0200 Subject: [PATCH 2/5] add sanitizeBitrateISM() to properly exit when the switched bitarte is not supported; under ISM_BITRATE_SWITCHING --- lib_enc/lib_enc.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 0525c7c1db..4f990a25df 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -78,6 +78,9 @@ static int16_t getInputBufferSize( const Encoder_Struct *st_ivas ); static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error doCommonSetterChecks( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error sanitizeBandwidth( const IVAS_ENC_HANDLE hIvasEnc ); +#ifdef ISM_BITRATE_SWITCHING +static ivas_error sanitizeBitrateISM( const ENCODER_CONFIG_HANDLE hEncoderConfig ); +#endif static void init_encoder_config( ENCODER_CONFIG_HANDLE hEncoderConfig ); static void resetIsmMetadataProvidedFlags( IVAS_ENC_HANDLE hIvasEnc ); static ivas_error bandwidthApiToInternal( const IVAS_ENC_BANDWIDTH maxBandwidth, int16_t *internalMaxBandwidth ); @@ -761,6 +764,12 @@ static ivas_error configureEncoder( } else if ( hEncoderConfig->ivas_format == ISM_FORMAT ) { +#ifdef ISM_BITRATE_SWITCHING + if ( ( error = sanitizeBitrateISM( hEncoderConfig ) ) != IVAS_ERR_OK ) + { + return error; + } +#else if ( hEncoderConfig->ivas_total_brate > IVAS_256k ) { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); @@ -777,6 +786,7 @@ static ivas_error configureEncoder( { return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); } +#endif } else if ( hEncoderConfig->ivas_format == SBA_FORMAT ) { @@ -1625,6 +1635,9 @@ static ivas_error setBitrate( { Encoder_Struct *st_ivas; ENCODER_CONFIG_HANDLE hEncoderConfig; +#ifdef ISM_BITRATE_SWITCHING + ivas_error error; +#endif st_ivas = hIvasEnc->st_ivas; hEncoderConfig = st_ivas->hEncoderConfig; @@ -1671,6 +1684,16 @@ static ivas_error setBitrate( } } +#ifdef ISM_BITRATE_SWITCHING + if ( hEncoderConfig->ivas_format == ISM_FORMAT ) + { + if ( ( error = sanitizeBitrateISM( hEncoderConfig ) ) != IVAS_ERR_OK ) + { + return error; + } + } +#endif + st_ivas->codec_mode = MODE1; if ( hEncoderConfig->element_mode_init == EVS_MONO ) @@ -1897,6 +1920,41 @@ static ivas_error sanitizeBandwidth( } +#ifdef ISM_BITRATE_SWITCHING +/*---------------------------------------------------------------------* + * sanitizeBitrateISM() + * + * + *---------------------------------------------------------------------*/ + +static ivas_error sanitizeBitrateISM( + const ENCODER_CONFIG_HANDLE hEncoderConfig ) +{ + if ( hEncoderConfig->ivas_total_brate > IVAS_256k ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + + if ( hEncoderConfig->ivas_total_brate < IVAS_16k4 && hEncoderConfig->nchan_inp == 2 ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + + if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 3 ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + + if ( hEncoderConfig->ivas_total_brate < IVAS_24k4 && hEncoderConfig->nchan_inp == 4 ) + { + return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISm specified in IVAS: %d", hEncoderConfig->ivas_total_brate ); + } + + return IVAS_ERR_OK; +} +#endif + + /*---------------------------------------------------------------------* * setBandwidth() * -- GitLab From 41867f8f6fe38cc133d815f98b878c0e4b8a14db Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 13 Oct 2022 16:50:07 +0200 Subject: [PATCH 3/5] fix memory deallocation at the necoder + comments --- lib_dec/ivas_ism_param_dec.c | 14 +++++++------- lib_enc/ivas_ism_param_enc.c | 7 ++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index cde18f55d5..6fef1e4668 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1006,10 +1006,10 @@ void ivas_param_ism_params_to_masa_param_mapping( #ifdef ISM_BITRATE_SWITCHING static ivas_error ivas_ism_format_bitrate_switching( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t last_nchan_trans, /* i : last number of SCE channels in the bitstream */ - const ISM_MODE last_ism_mode, /* i : last ISM mode */ - const int16_t num_obj /* i : number of objects in the bitstream */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t last_nchan_trans, /* i : last number of SCE channels in the bitstream*/ + const ISM_MODE last_ism_mode, /* i : last ISM mode */ + const int16_t num_obj /* i : number of objects in the bitstream */ ) { int16_t sce_id; @@ -1113,7 +1113,7 @@ static ivas_error ivas_ism_format_bitrate_switching( { /* switching from ParamISM to DiscISM */ - /* close the ParamISM struct */ + /* Deallocate the ParamISM struct */ if ( st_ivas->hDirAC != NULL ) { ivas_param_ism_dec_close( st_ivas->hDirAC, st_ivas->hDecoderConfig->output_config ); @@ -1151,9 +1151,9 @@ static ivas_error ivas_ism_format_bitrate_switching( if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC ) { - /* switching from DiscISM to ParamISM */ + /* switching from Discrete ISM to ParamISM */ - /* Initialize the ParamISM struct */ + /* Allocate and initialize the ParamISM struct */ ivas_param_ism_dec_open( st_ivas ); if ( st_ivas->hOutSetup.output_config == AUDIO_CONFIG_BINAURAL ) diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index 508f33ab45..c104c855c7 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -503,9 +503,9 @@ ivas_error ivas_ism_enc_config( } } - if ( ( st_ivas->ism_mode == ISM_MODE_PARAM ) && ( last_ism_mode == ISM_MODE_DISC ) ) + if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC ) { - /* Initialize the memory used by ParamISM when switch to Param ISM from Disc ISM */ + /* Allocate and Initialize the memory used by ParamISM when switch from Discrete ISM */ if ( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK ) { return error; @@ -514,8 +514,9 @@ ivas_error ivas_ism_enc_config( if ( ( st_ivas->ism_mode == ISM_MODE_DISC ) && ( last_ism_mode == ISM_MODE_PARAM ) ) { - /* Reset the memory used by ParamISM when switch to Disc ISM */ + /* Deallocate the memory used by ParamISM when switch to Discrete ISM */ ivas_param_ism_enc_close( st_ivas->hDirAC, st_ivas->hEncoderConfig->input_Fs ); + st_ivas->hDirAC = NULL; } /* destroy the memory of hp20*/ -- GitLab From 70ce38a3a2e9a220772482c1f633489eaea88224 Mon Sep 17 00:00:00 2001 From: vaclav Date: Thu, 13 Oct 2022 17:57:21 +0200 Subject: [PATCH 4/5] integrate CORECODER_BITRATE_SWITCHING into ISM_BITRATE_SWITCHING --- lib_dec/ivas_corecoder_dec_reconfig.c | 45 +++++---- lib_dec/ivas_ism_param_dec.c | 49 ++++++---- lib_enc/ivas_ism_param_enc.c | 128 +++++++++++++++++++++++--- 3 files changed, 174 insertions(+), 48 deletions(-) diff --git a/lib_dec/ivas_corecoder_dec_reconfig.c b/lib_dec/ivas_corecoder_dec_reconfig.c index 4ea39c6e76..cebd170100 100644 --- a/lib_dec/ivas_corecoder_dec_reconfig.c +++ b/lib_dec/ivas_corecoder_dec_reconfig.c @@ -272,31 +272,36 @@ ivas_error ivas_corecoder_dec_reconfig( *-----------------------------------------------------------------*/ /// VE: this could be merged with part of ivas_init_decoder() - if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) - { - /* skip as done in init function */ - } - else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) - { - st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; - st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; - } - else if ( st_ivas->nchan_transport == 2 ) +#ifdef ISM_BITRATE_SWITCHING + if ( st_ivas->ivas_format == SBA_FORMAT ) +#endif { - for ( n = 0; n < CPE_CHANNELS; n++ ) + if ( st_ivas->sba_mode == SBA_MODE_SPAR && st_ivas->nchan_transport == 1 ) { - st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; + /* skip as done in init function */ } - } - else - { - for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + else if ( st_ivas->nchan_transport == 1 && ( ( st_ivas->renderer_type == RENDERER_DIRAC && st_ivas->hDirAC->synthesisConf == DIRAC_SYNTHESIS_GAIN_SHD ) || ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) + { + st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1; + st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1; + } + else if ( st_ivas->nchan_transport == 2 ) { for ( n = 0; n < CPE_CHANNELS; n++ ) { - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; - st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; + st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0; + st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1; + } + } + else + { + for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0; + st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0; + } } } } @@ -317,7 +322,7 @@ ivas_error ivas_corecoder_dec_reconfig( /*-------------------------------------------------------------------* * ivas_hp20_dec_reconfig() * - * Allocate, initalize, and configure HP20 memory handles in case of bitrate switching + * Allocate, initialize, and configure HP20 memory handles in case of bitrate switching *-------------------------------------------------------------------*/ ivas_error ivas_hp20_dec_reconfig( diff --git a/lib_dec/ivas_ism_param_dec.c b/lib_dec/ivas_ism_param_dec.c index 6fef1e4668..c6c1f99c9c 100644 --- a/lib_dec/ivas_ism_param_dec.c +++ b/lib_dec/ivas_ism_param_dec.c @@ -1005,32 +1005,44 @@ void ivas_param_ism_params_to_masa_param_mapping( #ifdef ISM_BITRATE_SWITCHING -static ivas_error ivas_ism_format_bitrate_switching( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const int16_t last_nchan_trans, /* i : last number of SCE channels in the bitstream*/ - const ISM_MODE last_ism_mode, /* i : last ISM mode */ - const int16_t num_obj /* i : number of objects in the bitstream */ +/*-------------------------------------------------------------------------* + * ivas_ism_bitrate_switching() + * + * + *-------------------------------------------------------------------------*/ + +static ivas_error ivas_ism_bitrate_switching( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const int16_t nchan_transport_old, /* i : last number of transport channels */ + const ISM_MODE last_ism_mode, /* i : last ISM mode */ + const int16_t num_obj /* i : number of objects in the bitstream */ ) { +#ifndef CORECODER_BITRATE_SWITCHING int16_t sce_id; +#endif ivas_error error; int32_t element_brate_tmp[MAX_NUM_OBJECTS]; error = IVAS_ERR_OK; ivas_ism_config( st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, num_obj, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); + st_ivas->nSCE = st_ivas->nchan_transport; - if ( st_ivas->nchan_transport > last_nchan_trans ) +#ifdef CORECODER_BITRATE_SWITCHING + ivas_corecoder_dec_reconfig( st_ivas, nchan_transport_old, 0, nchan_transport_old, 0 ); +#else + if ( st_ivas->nchan_transport > nchan_transport_old ) { /* Initialize for new bitrate */ - for ( sce_id = 0; sce_id < last_nchan_trans; sce_id++ ) + for ( sce_id = 0; sce_id < nchan_transport_old; sce_id++ ) { st_ivas->hSCE[sce_id]->element_brate = st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport; st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */ } /* Initialize some memories */ - for ( sce_id = last_nchan_trans; sce_id < st_ivas->nchan_transport; sce_id++ ) + for ( sce_id = nchan_transport_old; sce_id < st_ivas->nchan_transport; sce_id++ ) { if ( ( error = create_sce_dec( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) { @@ -1048,17 +1060,21 @@ static ivas_error ivas_ism_format_bitrate_switching( } /* Destroy the core coder memory */ - for ( ; sce_id < last_nchan_trans; sce_id++ ) + for ( ; sce_id < nchan_transport_old; sce_id++ ) { destroy_sce_dec( st_ivas->hSCE[sce_id] ); st_ivas->hSCE[sce_id] = NULL; } } +#endif +#ifdef CORECODER_BITRATE_SWITCHING + ivas_hp20_dec_reconfig( st_ivas, nchan_transport_old ); +#else /* destroy the memory of hp20*/ if ( st_ivas->mem_hp20_out != NULL ) { - for ( sce_id = 0; sce_id < last_nchan_trans; sce_id++ ) + for ( sce_id = 0; sce_id < nchan_transport_old; sce_id++ ) { count_free( st_ivas->mem_hp20_out[sce_id] ); st_ivas->mem_hp20_out[sce_id] = NULL; @@ -1091,7 +1107,7 @@ static ivas_error ivas_ism_format_bitrate_switching( set_f( st_ivas->mem_hp20_out[sce_id], 0.0f, L_HP20_MEM ); } - +#endif /* Initialize the needed renderer struct and destroy the unnecessary renderer struct */ @@ -1218,7 +1234,7 @@ ivas_error ivas_ism_dec_config( ISM_MODE last_ism_mode; ivas_error error; #ifdef ISM_BITRATE_SWITCHING - int16_t last_nchan_trans; + int16_t nchan_transport_old; #endif error = IVAS_ERR_OK; @@ -1229,10 +1245,10 @@ ivas_error ivas_ism_dec_config( last_ism_mode = st_ivas->ism_mode; #ifdef ISM_BITRATE_SWITCHING /* Assumes that num of input objects are constant */ - last_nchan_trans = num_obj; + nchan_transport_old = num_obj; if ( last_ism_mode == ISM_MODE_PARAM ) { - last_nchan_trans = 2; + nchan_transport_old = 2; } #endif @@ -1255,12 +1271,11 @@ ivas_error ivas_ism_dec_config( { #ifdef ISM_BITRATE_SWITCHING /* ISM bit-rate switching */ - if ( ( st_ivas->hDecoderConfig->last_ivas_total_brate != IVAS_SID_5k2 ) && ( st_ivas->hDecoderConfig->last_ivas_total_brate != FRAME_NO_DATA ) ) + if ( st_ivas->hDecoderConfig->last_ivas_total_brate != IVAS_SID_5k2 && st_ivas->hDecoderConfig->last_ivas_total_brate != FRAME_NO_DATA ) { if ( ( st_ivas->ism_mode != last_ism_mode ) || ( st_ivas->hDecoderConfig->ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) ) { - ivas_ism_format_bitrate_switching( st_ivas, last_nchan_trans, last_ism_mode, num_obj ); - st_ivas->nSCE = st_ivas->nchan_transport; + ivas_ism_bitrate_switching( st_ivas, nchan_transport_old, last_ism_mode, num_obj ); } } #else diff --git a/lib_enc/ivas_ism_param_enc.c b/lib_enc/ivas_ism_param_enc.c index c104c855c7..a77f6d3615 100644 --- a/lib_enc/ivas_ism_param_enc.c +++ b/lib_enc/ivas_ism_param_enc.c @@ -42,6 +42,10 @@ #include "wmops.h" +#ifdef CORECODER_BITRATE_SWITCHING +static ivas_error ivas_hp20_reconfig( Encoder_Struct *st_ivas, const int16_t nchan_hp20_old ); +#endif + /*------------------------------------------------------------------------- * Local function definitions *------------------------------------------------------------------------*/ @@ -416,26 +420,33 @@ ivas_error ivas_ism_enc_config( ivas_error error; ISM_MODE last_ism_mode; #ifdef ISM_BITRATE_SWITCHING - int16_t last_nSCE; +#ifdef CORECODER_BITRATE_SWITCHING + int16_t nchan_transport_old; +#else + int16_t nSCE_old, nchan_transport_old; int16_t sce_id, n; +#endif #endif error = IVAS_ERR_OK; - last_ism_mode = st_ivas->ism_mode; -#ifdef ISM_BITRATE_SWITCHING - last_nSCE = st_ivas->nSCE; -#endif /* select ISM format mode */ st_ivas->ism_mode = ivas_ism_mode_select( st_ivas->hEncoderConfig->nchan_inp, st_ivas->hEncoderConfig->ivas_total_brate ); #ifdef ISM_BITRATE_SWITCHING - /* ISM bit-rate switching */ + /* ISM bit-rate switching */ if ( ( st_ivas->ism_mode != last_ism_mode ) || ( st_ivas->hEncoderConfig->ivas_total_brate != st_ivas->hEncoderConfig->last_ivas_total_brate ) ) { int32_t element_brate_tmp[MAX_NUM_OBJECTS]; +#ifndef CORECODER_BITRATE_SWITCHING Indice *ind_list_sce, *ind_list_metadata; +#endif + +#ifndef CORECODER_BITRATE_SWITCHING + nSCE_old = st_ivas->nSCE; +#endif + nchan_transport_old = st_ivas->nchan_transport; /* Reset and Initialize */ if ( st_ivas->ism_mode == ISM_MODE_PARAM ) @@ -452,10 +463,13 @@ ivas_error ivas_ism_enc_config( ivas_ism_config( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_inp, NULL, NULL, NULL, element_brate_tmp, NULL, NULL ); - if ( st_ivas->nSCE > last_nSCE ) +#ifdef CORECODER_BITRATE_SWITCHING + ivas_corecoder_enc_reconfig( st_ivas, nchan_transport_old, 0, nchan_transport_old ); +#else + if ( st_ivas->nSCE > nSCE_old ) { /* Reconfigure the core coders */ - for ( sce_id = 0; sce_id < last_nSCE; sce_id++ ) + for ( sce_id = 0; sce_id < nSCE_old; sce_id++ ) { copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 ); st_ivas->hSCE[sce_id]->element_brate = st_ivas->hEncoderConfig->ivas_total_brate / st_ivas->nchan_transport; @@ -466,7 +480,7 @@ ivas_error ivas_ism_enc_config( ind_list_sce = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list; ind_list_metadata = st_ivas->hSCE[0]->hMetaData->ind_list; - for ( sce_id = last_nSCE; sce_id < st_ivas->nSCE; sce_id++ ) + for ( sce_id = nSCE_old; sce_id < st_ivas->nSCE; sce_id++ ) { /* Initialize the Core Coder */ if ( ( error = create_sce_enc( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK ) @@ -493,7 +507,7 @@ ivas_error ivas_ism_enc_config( } /* Delete the extra memory */ - for ( sce_id = st_ivas->nSCE; sce_id < last_nSCE; sce_id++ ) + for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ ) { if ( st_ivas->hSCE[sce_id] != NULL ) { @@ -502,6 +516,7 @@ ivas_error ivas_ism_enc_config( } } } +#endif if ( st_ivas->ism_mode == ISM_MODE_PARAM && last_ism_mode == ISM_MODE_DISC ) { @@ -519,10 +534,13 @@ ivas_error ivas_ism_enc_config( st_ivas->hDirAC = NULL; } +#ifdef CORECODER_BITRATE_SWITCHING + ivas_hp20_reconfig( st_ivas, nchan_transport_old ); +#else /* destroy the memory of hp20*/ if ( st_ivas->mem_hp20_in != NULL ) { - for ( sce_id = 0; sce_id < last_nSCE; sce_id++ ) + for ( sce_id = 0; sce_id < nSCE_old; sce_id++ ) { count_free( st_ivas->mem_hp20_in[sce_id] ); st_ivas->mem_hp20_in[sce_id] = NULL; @@ -556,6 +574,7 @@ ivas_error ivas_ism_enc_config( set_f( st_ivas->mem_hp20_in[sce_id], 0.0f, L_HP20_MEM ); } +#endif } #else /* ISM format switching */ @@ -568,3 +587,90 @@ ivas_error ivas_ism_enc_config( return error; } + + +#ifdef CORECODER_BITRATE_SWITCHING +// VE: this is the same function as at the decoder -> harmonize them to a new file ivas_corecoder_reconfig.c +/*-------------------------------------------------------------------* + * ivas_hp20_dec_reconfig() + * + * Allocate, initialize, and configure HP20 memory handles in case of bitrate switching + *-------------------------------------------------------------------*/ + +static ivas_error ivas_hp20_reconfig( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const int16_t nchan_hp20_old /* i : number of HP20 filters in previous frame */ +) +{ + int16_t i, nchan_hp20; + float **old_mem_hp20_out; + ivas_error error; + + error = IVAS_ERR_OK; + + /*-----------------------------------------------------------------* + * HP20 memories + *-----------------------------------------------------------------*/ + + nchan_hp20 = getNumChanAnalysis( st_ivas ); + + if ( nchan_hp20 > nchan_hp20_old ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_out = st_ivas->mem_hp20_in; + st_ivas->mem_hp20_in = NULL; + + if ( ( st_ivas->mem_hp20_in = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < nchan_hp20_old; i++ ) + { + st_ivas->mem_hp20_in[i] = old_mem_hp20_out[i]; + old_mem_hp20_out[i] = NULL; + } + /* create additional hp20 memories */ + for ( ; i < nchan_hp20; i++ ) + { + if ( ( st_ivas->mem_hp20_in[i] = (float *) count_malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM ); + } + + count_free( old_mem_hp20_out ); + old_mem_hp20_out = NULL; + } + else if ( nchan_hp20 < nchan_hp20_old ) + { + /* save old mem_hp_20 pointer */ + old_mem_hp20_out = st_ivas->mem_hp20_in; + st_ivas->mem_hp20_in = NULL; + + if ( ( st_ivas->mem_hp20_in = (float **) count_malloc( nchan_hp20 * sizeof( float * ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) ); + } + + for ( i = 0; i < nchan_hp20; i++ ) + { + st_ivas->mem_hp20_in[i] = old_mem_hp20_out[i]; + old_mem_hp20_out[i] = NULL; + } + /* remove superfluous hp20 memories */ + for ( ; i < nchan_hp20_old; i++ ) + { + count_free( old_mem_hp20_out[i] ); + old_mem_hp20_out[i] = NULL; + } + + count_free( old_mem_hp20_out ); + old_mem_hp20_out = NULL; + } + + return error; +} +#endif -- GitLab From 4acd8d18e4fb0c556fc218afa994ee51c5f986eb Mon Sep 17 00:00:00 2001 From: Srikanth Korse Date: Sat, 15 Oct 2022 10:46:32 +0200 Subject: [PATCH 5/5] addition of switching profile file for ISM --- scripts/switchPaths/sw_24k4_256k.bin | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 scripts/switchPaths/sw_24k4_256k.bin diff --git a/scripts/switchPaths/sw_24k4_256k.bin b/scripts/switchPaths/sw_24k4_256k.bin new file mode 100644 index 0000000000..dd29526180 --- /dev/null +++ b/scripts/switchPaths/sw_24k4_256k.bin @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73897d458d4bc2cea9a9cc55f321edd0f11d28275ba24d45de8295a2fc772833 +size 41760 -- GitLab