From dec683eb208c6046f7cd6b25f79c4cc85d78aaef Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 19 Aug 2025 15:21:38 +0200 Subject: [PATCH 1/2] port MR --- lib_com/ivas_cnst.h | 1 + lib_com/ivas_prot_fx.h | 50 ++++++---- lib_com/options.h | 1 + lib_dec/ivas_init_dec_fx.c | 73 ++++++++------ lib_dec/ivas_ism_renderer_fx.c | 5 +- lib_dec/ivas_jbm_dec_fx.c | 27 ++++-- lib_dec/ivas_masa_dec_fx.c | 30 +++--- lib_dec/ivas_omasa_dec_fx.c | 168 ++++++++++++++++++++++++++------- lib_dec/ivas_sba_dec_fx.c | 2 + lib_dec/ivas_stat_dec.h | 2 + lib_dec/lib_dec_fx.c | 11 +++ lib_enc/ivas_masa_enc_fx.c | 139 ++++++++++++++++++++++++--- lib_enc/ivas_omasa_enc_fx.c | 61 +++++++++++- lib_enc/ivas_stat_enc.h | 20 +++- 14 files changed, 467 insertions(+), 123 deletions(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 23028e020..ab6de21b7 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -154,6 +154,7 @@ typedef enum #else RENDERER_OSBA_LS #endif + } RENDERER_TYPE; #define MAX_FREQUENCY_BANDS 64 diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 8efa8b896..1f92a0965 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -165,38 +165,43 @@ void ivas_omasa_combine_separate_ism_with_masa_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Word32 *output[], /* o : output synthesis signal */ Word16 *output_q, /* i/o: output Q value */ - const int16_t nchan_ism, /* i : number of ISMs */ - const int16_t output_frame /* i : output frame length per channel */ + const Word16 nchan_ism, /* i : number of ISMs */ + const Word16 output_frame /* i : output frame length per channel */ ); +#ifdef FIX_1161_REDUCE_OMASA_HEAP +ivas_error ivas_omasa_objects_delay_open_fx( +#else ivas_error ivas_omasa_render_objects_from_mix_open_fx( +#endif Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); void ivas_omasa_render_objects_from_mix_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Word32 *output[], /* o : output synthesis signal */ - const int16_t nchan_ism, /* i : number of ISMs */ - const int16_t output_frame, /* i : output frame length per channel */ + const Word16 nchan_ism, /* i : number of ISMs */ + const Word16 output_frame, /* i : output frame length per channel */ Word16 *output_q /* i/o: output Q value */ ); #endif ivas_error ivas_omasa_ism_metadata_dec_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - const Word32 ism_total_brate, /* i : ISM total bitrate */ - Word16 *nchan_ism, /* o : number of ISM separated channels */ - Word16 *nchan_transport_ism, /* o : number of ISM TCs */ - const Word16 dirac_bs_md_write_idx, /* i : DirAC bitstream write index */ - Word16 nb_bits_metadata[] /* o : number of ISM metadata bits */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const Word32 ism_total_brate, /* i : ISM total bitrate */ + Word16 *nchan_ism, /* o : number of ISM separated channels */ + Word16 *nchan_transport_ism, /* o : number of ISM TCs */ + const Word16 dirac_bs_md_write_idx, /* i : DirAC bitstream write index */ + Word16 nb_bits_metadata[] /* o : number of ISM metadata bits */ ); + ivas_error ivas_omasa_dec_config_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ - UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + UWord16 *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ Word16 *num_src, Word16 SrcInd[MAX_NUM_TDREND_CHANNELS], - Word16 *data /* o : output synthesis signal */ + Word16 *data /* o : output synthesis signal */ ); void ivas_omasa_modify_masa_energy_ratios_fx( @@ -205,9 +210,9 @@ void ivas_omasa_modify_masa_energy_ratios_fx( ); Word32 calculate_cpe_brate_MASA_ISM_fx( - const ISM_MODE ism_mode, /* i : ism mode */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - const Word16 nchan_ism /* i : number of objects */ + const ISM_MODE ism_mode, /* i : ism mode */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + const Word16 nchan_ism /* i : number of objects */ ); Word16 ivas_jbm_dec_get_num_tc_channels_fx( @@ -3162,8 +3167,8 @@ void stereo_tcx_core_enc( Word16 pitch_buf_fx[NB_SUBFR16k], /* o : pitch for each subframe, Q6 */ const Word16 last_element_mode, /* i : last element mode, Q0 */ const Word16 vad_hover_flag, /* i : VAD hangover flag, Q0 */ - Word16 Q_new ); - + Word16 Q_new +); Word16 transient_analysis_ivas_fx( TRAN_DET_HANDLE hTranDet, /* i : handle transient detection */ @@ -3289,20 +3294,24 @@ void ivas_fb_mixer_get_windowed_fr_fx( const Word16 length, /* i : number of new samples in time slot */ const Word16 mdft_len, /* i : MDFT frame length */ const Word16 nchan_fb_in, /* i : number of analysis channels */ - Word16 gb ); + Word16 gb +); + void ivas_omasa_set_config_fx( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ const Word32 input_Fs, /* i : Input sample rate */ const ISM_MODE ism_mode /* i : ISM mode */ ); + Word16 ivas_omasa_ener_brate_fx( const Word16 nchan_ism, /* i : number of ISMs */ const Word32 ivas_total_brate, /* i : IVAS total bitrate */ Word32 *data_f[], /* i : Input / transport audio signals */ const Word16 input_frame, /* i : Input frame size */ - Word16 data_e /*i:exponent for data_f */ + const Word16 data_e /* i : exponent for data_f */ ); + void computeDiffuseness_mdft_fx( Word32 **buffer_intensity[DIRAC_NUM_DIMS], const Word32 *buffer_energy, @@ -3341,6 +3350,7 @@ UWord8 ivas_masa_surrcoh_signicant_fx( ivas_error ivas_mcmasa_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ); + void ivas_mcmasa_enc_close_fx( MCMASA_ENC_HANDLE *hMcMasa, /* i/o: encoder McMASA handle */ const Word32 input_Fs /* i : input sampling rate */ diff --git a/lib_com/options.h b/lib_com/options.h index 785ea51ed..0714cb0bc 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -87,6 +87,7 @@ #define FIX_1372_ISAR_POST_REND #define NONBE_FIX_984_OMASA_EXT_OUTPUT /* Nokia: issue #984: complete the OMASA EXT output implementation */ +#define FIX_1161_REDUCE_OMASA_HEAP /* VA: reduction of OMASA heap memory */ #define USE_NEW_HRTF_BINARY_FILE_FORMAT /* Orange: to activate when decided to change the hrtf binary file format */ #define FIX_WARNING_RENDER_CONFIG /* Orange: fix warning on windows build */ #define FIX_1052_EXT_OUTPUT /* VA: issue 1052: define EXT decoder output configuration for stereo and MC formats */ diff --git a/lib_dec/ivas_init_dec_fx.c b/lib_dec/ivas_init_dec_fx.c index 89abe3f0c..0f7d77858 100644 --- a/lib_dec/ivas_init_dec_fx.c +++ b/lib_dec/ivas_init_dec_fx.c @@ -1359,7 +1359,6 @@ ivas_error ivas_init_decoder_fx( } } - /*--------------------------------------------------------------------* * Allocate and initialize HRTF Statistics handle *--------------------------------------------------------------------*/ @@ -1532,7 +1531,6 @@ ivas_error ivas_init_decoder_fx( } } - test(); test(); #ifdef NONBE_FIX_1052_SBA_EXT_FIX @@ -1727,7 +1725,6 @@ ivas_error ivas_init_decoder_fx( } } - test(); test(); IF( NE_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && NE_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) @@ -1865,6 +1862,7 @@ ivas_error ivas_init_decoder_fx( { k = add( k, 1 ); } + test(); IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) { @@ -2198,7 +2196,6 @@ ivas_error ivas_init_decoder_fx( } } - /*-----------------------------------------------------------------* * Allocate and initialize HP20 filter memories *-----------------------------------------------------------------*/ @@ -2350,10 +2347,8 @@ ivas_error ivas_init_decoder_fx( IF( ( EQ_32( st_ivas->ivas_format, MC_FORMAT ) ) && ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) ) { granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS ); - n_channels_transport_jbm = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); - IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, TC_BUFFER_MODE_RENDERER, n_channels_transport_jbm, MC_PARAMUPMIX_MAX_INPUT_CHANS, MC_PARAMUPMIX_MAX_INPUT_CHANS, granularity ) ), IVAS_ERR_OK ) ) { return error; @@ -2380,10 +2375,12 @@ ivas_error ivas_init_decoder_fx( /* Allocate TD renderer for the objects in DISC mode */ Word16 SrcInd[MAX_NUM_TDREND_CHANNELS]; Word16 num_src; + IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) ) { return error; } + Word16 nchan_rend = num_src; move16(); test(); @@ -2403,6 +2400,7 @@ ivas_error ivas_init_decoder_fx( SrcSpatial_p->q_Pos_p = Q31; move16(); } + IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { IF( NE_32( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) ) @@ -2411,16 +2409,50 @@ ivas_error ivas_init_decoder_fx( } } +#ifdef FIX_1161_REDUCE_OMASA_HEAP + /* Allocate memory for delay buffer within 'hMasaIsmData' */ + IF( NE_32( ( error = ivas_omasa_objects_delay_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } +#endif } + + test(); + test(); + test(); + IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) + { + /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + IF( NE_32( ( error = ivas_omasa_objects_delay_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + { + return error; + } +#endif + + IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) + { + return error; + } + } + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) ) { /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + IF( NE_32( ( error = ivas_omasa_objects_delay_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else error = ivas_omasa_render_objects_from_mix_open_fx( st_ivas ); move32(); @@ -2428,12 +2460,9 @@ ivas_error ivas_init_decoder_fx( { return error; } +#endif - error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, DIRAC_OPEN, 0, - st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, 0, 0 ); - move32(); - - IF( NE_32( error, IVAS_ERR_OK ) ) + IF( ( ( error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, DIRAC_OPEN, 0, st_ivas->ivas_format, st_ivas->mc_mode, output_Fs, 0, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -2442,25 +2471,12 @@ ivas_error ivas_init_decoder_fx( IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) ) { /* Allocate 'hIsmRendererData' handle */ - error = ivas_omasa_combine_separate_ism_with_masa_open_fx( st_ivas ); - move32(); - IF( NE_32( error, IVAS_ERR_OK ) ) + IF( ( ( error = ivas_omasa_combine_separate_ism_with_masa_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } } #endif - test(); - test(); - test(); - IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) - { - /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ - IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) - { - return error; - } - } } test(); @@ -2536,7 +2552,6 @@ ivas_error ivas_init_decoder_fx( } } - #ifndef NONBE_FIX_MC_LFE_LPF /*-----------------------------------------------------------------* * LFE handles for rendering after rendering to adjust LFE delay to binaural filter delay @@ -2573,7 +2588,6 @@ ivas_error ivas_init_decoder_fx( set32_fx( st_ivas->hLFE->prior_out_buffer_fx, 0, L_FRAME48k ); } #endif - /*-----------------------------------------------------------------* * CLDFB handles for rendering *-----------------------------------------------------------------*/ @@ -2634,6 +2648,7 @@ ivas_error ivas_init_decoder_fx( /*-----------------------------------------------------------------* * LFE handles for rendering after rendering to adjust LFE delay to filter delay *-----------------------------------------------------------------*/ + test(); IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) ) { @@ -2738,6 +2753,7 @@ ivas_error ivas_init_decoder_fx( /*-----------------------------------------------------------------* * Allocate floating-point output audio buffers *-----------------------------------------------------------------*/ + st_ivas->p_out_len = ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); move16(); FOR( n = 0; n < ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ ) @@ -2754,9 +2770,11 @@ ivas_error ivas_init_decoder_fx( { st_ivas->p_output_fx[n] = NULL; } + return error; } + /*------------------------------------------------------------------------- * destroy_core_dec() * @@ -3686,6 +3704,5 @@ static ivas_error doSanityChecks_IVAS( } } #endif - return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_ism_renderer_fx.c b/lib_dec/ivas_ism_renderer_fx.c index 5ebae5c2f..3aad49c26 100644 --- a/lib_dec/ivas_ism_renderer_fx.c +++ b/lib_dec/ivas_ism_renderer_fx.c @@ -110,6 +110,7 @@ ivas_error ivas_ism_renderer_open_fx( interpolator_length = init_interpolator_length; move16(); } + IF( ( st_ivas->hIsmRendererData->interpolator_fx = (Word16 *) malloc( sizeof( Word16 ) * init_interpolator_length ) ) == NULL ) { return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for ISM renderer interpolator\n" ) ); @@ -411,7 +412,7 @@ void ivas_ism_get_stereo_gains_fx( } /*-------------------------------------------------------------------------* - * ivas_masa_oism_separate_object_renderer_open() + * ivas_omasa_separate_object_renderer_open() * * Open structures, reserve memory, and init values. *-------------------------------------------------------------------------*/ @@ -452,6 +453,7 @@ ivas_error ivas_omasa_separate_object_renderer_open( st_ivas->hIsmRendererData->interpolator_len = interpolator_length; move16(); +#ifndef FIX_1161_REDUCE_OMASA_HEAP st_ivas->hMasaIsmData->delayBuffer_size = extract_l( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES ); move16(); @@ -480,6 +482,7 @@ ivas_error ivas_omasa_separate_object_renderer_open( } set32_fx( st_ivas->hMasaIsmData->delayBuffer_fx[i], 0, st_ivas->hMasaIsmData->delayBuffer_size ); } +#endif return IVAS_ERR_OK; } diff --git a/lib_dec/ivas_jbm_dec_fx.c b/lib_dec/ivas_jbm_dec_fx.c index a0595eddd..59b4a2994 100644 --- a/lib_dec/ivas_jbm_dec_fx.c +++ b/lib_dec/ivas_jbm_dec_fx.c @@ -654,16 +654,17 @@ ivas_error ivas_jbm_dec_tc_fx( { Word16 q_shift = 0; move16(); + ivas_masa_prerender_fx( st_ivas, p_output_fx, &q_shift, output_frame, nchan_remapped ); FOR( i = 0; i < 2; i++ ) { Scale_sig32( p_output_fx[i], output_frame, negate( q_shift ) ); } + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT test(); /* external output */ - IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && - EQ_32( st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) ) + IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_32( st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) ) { FOR( n = 0; n < st_ivas->nchan_ism; n++ ) { @@ -821,6 +822,7 @@ ivas_error ivas_jbm_dec_tc_fx( ivas_omasa_rearrange_channels_fx( p_output_fx, nchan_transport_ism, output_frame ); #endif + IF( st_ivas->hDecoderConfig->Opt_tsm ) { ivas_jbm_dec_copy_masa_meta_to_buffer( st_ivas ); @@ -1775,23 +1777,31 @@ void ivas_jbm_dec_feed_tc_to_renderer_fx( } #endif - if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_DIRAC ) + test(); + IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) ) { - int16_t num_objects; + Word16 num_objects; /* Delay the signal to match CLDFB delay. Delay the whole buffer. */ num_objects = 0; - IF( ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC ) + move16(); + + test(); + test(); + IF( ( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) { num_objects = 1; + move16(); } ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { num_objects = st_ivas->nchan_ism; + move16(); } FOR( n = 0; n < num_objects; n++ ) { - if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) + test(); + IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) { v_multc_fixed_16( st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], OMASA_TDREND_MATCHING_GAIN_FX, st_ivas->hTcBuffer->tc_fx[CPE_CHANNELS + n], st_ivas->hTcBuffer->n_samples_available ); } @@ -2178,8 +2188,7 @@ ivas_error ivas_jbm_dec_render_fx( ivas_omasa_dirac_rend_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ); } #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT - ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) || - EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) ) + ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) ) { ivas_jbm_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx ); ivas_omasa_rearrange_channels_fx( p_output_fx, st_ivas->nchan_ism, *nSamplesRendered ); @@ -2809,7 +2818,7 @@ ivas_error ivas_jbm_dec_flush_renderer_fx( IF( EQ_16( mc_mode_old, MC_MODE_MCT ) ) { #ifdef NONBE_FIX_1070_USAN_SEGFAULT_MC_TO_BIN_BTSW_HEADROT - int16_t crendInPlaceRotation = FALSE; + Word16 crendInPlaceRotation = FALSE; test(); test(); diff --git a/lib_dec/ivas_masa_dec_fx.c b/lib_dec/ivas_masa_dec_fx.c index 3be3f4601..0f22a8b29 100644 --- a/lib_dec/ivas_masa_dec_fx.c +++ b/lib_dec/ivas_masa_dec_fx.c @@ -57,7 +57,7 @@ * Local function prototypes *-----------------------------------------------------------------------*/ -static Word16 rint_fx( Word32 num ); +static Word16 rint_fx( const Word32 num ); static void index_16bits_fx( IVAS_QMETADATA_HANDLE hQMetaData, SPHERICAL_GRID_DATA *Sph_Grid16 ); @@ -703,11 +703,12 @@ ivas_error ivas_masa_decode_fx( move16(); } #endif + IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) { IF( hQMetaData->q_direction == NULL ) { - if ( NE_32( ( error = ivas_masa_dec_config_fx( st_ivas ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_masa_dec_config_fx( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } @@ -858,13 +859,12 @@ ivas_error ivas_masa_dec_open_fx( ism_total_brate = 0; move32(); + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT /* ISM metadata */ test(); test(); - if ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && - st_ivas->hIsmMetaData[0] != NULL && - EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && st_ivas->hIsmMetaData[0] != NULL && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { /* these are not needed -> clean. EXT metafile writer in OMASA needs only the number of ISMs and writes default null-data */ ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 ); @@ -958,6 +958,7 @@ ivas_error ivas_masa_dec_open_fx( nchan_transport = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); nchan_to_allocate = nchan_transport; move16(); + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT test(); test(); @@ -972,9 +973,7 @@ ivas_error ivas_masa_dec_open_fx( move16(); } #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT - ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && - ( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) || - EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) ) ) { nchan_transport = add( st_ivas->nchan_transport, st_ivas->nchan_ism ); nchan_to_allocate = add( st_ivas->nchan_transport, st_ivas->nchan_ism ); @@ -1155,7 +1154,7 @@ static ivas_error ivas_masa_dec_config_fx( } ELSE { - st_ivas->hQMetaData->q_direction[i].cfg.nblocks = 4; + st_ivas->hQMetaData->q_direction[i].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; } move16(); @@ -2069,9 +2068,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( tc_nchan_to_allocate = add( tc_nchan_to_allocate, 1 ); } #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT - ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && - ( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) || - EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) ) ) + ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) ) ) { tc_nchan_transport = add( st_ivas->nchan_transport, st_ivas->nchan_ism ); tc_nchan_to_allocate = add( st_ivas->nchan_transport, st_ivas->nchan_ism ); @@ -2081,7 +2078,7 @@ ivas_error ivas_masa_dec_reconfigure_fx( test(); IF( NE_16( tc_nchan_transport, st_ivas->hTcBuffer->nchan_transport_jbm ) || NE_16( tc_nchan_to_allocate, st_ivas->hTcBuffer->nchan_transport_internal ) || NE_16( buffer_mode_new, st_ivas->hTcBuffer->tc_buffer_mode ) ) { - if ( NE_32( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, buffer_mode_new, tc_nchan_transport, tc_nchan_to_allocate, tc_nchan_to_allocate, n_samples_granularity ), IVAS_ERR_OK ) ) + IF( NE_32( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, buffer_mode_new, tc_nchan_transport, tc_nchan_to_allocate, tc_nchan_to_allocate, n_samples_granularity ), IVAS_ERR_OK ) ) { return error; } @@ -3518,6 +3515,7 @@ static Word16 ivas_decode_masaism_metadata_fx( hMasaIsmData->energy_ratio_ism_fx[dir][meta_write_index][b] = energy_ratio_ism_fx[i][band][dir]; move32(); } + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT IF( hMasaIsmData->hExtData != NULL ) { @@ -3533,11 +3531,13 @@ static Word16 ivas_decode_masaism_metadata_fx( return sub( nb_bits_read, *next_bit_pos ); } + /* Fixed point implementation of rint(). */ -static Word16 rint_fx( /* returns in Q0 */ - Word32 num /* num in Q0 */ +/* returns in Q0 */ +static Word16 rint_fx( + const Word32 num /* num in Q0 */ ) { Word32 frac_part = L_and( L_abs( num ), 0x0000FFFF ); // Q15 diff --git a/lib_dec/ivas_omasa_dec_fx.c b/lib_dec/ivas_omasa_dec_fx.c index bde77e968..a85a2a259 100644 --- a/lib_dec/ivas_omasa_dec_fx.c +++ b/lib_dec/ivas_omasa_dec_fx.c @@ -116,6 +116,11 @@ static Word16 interpolator_table_16k_q15[] = { 28672, 29082, 29491, 29901, 30310, 30720, 31130, 31539, 31949, 32358 }; + +/*------------------------------------------------------------------------- + * Local functions + *------------------------------------------------------------------------*/ + /** * Calculate mantissa (Q31) * gain (Q31). * @@ -123,7 +128,12 @@ static Word16 interpolator_table_16k_q15[] = { * Adjust the result so that accuracy of the mantissa multiplication is maximixed * and the corresponding exponent is minimized. */ -static Word32 mult32_mantissa_fx( Word32 mantissa, Word32 gain, Word16 exp, Word16 *exp_result ) + +static Word32 mult32_mantissa_fx( + const Word32 mantissa, + const Word32 gain, + const Word16 exp, + Word16 *exp_result ) { Word64 mult = W_mult_32_32( mantissa, gain ); // Q31 * Q31 -> Q63 Word16 norm = W_norm( mult ); @@ -133,10 +143,16 @@ static Word32 mult32_mantissa_fx( Word32 mantissa, Word32 gain, Word16 exp, Word return result; } + /** * Calculate re^2 + im^2 using exponent (Q0) and mantissa (Q31) format. */ -static Word32 sample_energy_fx( Word32 re_m, Word16 re_e, Word32 im_m, Word16 im_e, Word16 *exp_result ) +static Word32 sample_energy_fx( + const Word32 re_m, + const Word16 re_e, + const Word32 im_m, + const Word16 im_e, + Word16 *exp_result ) { Word16 re_exp = add( re_e, re_e ); Word32 re_mult = mult32_mantissa_fx( re_m, re_m, re_exp, &re_exp ); @@ -149,10 +165,18 @@ static Word32 sample_energy_fx( Word32 re_m, Word16 re_e, Word32 im_m, Word16 im return BASOP_Util_Add_Mant32Exp( re_mult, re_exp, im_mult, im_exp, exp_result ); } + /** * Accumulate sum of re^2 + im^2 over the specified length using exponent (Q0) and mantissa (Q31) format. */ -static void sample_energy_acc_fx( Word32 *re_m, Word16 *re_e, Word32 *im_m, Word16 *im_e, Word32 *out_m, Word16 *out_e, Word16 len ) +static void sample_energy_acc_fx( + Word32 *re_m, + Word16 *re_e, + Word32 *im_m, + Word16 *im_e, + Word32 *out_m, + Word16 *out_e, + const Word16 len ) { Word16 i; @@ -168,16 +192,18 @@ static void sample_energy_acc_fx( Word32 *re_m, Word16 *re_e, Word32 *im_m, Word *out_m = BASOP_Util_Add_Mant32Exp( *out_m, *out_e, mantissa, exp, out_e ); move32(); } + + return; } // Multiplication of vector (comprising of exponent and mantissa parts) by constant value (Q31) static void v_multc_exp_mantissa_fx( const Word32 *in_mantissa, const Word16 *in_exp, - Word32 c, + const Word32 c, Word32 *out_mantissa, Word16 *out_exp, - Word16 len ) + const Word16 len ) { Word16 i; @@ -186,16 +212,18 @@ static void v_multc_exp_mantissa_fx( out_mantissa[i] = mult32_mantissa_fx( in_mantissa[i], c, in_exp[i], &out_exp[i] ); move32(); } + return; } + // Multiplication of vector (comprising of exponent and mantissa parts) by constant acumulate to the output static void v_multc_acc_exp_mantissa_fx( const Word32 *in_mantissa, const Word16 *in_exp, - Word32 c, + const Word32 c, Word32 *out_mantissa, Word16 *out_exp, - Word16 len ) + const Word16 len ) { Word16 i; @@ -205,15 +233,23 @@ static void v_multc_acc_exp_mantissa_fx( Word32 mantissa = mult32_mantissa_fx( in_mantissa[i], c, in_exp[i], &exp ); move32(); - out_mantissa[i] = BASOP_Util_Add_Mant32Exp( out_mantissa[i], out_exp[i], - mantissa, exp, &out_exp[i] ); + out_mantissa[i] = BASOP_Util_Add_Mant32Exp( out_mantissa[i], out_exp[i], mantissa, exp, &out_exp[i] ); move32(); } + + return; } + // Calculate min( 4, sqrtf( target / proto ) ) // target and proto values are expressed using exponent and mantissa -static Word32 get_processing_gain_fx( Word32 proto_m, Word16 proto_e, Word32 target_m, Word16 target_e, Word16 *exp ) + +static Word32 get_processing_gain_fx( + const Word32 proto_m, + const Word16 proto_e, + const Word32 target_m, + const Word16 target_e, + Word16 *exp ) { Word16 b = extract_h( proto_m ); IF( EQ_16( b, 0 ) ) @@ -244,7 +280,12 @@ static Word32 get_processing_gain_fx( Word32 proto_m, Word16 proto_e, Word32 tar return sqrt_mantissa; } -static void mantissa_exp_to_qvalue( Word16 *exp, Word32 *output, Word16 target_exp, Word16 len ) + +static void mantissa_exp_to_qvalue( + Word16 *exp, + Word32 *output, + const Word16 target_exp, + const Word16 len ) { Word16 bin; @@ -261,11 +302,12 @@ static void mantissa_exp_to_qvalue( Word16 *exp, Word32 *output, Word16 target_e output[bin] = W_sat_l( W_shr( output[bin], shift ) ); } } + + return; } #endif - /*-------------------------------------------------------------------* * ivas_omasa_data_open() * @@ -375,6 +417,7 @@ ivas_error ivas_omasa_data_open_fx( move32(); } #endif + st_ivas->hMasaIsmData = hMasaIsmData; return IVAS_ERR_OK; @@ -408,6 +451,7 @@ void ivas_omasa_data_close_fx( free( ( *hMasaIsmData )->delayBuffer_fx ); ( *hMasaIsmData )->delayBuffer_fx = NULL; } + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT IF( ( *hMasaIsmData )->hExtData != NULL ) { @@ -416,6 +460,7 @@ void ivas_omasa_data_close_fx( move32(); } #endif + free( *hMasaIsmData ); *hMasaIsmData = NULL; @@ -565,6 +610,7 @@ ivas_error ivas_omasa_dec_config_fx( /* ISM MD reconfig. */ n_MD = 0; move16(); + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { @@ -697,12 +743,13 @@ ivas_error ivas_omasa_dec_config_fx( IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { /* Allocate TD renderer for the objects in DISC mode */ - IF( st_ivas->hBinRendererTd == NULL ) + if ( st_ivas->hBinRendererTd == NULL ) { IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, num_src ) ), IVAS_ERR_OK ) ) { return error; } + IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) { IF( NE_32( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) ) @@ -713,10 +760,17 @@ ivas_error ivas_omasa_dec_config_fx( } /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + IF( NE_32( ( error = ivas_omasa_objects_delay_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; } +#endif } ELSE { @@ -725,6 +779,7 @@ ivas_error ivas_omasa_dec_config_fx( /* TD renderer handle */ ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd ); } + /* ISM renderer handle + ISM data handle */ ivas_omasa_separate_object_renderer_close( st_ivas ); } @@ -742,6 +797,13 @@ ivas_error ivas_omasa_dec_config_fx( IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) { /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + IF( NE_32( ( error = ivas_omasa_objects_delay_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + { + return error; + } +#endif + IF( NE_32( ( error = ivas_omasa_separate_object_renderer_open( st_ivas ) ), IVAS_ERR_OK ) ) { return error; @@ -753,6 +815,7 @@ ivas_error ivas_omasa_dec_config_fx( ivas_omasa_separate_object_renderer_close( st_ivas ); } } + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT IF( EQ_32( st_ivas->renderer_type, RENDERER_OMASA_MIX_EXT ) ) { @@ -779,23 +842,27 @@ ivas_error ivas_omasa_dec_config_fx( move32(); /* Allocate 'hIsmRendererData' handle and memory for delay buffer within 'hMasaIsmData' */ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + IF( NE_32( ( error = ivas_omasa_objects_delay_open_fx( st_ivas ) ), IVAS_ERR_OK ) ) + { + return error; + } +#else error = ivas_omasa_render_objects_from_mix_open_fx( st_ivas ); move32(); IF( NE_32( error, IVAS_ERR_OK ) ) { return error; } +#endif - error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, - common_rend_config_flag, 0, - st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs, 0, 0 ); - move32(); - IF( NE_32( error, IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_spat_hSpatParamRendCom_config_fx( &st_ivas->hSpatParamRendCom, common_rend_config_flag, 0, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->hDecoderConfig->output_Fs, 0, 0 ) ), IVAS_ERR_OK ) ) { return error; } } #endif + /*-----------------------------------------------------------------* * TD Decorrelator *-----------------------------------------------------------------*/ @@ -949,6 +1016,7 @@ void ivas_set_surplus_brate_dec( * * decode ISM metadata in OMASA format *--------------------------------------------------------------------------*/ + ivas_error ivas_omasa_ism_metadata_dec_fx( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ const Word32 ism_total_brate, /* i : ISM total bitrate */ @@ -967,6 +1035,7 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( move16(); *nchan_transport_ism = st_ivas->nchan_ism; move16(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) { *nchan_ism = 1; @@ -981,6 +1050,7 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( *nchan_transport_ism = 1; move16(); } + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT test(); #endif @@ -1050,8 +1120,7 @@ ivas_error ivas_omasa_ism_metadata_dec_fx( } } #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT - ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) && - EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) + ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) && EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) { azimuth_ism = extract_l( L_shr_r( L_abs( st_ivas->hIsmMetaData[0]->azimuth_fx ), 22 ) ); if ( st_ivas->hIsmMetaData[0]->azimuth_fx < 0 ) @@ -1106,7 +1175,7 @@ void ivas_omasa_dirac_rend_jbm_fx( Word32 data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; test(); - if ( !st_ivas->hDecoderConfig->Opt_tsm ) + IF( !st_ivas->hDecoderConfig->Opt_tsm ) { *nSamplesRendered = min( nSamplesAsked, st_ivas->hTcBuffer->n_samples_available ); @@ -1125,7 +1194,6 @@ void ivas_omasa_dirac_rend_jbm_fx( } } - subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; move16(); slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; @@ -1148,6 +1216,7 @@ void ivas_omasa_dirac_rend_jbm_fx( return; } + /*--------------------------------------------------------------------------* * ivas_omasa_dirac_td_binaural_render() * @@ -1288,7 +1357,8 @@ void ivas_omasa_rearrange_channels_fx( * Open structures, reserve memory, and init values. *-------------------------------------------------------------------------*/ -ivas_error ivas_omasa_combine_separate_ism_with_masa_open_fx( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +ivas_error ivas_omasa_combine_separate_ism_with_masa_open_fx( + Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { Word16 i; @@ -1331,8 +1401,7 @@ ivas_error ivas_omasa_combine_separate_ism_with_masa_open_fx( Decoder_Struct *st move16(); move32(); - st_ivas->hIsmRendererData->interpolator_fx = - (Word16 *) malloc( sizeof( Word16 ) * st_ivas->hIsmRendererData->interpolator_len ); + st_ivas->hIsmRendererData->interpolator_fx = (Word16 *) malloc( sizeof( Word16 ) * st_ivas->hIsmRendererData->interpolator_len ); IF( st_ivas->hIsmRendererData->interpolator_fx == NULL ) { @@ -1353,6 +1422,7 @@ ivas_error ivas_omasa_combine_separate_ism_with_masa_open_fx( Decoder_Struct *st return IVAS_ERR_OK; } + /*--------------------------------------------------------------------------* * ivas_omasa_combine_separate_ism_with_masa_fx() * @@ -1360,11 +1430,11 @@ ivas_error ivas_omasa_combine_separate_ism_with_masa_open_fx( Decoder_Struct *st *--------------------------------------------------------------------------*/ void ivas_omasa_combine_separate_ism_with_masa_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output[], /* i/o: output synthesis signal */ - Word16 *output_q, /* i/o: output Q value */ - const int16_t nchan_ism, /* i : number of ISMs */ - const int16_t output_frame /* i : output frame length per channel */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Word32 *output[], /* i/o: output synthesis signal */ + Word16 *output_q, /* i/o: output Q value */ + const Word16 nchan_ism, /* i : number of ISMs */ + const Word16 output_frame /* i : output frame length per channel */ ) { Word16 n, sf, band, k; @@ -1608,9 +1678,20 @@ void ivas_omasa_combine_separate_ism_with_masa_fx( { set_zero_fx( output[add( MASA_MAX_TRANSPORT_CHANNELS, n )], output_frame ); } + + return; } +#ifdef FIX_1161_REDUCE_OMASA_HEAP +/*-------------------------------------------------------------------------* + * ivas_omasa_objects_delay_open() + * + * Open structures, reserve memory, and init values for dela buffers of objects. + *-------------------------------------------------------------------------*/ + +ivas_error ivas_omasa_objects_delay_open_fx( +#else /*-------------------------------------------------------------------------* * ivas_omasa_render_objects_from_mix_open_fx() * @@ -1618,14 +1699,29 @@ void ivas_omasa_combine_separate_ism_with_masa_fx( *-------------------------------------------------------------------------*/ ivas_error ivas_omasa_render_objects_from_mix_open_fx( +#endif Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ) { Word16 i; Word32 size; +#ifdef FIX_1161_REDUCE_OMASA_HEAP + test(); + IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) ) + { + st_ivas->hMasaIsmData->delayBuffer_nchan = 1; + move16(); + } + ELSE + { + st_ivas->hMasaIsmData->delayBuffer_nchan = st_ivas->nchan_ism; + move16(); + } +#else st_ivas->hMasaIsmData->delayBuffer_nchan = 1; move16(); +#endif st_ivas->hMasaIsmData->delayBuffer_size = extract_l( Mult_32_16( st_ivas->hDecoderConfig->output_Fs, OMASA_DELAYFRAMES_PER_SEC_Q15 ) ); @@ -1664,11 +1760,11 @@ ivas_error ivas_omasa_render_objects_from_mix_open_fx( *--------------------------------------------------------------------------*/ void ivas_omasa_render_objects_from_mix_fx( - Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ - Word32 *output[], /* o : output synthesis signal */ - const int16_t nchan_ism, /* i : number of ISMs */ - const int16_t output_frame, /* i : output frame length per channel */ - Word16 *output_q /* i/o: output Q value */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Word32 *output[], /* o : output synthesis signal */ + const Word16 nchan_ism, /* i : number of ISMs */ + const Word16 output_frame, /* i : output frame length per channel */ + Word16 *output_q /* i/o: output Q value */ ) { Word16 n, m, i; @@ -2120,5 +2216,7 @@ void ivas_omasa_render_objects_from_mix_fx( hExtData->prev_idx_separated_ism = st_ivas->hMasaIsmData->idx_separated_ism; move16(); + + return; } #endif diff --git a/lib_dec/ivas_sba_dec_fx.c b/lib_dec/ivas_sba_dec_fx.c index 1189abd24..7478fd237 100644 --- a/lib_dec/ivas_sba_dec_fx.c +++ b/lib_dec/ivas_sba_dec_fx.c @@ -815,11 +815,13 @@ void ivas_sba_dec_digest_tc_fx( { ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots ); } + test(); IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) { ivas_spar_dec_digest_tc_fx( st_ivas, st_ivas->nchan_transport, nCldfbSlots, nSamplesForRendering ); } + test(); IF( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index f135d651a..e8bdb908e 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -980,9 +980,11 @@ typedef struct ivas_masa_ism_data_structure Word32 **delayBuffer_fx; /* Q11 */ Word16 delayBuffer_size; Word16 delayBuffer_nchan; + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT MASA_ISM_EXT_DATA_HANDLE hExtData; #endif + } MASA_ISM_DATA, *MASA_ISM_DATA_HANDLE; diff --git a/lib_dec/lib_dec_fx.c b/lib_dec/lib_dec_fx.c index c75cba971..651a8fc8b 100644 --- a/lib_dec/lib_dec_fx.c +++ b/lib_dec/lib_dec_fx.c @@ -1993,11 +1993,13 @@ ivas_error IVAS_DEC_GetNumObjects( is_masa_ism = 0; move16(); #endif + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { return IVAS_ERR_UNEXPECTED_NULL_POINTER; } + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT IF( hIvasDec->st_ivas->hMasa != NULL ) { @@ -2007,6 +2009,7 @@ ivas_error IVAS_DEC_GetNumObjects( move16(); } } + test(); test(); test(); @@ -2053,6 +2056,7 @@ ivas_error IVAS_DEC_GetFormat( *format = IVAS_DEC_BS_UNKOWN; } move32(); + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT test(); if ( EQ_32( *format, IVAS_DEC_BS_MASA ) && EQ_32( hIvasDec->st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) ) @@ -2061,6 +2065,7 @@ ivas_error IVAS_DEC_GetFormat( move32(); } #endif + return IVAS_ERR_OK; } @@ -2173,9 +2178,11 @@ ivas_error IVAS_DEC_GetObjectMetadata( ISM_METADATA_HANDLE hIsmMeta; #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT Word16 is_masa_ism; + is_masa_ism = 0; move16(); #endif + test(); IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL ) { @@ -2183,6 +2190,7 @@ ivas_error IVAS_DEC_GetObjectMetadata( } st_ivas = hIvasDec->st_ivas; + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT IF( hIvasDec->st_ivas->hMasa != NULL ) { @@ -2192,6 +2200,7 @@ ivas_error IVAS_DEC_GetObjectMetadata( move16(); } } + test(); test(); test(); @@ -2214,6 +2223,7 @@ ivas_error IVAS_DEC_GetObjectMetadata( } hIsmMeta = st_ivas->hIsmMetaData[objectIdx]; + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT test(); test(); @@ -2928,6 +2938,7 @@ ivas_error IVAS_DEC_GetDelay( out_fs_fx = FS_48K_IN_NS_Q31; } move32(); + #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT nSamples[1] = NS2SA_FX2( hDecoderConfig->output_Fs, get_delay_fx( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbSynDec[0], (Word16) EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) ); move16(); diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index cfd2aaef4..5c61deb71 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -223,11 +223,31 @@ ivas_error ivas_masa_enc_open_fx( hOmasaData->omasa_stereo_sw_cnt = OMASA_STEREO_SW_CNT_MAX; move16(); +#ifdef FIX_1161_REDUCE_OMASA_HEAP + IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) + { + IF( ( hOmasaData->hOmasaEnergy = (OMASA_ENCODER_ENERGY_HANDLE) malloc( sizeof( OMASA_ENCODER_ENERGY_STATE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA energy handle\n" ) ); + } + + FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + set_zero_fx( hOmasaData->hOmasaEnergy->energy_ism_fx[i], MASA_FREQUENCY_BANDS ); // hOmasaData->energy_ism_fx_e + set16_fx( hOmasaData->hOmasaEnergy->energy_ism_fx_e[i], 0, MASA_FREQUENCY_BANDS ); + } + } + else + { + hOmasaData->hOmasaEnergy = NULL; + } +#else FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { set_zero_fx( hOmasaData->energy_ism_fx[i], MASA_FREQUENCY_BANDS ); // hOmasaData->energy_ism_fx_e set16_fx( hOmasaData->energy_ism_fx_e[i], 0, MASA_FREQUENCY_BANDS ); } +#endif hMasa->data.hOmasaData = hOmasaData; } @@ -265,6 +285,14 @@ void ivas_masa_enc_close_fx( IF( ( *hMasa )->data.hOmasaData != NULL ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + IF( ( *hMasa )->data.hOmasaData->hOmasaEnergy != NULL ) + { + free( ( *hMasa )->data.hOmasaData->hOmasaEnergy ); + ( *hMasa )->data.hOmasaData->hOmasaEnergy = NULL; + } + +#endif free( ( *hMasa )->data.hOmasaData ); ( *hMasa )->data.hOmasaData = NULL; } @@ -1146,7 +1174,7 @@ ivas_error ivas_masa_enc_config_fx( } ELSE { - hQMetaData->q_direction[i].cfg.nblocks = 4; + hQMetaData->q_direction[i].cfg.nblocks = MAX_PARAM_SPATIAL_SUBFRAMES; } move16(); @@ -2022,7 +2050,7 @@ static void move_metadata_to_qmetadata_fx( move16(); move16(); move16(); - numSf = 4; + numSf = MAX_PARAM_SPATIAL_SUBFRAMES; if ( EQ_16( hMasa->config.joinedSubframes, TRUE ) ) { numSf = 1; @@ -3809,11 +3837,13 @@ static void masa_metadata_direction_alignment_fx( return; } + /*-------------------------------------------------------------------* * ivas_merge_masa_metadata() * * *-------------------------------------------------------------------*/ + void ivas_merge_masa_metadata_fx( MASA_ENCODER_HANDLE hMasa, /* i/o: MASA enc handle. source for MASA metadata and combined metadata will be here */ OMASA_SPATIAL_META_HANDLE hOMasaMeta /* i : ISM-object metadata to be merged with the MASA metadata */ @@ -3834,6 +3864,9 @@ void ivas_merge_masa_metadata_fx( Word32 eneBand_fx; /*eneBand_e*/ Word16 eneBand_e; Word32 energyMerged_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /*energyMerged_e*/ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + OMASA_ENCODER_ENERGY_HANDLE hOmasaEnergy = hMasa->data.hOmasaData->hOmasaEnergy; +#endif Word32 temp1 /*temp1_e*/, temp2 /*temp2_e*/; Word16 temp1_e, temp2_e; @@ -3845,7 +3878,7 @@ void ivas_merge_masa_metadata_fx( } ELSE { - numSf = 4; + numSf = MAX_PARAM_SPATIAL_SUBFRAMES; } move16(); move16(); @@ -3877,7 +3910,11 @@ void ivas_merge_masa_metadata_fx( eneBand_e = hMasa->data.energy_e[sf][band]; move32(); move16(); +#ifdef FIX_1161_REDUCE_OMASA_HEAP + energyMerged_fx[sf][band] = BASOP_Util_Add_Mant32Exp( eneBand_fx, eneBand_e, hOmasaEnergy->energy_ism_fx[sf][band], hOmasaEnergy->energy_ism_fx_e[sf][band], &energyMerged_e[sf][band] ); +#else energyMerged_fx[sf][band] = BASOP_Util_Add_Mant32Exp( eneBand_fx, eneBand_e, hMasa->data.hOmasaData->energy_ism_fx[sf][band], hMasa->data.hOmasaData->energy_ism_fx_e[sf][band], &energyMerged_e[sf][band] ); +#endif move32(); /* Compute weights */ @@ -3903,8 +3940,12 @@ void ivas_merge_masa_metadata_fx( total_diff_nrg_e = add( eneBand_e, 1 ); /* criterion is mean of ISM ratio and new ratio */ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + temp1 = BASOP_Util_Add_Mant32Exp( L_add( EPSILON_FX, eneBand_fx ), eneBand_e, hOmasaEnergy->energy_ism_fx[sf][band], hOmasaEnergy->energy_ism_fx_e[sf][band], &temp1_e ); /* EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band]*/ +#else temp1 = BASOP_Util_Add_Mant32Exp( L_add( EPSILON_FX, eneBand_fx ), eneBand_e, hMasa->data.hOmasaData->energy_ism_fx[sf][band], hMasa->data.hOmasaData->energy_ism_fx_e[sf][band], &temp1_e ); /* EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band]*/ - temp2 = L_deposit_h( BASOP_Util_Divide3232_Scale( total_diff_nrg_fx, temp1, &temp2_e ) ); /*temp2_e*/ /*total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] )*/ +#endif + temp2 = L_deposit_h( BASOP_Util_Divide3232_Scale( total_diff_nrg_fx, temp1, &temp2_e ) ); /*temp2_e*/ /*total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] )*/ temp2_e = add( temp2_e, sub( total_diff_nrg_e, temp1_e ) ); IF( temp2_e < 0 ) { @@ -3912,11 +3953,16 @@ void ivas_merge_masa_metadata_fx( temp2_e = 0; move16(); } - temp2 = L_sub( L_shl_sat( 1, sub( 31, temp2_e ) ), temp2 ); /*( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) )*/ - temp2 = BASOP_Util_Add_Mant32Exp( hOMasaMeta->directional_meta[0].energy_ratio_fx[sf][band], 1, temp2, temp2_e, &temp2_e ); /*( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) )*/ - energyTimesRatioISM_fx = Mpy_32_32( L_shr( temp2, 1 ), hMasa->data.hOmasaData->energy_ism_fx[sf][band] ); /*energyTimesRatioISM_e*/ + temp2 = L_sub( L_shl_sat( 1, sub( 31, temp2_e ) ), temp2 ); /*( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hOmasaEnergy->energy_ism[sf][band] ) )*/ + temp2 = BASOP_Util_Add_Mant32Exp( hOMasaMeta->directional_meta[0].energy_ratio_fx[sf][band], 1, temp2, temp2_e, &temp2_e ); /*( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hOmasaEnergy->energy_ism[sf][band] ) )*/ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + energyTimesRatioISM_fx = Mpy_32_32( L_shr( temp2, 1 ), hOmasaEnergy->energy_ism_fx[sf][band] ); /*energyTimesRatioISM_e*/ + energyTimesRatioISM_e = add( temp2_e, hOmasaEnergy->energy_ism_fx_e[sf][band] ); +#else + energyTimesRatioISM_fx = Mpy_32_32( L_shr( temp2, 1 ), hMasa->data.hOmasaData->energy_ism_fx[sf][band] ); /*energyTimesRatioISM_e*/ energyTimesRatioISM_e = add( temp2_e, hMasa->data.hOmasaData->energy_ism_fx_e[sf][band] ); - /*energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] ) ) ) / 2.0f * hMasa->data.hOmasaData->energy_ism[sf][band];*/ +#endif + /*energyTimesRatioISM = ( hOMasaMeta->directional_meta[0].energy_ratio[sf][band] + ( 1.0f - total_diff_nrg / ( EPSILON + eneBand + hOmasaEnergy->energy_ism[sf][band] ) ) ) / 2.0f * hOmasaEnergy->energy_ism[sf][band];*/ /* Determine combined metadata based on the weights */ merge_dest = -1; @@ -3951,7 +3997,7 @@ void ivas_merge_masa_metadata_fx( dir_sum_e = temp2_e; move32(); move16(); - /*dir_sum = 1.0f - total_diff_nrg / ( EPSILON + eneBand + hMasa->data.hOmasaData->energy_ism[sf][band] )*/ + /*dir_sum = 1.0f - total_diff_nrg / ( EPSILON + eneBand + hOmasaEnergy->energy_ism[sf][band] )*/ IF( EQ_16( BASOP_Util_Cmp_Mant32Exp( dir_sum_fx, dir_sum_e, hOMasaMeta->directional_meta[0].energy_ratio_fx[sf][band], 1 ), -1 ) ) { hMeta->directional_meta[merge_dest].energy_ratio_fx[sf][band] = L_shl( dir_sum_fx, sub( dir_sum_e, 1 ) ); /*scaling to Q30*/ @@ -4726,6 +4772,8 @@ static Word16 encode_ratio_ism_subframe_fx( return nbits; } + + static void ivas_encode_masaism_metadata_fx( MASA_ENCODER_HANDLE hMasa, IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -4757,6 +4805,9 @@ static void ivas_encode_masaism_metadata_fx( Word16 tmp, rotate, energy_ism_e, energy_ism_ind_e[MAX_NUM_OBJECTS]; Word16 n_ism_tmp, i; OMASA_ENCODER_DATA_HANDLE hOmasaData = hMasa->data.hOmasaData; +#ifdef FIX_1161_REDUCE_OMASA_HEAP + OMASA_ENCODER_ENERGY_HANDLE hOmasaEnergy = hOmasaData->hOmasaEnergy; +#endif Word16 nbands_work; Word32 L_tmp; Word16 L_tmp_e; @@ -4777,9 +4828,14 @@ static void ivas_encode_masaism_metadata_fx( move16(); FOR( i = 0; i < omasa_nbands; i++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, hOmasaEnergy->energy_ism_fx[sf][i], hOmasaEnergy->energy_ism_fx_e[sf][i], &L_tmp_e ); +#else L_tmp = BASOP_Util_Add_Mant32Exp( L_tmp, L_tmp_e, hOmasaData->energy_ism_fx[sf][i], hOmasaData->energy_ism_fx_e[sf][i], &L_tmp_e ); +#endif } - /* if ( sum_f( hOmasaData->energy_ism[sf], omasa_nbands ) == 0.0f ) */ + + /* if ( sum_f( hOmasaEnergy->energy_ism[sf], omasa_nbands ) == 0.0f ) */ IF( L_tmp == 0 ) { hOmasaData->masa_to_total_energy_ratio_fx[sf][0] = ONE_IN_Q30; // 1.0f in Q30 @@ -4815,7 +4871,12 @@ static void ivas_encode_masaism_metadata_fx( FOR( band = 0; band < omasa_nbands; band++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + energy_ism = BASOP_Util_Add_Mant32Exp( energy_ism, energy_ism_e, hOmasaEnergy->energy_ism_fx[sf][band], hOmasaEnergy->energy_ism_fx_e[sf][band], &energy_ism_e ); +#else energy_ism = BASOP_Util_Add_Mant32Exp( energy_ism, energy_ism_e, hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ism_fx_e[sf][band], &energy_ism_e ); +#endif + FOR( obj = 0; obj < nchan_ism; obj++ ) { @@ -4826,11 +4887,19 @@ static void ivas_encode_masaism_metadata_fx( FOR( obj = 0; obj < nchan_ism; obj++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + hOmasaEnergy->energy_ratio_ism_fx[sf][0][obj] = BASOP_Util_Divide3232_Scale_newton( energy_ism_ind[obj], energy_ism, &L_tmp_e ); +#else hOmasaData->energy_ratio_ism_fx[sf][0][obj] = BASOP_Util_Divide3232_Scale_newton( energy_ism_ind[obj], energy_ism, &L_tmp_e ); +#endif move32(); L_tmp_e = add( L_tmp_e, sub( energy_ism_ind_e[obj], energy_ism_e ) ); /* Scaling to Q30 */ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + hOmasaEnergy->energy_ratio_ism_fx[sf][0][obj] = L_shl( hOmasaEnergy->energy_ratio_ism_fx[sf][0][obj], sub( L_tmp_e, 1 ) ); // Q30 +#else hOmasaData->energy_ratio_ism_fx[sf][0][obj] = L_shl( hOmasaData->energy_ratio_ism_fx[sf][0][obj], sub( L_tmp_e, 1 ) ); // Q30 +#endif move32(); } L_tmp = BASOP_Util_Add_Mant32Exp( eneBand32, eneBand_exp, energy_ism, energy_ism_e, &L_tmp_e ); @@ -4868,11 +4937,21 @@ static void ivas_encode_masaism_metadata_fx( } FOR( sf = 0; sf < omasa_nblocks; sf++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + energy_ism = BASOP_Util_Add_Mant32Exp( energy_ism, energy_ism_e, hOmasaEnergy->energy_ism_fx[sf][band], hOmasaEnergy->energy_ism_fx_e[sf][band], &energy_ism_e ); +#else energy_ism = BASOP_Util_Add_Mant32Exp( energy_ism, energy_ism_e, hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ism_fx_e[sf][band], &energy_ism_e ); +#endif + FOR( obj = 0; obj < nchan_ism; obj++ ) { - L_tmp = Mpy_32_32( hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q = (31 - hOmasaData->energy_ism_fx_e[sf][band]) + Q30 - 31 +#ifdef FIX_1161_REDUCE_OMASA_HEAP + L_tmp = Mpy_32_32( hOmasaEnergy->energy_ism_fx[sf][band], hOmasaEnergy->energy_ratio_ism_fx[sf][band][obj] ); // Q = (31 - hOmasaEnergy->energy_ism_fx_e[sf][band]) + Q30 - 31 + L_tmp_e = add( 1, hOmasaEnergy->energy_ism_fx_e[sf][band] ); +#else + L_tmp = Mpy_32_32( hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q = (31 - hOmasaEnergy->energy_ism_fx_e[sf][band]) + Q30 - 31 L_tmp_e = add( 1, hOmasaData->energy_ism_fx_e[sf][band] ); +#endif energy_ism_ind[obj] = BASOP_Util_Add_Mant32Exp( energy_ism_ind[obj], energy_ism_ind_e[obj], L_tmp, L_tmp_e, &energy_ism_ind_e[obj] ); move32(); } @@ -4887,11 +4966,19 @@ static void ivas_encode_masaism_metadata_fx( { FOR( obj = 0; obj < nchan_ism; obj++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + hOmasaEnergy->energy_ratio_ism_fx[0][band][obj] = BASOP_Util_Divide3232_Scale_newton( energy_ism_ind[obj], energy_ism, &L_tmp_e ); +#else hOmasaData->energy_ratio_ism_fx[0][band][obj] = BASOP_Util_Divide3232_Scale_newton( energy_ism_ind[obj], energy_ism, &L_tmp_e ); +#endif move32(); L_tmp_e = add( L_tmp_e, sub( energy_ism_ind_e[obj], energy_ism_e ) ); /* Scaling to Q30 */ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + hOmasaEnergy->energy_ratio_ism_fx[0][band][obj] = L_shl( hOmasaEnergy->energy_ratio_ism_fx[0][band][obj], sub( L_tmp_e, 1 ) ); // Q30 +#else hOmasaData->energy_ratio_ism_fx[0][band][obj] = L_shl( hOmasaData->energy_ratio_ism_fx[0][band][obj], sub( L_tmp_e, 1 ) ); // Q30 +#endif move32(); } brange[0] = hMasa->data.band_mapping[band]; @@ -4936,7 +5023,11 @@ static void ivas_encode_masaism_metadata_fx( FOR( obj = 0; obj < nchan_ism; obj++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + hOmasaEnergy->energy_ratio_ism_fx[0][band][obj] = hOmasaEnergy->energy_ratio_ism_fx[0][nbands_work - 1][obj]; +#else hOmasaData->energy_ratio_ism_fx[0][band][obj] = hOmasaData->energy_ratio_ism_fx[0][nbands_work - 1][obj]; +#endif move32(); } } @@ -4947,7 +5038,11 @@ static void ivas_encode_masaism_metadata_fx( { FOR( band = 0; band < nbands_work; band++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + IF( hOmasaEnergy->energy_ism_fx[sf][band] == 0 ) +#else IF( hOmasaData->energy_ism_fx[sf][band] == 0 ) +#endif { hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = ONE_IN_Q30; move32(); @@ -4969,7 +5064,11 @@ static void ivas_encode_masaism_metadata_fx( eneBand32 = W_extract_h( W_shl( eneBand, shift ) ); eneBand_exp = sub( 63, add( add( hMasa->data.q_energy, 1 ), shift ) ); +#ifdef FIX_1161_REDUCE_OMASA_HEAP + L_tmp = BASOP_Util_Add_Mant32Exp( eneBand32, eneBand_exp, hOmasaEnergy->energy_ism_fx[sf][band], hOmasaEnergy->energy_ism_fx_e[sf][band], &L_tmp_e ); +#else L_tmp = BASOP_Util_Add_Mant32Exp( eneBand32, eneBand_exp, hOmasaData->energy_ism_fx[sf][band], hOmasaData->energy_ism_fx_e[sf][band], &L_tmp_e ); +#endif IF( L_tmp != 0 ) { hOmasaData->masa_to_total_energy_ratio_fx[sf][band] = BASOP_Util_Divide3232_Scale_newton( eneBand32, L_tmp, &tmp ); @@ -4993,7 +5092,11 @@ static void ivas_encode_masaism_metadata_fx( FOR( obj = 0; obj < nchan_ism; obj++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + hOmasaEnergy->energy_ratio_ism_fx[sf][band][obj] = hOmasaEnergy->energy_ratio_ism_fx[sf][nbands_work - 1][obj]; +#else hOmasaData->energy_ratio_ism_fx[sf][band][obj] = hOmasaData->energy_ratio_ism_fx[sf][nbands_work - 1][obj]; +#endif move32(); } } @@ -5016,8 +5119,13 @@ static void ivas_encode_masaism_metadata_fx( { FOR( obj = 0; obj < nchan_ism; obj++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + assert( ( hOmasaEnergy->energy_ratio_ism_fx[sf][band][obj] >= 0 ) && ( hOmasaEnergy->energy_ratio_ism_fx[sf][band][obj] <= ONE_IN_Q30 ) ); + ratio_ism_fx[band][obj] = extract_h( hOmasaEnergy->energy_ratio_ism_fx[sf][band][obj] ); // Q14 +#else assert( ( hOmasaData->energy_ratio_ism_fx[sf][band][obj] >= 0 ) && ( hOmasaData->energy_ratio_ism_fx[sf][band][obj] <= ONE_IN_Q30 ) ); ratio_ism_fx[band][obj] = extract_h( hOmasaData->energy_ratio_ism_fx[sf][band][obj] ); // Q14 +#endif move16(); } @@ -5049,8 +5157,13 @@ static void ivas_encode_masaism_metadata_fx( } /* reconstructed values */ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + reconstruct_ism_ratios_fx( ratio_ism_idx[band], nchan_ism, STEP_PARAM_ISM_POW_RATIO_NBITS_Q31, hOmasaEnergy->q_energy_ratio_ism_fx[sf][band] ); +#else reconstruct_ism_ratios_fx( ratio_ism_idx[band], nchan_ism, STEP_PARAM_ISM_POW_RATIO_NBITS_Q31, hMasa->data.hOmasaData->q_energy_ratio_ism_fx[sf][band] ); +#endif } + test(); IF( GT_16( nchan_ism, 2 ) && EQ_16( idx_separated_object, sub( nchan_ism, 1 ) ) ) { @@ -5134,7 +5247,11 @@ static void ivas_encode_masaism_metadata_fx( } } +#ifdef FIX_1161_REDUCE_OMASA_HEAP + calculate_nbits_meta_fx( nchan_ism, hOmasaEnergy->q_energy_ratio_ism_fx, hOmasaData->masa_to_total_energy_ratio_fx, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); +#else calculate_nbits_meta_fx( nchan_ism, hOmasaData->q_energy_ratio_ism_fx, hOmasaData->masa_to_total_energy_ratio_fx, numSf, numCodingBands, bits_ism, idx_separated_object, ism_imp ); +#endif /* quantize directions */ FOR( obj = 0; obj < nchan_ism; obj++ ) diff --git a/lib_enc/ivas_omasa_enc_fx.c b/lib_enc/ivas_omasa_enc_fx.c index 4e7bc8328..a6e3446a1 100644 --- a/lib_enc/ivas_omasa_enc_fx.c +++ b/lib_enc/ivas_omasa_enc_fx.c @@ -99,6 +99,8 @@ void computeIntensityVector_enc_fx( Word16 inp_q ); static void computeReferencePower_omasa_ivas_fx( const Word16 *band_grouping, Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], Word32 Cldfb_ImagBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], Word32 *reference_power, const Word16 enc_param_start_band, const Word16 num_freq_bands, Word16 q_Cldfb, Word16 q_reference_power[CLDFB_NO_CHANNELS_MAX] ); + + /*--------------------------------------------------------------------------* * ivas_omasa_enc_open() * @@ -268,11 +270,13 @@ void ivas_omasa_enc_close_fx( return; } + /*--------------------------------------------------------------------------* * ivas_omasa_enc_config() * * oMASA encoder configuration *--------------------------------------------------------------------------*/ + ivas_error ivas_omasa_enc_config_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -483,6 +487,7 @@ void ivas_omasa_set_config_fx( * * Main OMASA encoding function *--------------------------------------------------------------------------*/ + void ivas_omasa_enc_fx( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ @@ -514,6 +519,7 @@ void ivas_omasa_enc_fx( UWord8 fade_out_separate_object; UWord8 fade_in_separate_object; Word32 temp32; /*temp32_e*/ + /* Estimate broadband energies */ nchan_all_inp = add( nchan_ism, nchan_transport ); set_zero_fx( broadband_energy_fx, nchan_all_inp ); @@ -878,6 +884,7 @@ void ivas_set_ism_importance_interformat_fx( return; } + /*--------------------------------------------------------------------------* * ivas_set_surplus_brate_enc() * @@ -951,7 +958,7 @@ Word16 ivas_omasa_ener_brate_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ Word32 *data_f[], /* i : Input / transport audio signals data_e*/ const Word16 input_frame, /* i : Input frame size */ - Word16 data_e /*i:exponent for data_f */ + const Word16 data_e /* i : exponent for data_f */ ) { Word16 i, flag_omasa_ener_brate; @@ -1017,6 +1024,7 @@ Word16 ivas_omasa_ener_brate_fx( return flag_omasa_ener_brate; } + /*--------------------------------------------------------------------------* * Local functions *--------------------------------------------------------------------------*/ @@ -1067,6 +1075,9 @@ static void ivas_omasa_param_est_enc_fx( Word32 temp; Word16 temp_e; Word16 q_intensity_real_fx[MASA_FREQUENCY_BANDS], q_reference_power_fx[CLDFB_NO_CHANNELS_MAX]; +#ifdef FIX_1161_REDUCE_OMASA_HEAP + OMASA_ENCODER_ENERGY_HANDLE hOmasaEnergy = hOmasaData->hOmasaEnergy; +#endif ref_exp = 0; norm_buff = MAX16B; @@ -1133,8 +1144,14 @@ static void ivas_omasa_param_est_enc_fx( move16(); move16(); } +#ifdef FIX_1161_REDUCE_OMASA_HEAP + set_zero_fx( hOmasaEnergy->energy_ism_fx[block_m_idx], num_freq_bands ); + set16_fx( hOmasaEnergy->energy_ism_fx_e[block_m_idx], 0, num_freq_bands ); +#else set_zero_fx( hOmasaData->energy_ism_fx[block_m_idx], num_freq_bands ); set16_fx( hOmasaData->energy_ism_fx_e[block_m_idx], 0, num_freq_bands ); +#endif + FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) { norm_buff = MAX16B; @@ -1174,7 +1191,11 @@ static void ivas_omasa_param_est_enc_fx( { temp = L_add( Mpy_32_32( Chnl_RealBuffer_fx[k][j], Chnl_RealBuffer_fx[k][j] ), Mpy_32_32( Chnl_ImagBuffer_fx[k][j], Chnl_ImagBuffer_fx[k][j] ) ); temp_e = sub( 62, shl( q, 1 ) ); +#ifdef FIX_1161_REDUCE_OMASA_HEAP + hOmasaEnergy->energy_ism_fx[block_m_idx][i] = BASOP_Util_Add_Mant32Exp( hOmasaEnergy->energy_ism_fx[block_m_idx][i], hOmasaEnergy->energy_ism_fx_e[block_m_idx][i], temp, temp_e, &hOmasaEnergy->energy_ism_fx_e[block_m_idx][i] ); /*2q-31*/ +#else hOmasaData->energy_ism_fx[block_m_idx][i] = BASOP_Util_Add_Mant32Exp( hOmasaData->energy_ism_fx[block_m_idx][i], hOmasaData->energy_ism_fx_e[block_m_idx][i], temp, temp_e, &hOmasaData->energy_ism_fx_e[block_m_idx][i] ); /*2q-31*/ +#endif move32(); } } @@ -1334,6 +1355,7 @@ static void ivas_omasa_param_est_enc_fx( move32(); move32(); } + return; } @@ -1362,6 +1384,10 @@ static void ivas_omasa_energy_and_ratio_est_fx( Word16 norm_Chnl; Word16 temp_e; /* to store temporary exp*/ Word16 energy_ratio_ism_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; /*q30*/ +#ifdef FIX_1161_REDUCE_OMASA_HEAP + OMASA_ENCODER_ENERGY_HANDLE hOmasaEnergy = hOmasaData->hOmasaEnergy; +#endif + num_freq_bands = hOMasa->nbands; l_ts = shr( input_frame, 4 ); /*input_frame / CLDFB_NO_COL_MAX*/ q_cldfb = q_data; @@ -1369,6 +1395,7 @@ static void ivas_omasa_energy_and_ratio_est_fx( move16(); /*q_cldfb*/ set_zero_fx( &Chnl_RealBuffer_fx[0][0], MAX_NUM_OBJECTS * CLDFB_NO_CHANNELS_MAX ); set_zero_fx( &Chnl_ImagBuffer_fx[0][0], MAX_NUM_OBJECTS * CLDFB_NO_CHANNELS_MAX ); + /* do processing over all CLDFB time slots */ FOR( block_m_idx = 0; block_m_idx < hOMasa->nSubframes; block_m_idx++ ) { @@ -1380,11 +1407,21 @@ static void ivas_omasa_energy_and_ratio_est_fx( /* Reset variable */ FOR( i = 0; i < hOMasa->nbands; i++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + set_zero_fx( hOmasaEnergy->energy_ratio_ism_fx[block_m_idx][i], nchan_ism ); +#else set_zero_fx( hOmasaData->energy_ratio_ism_fx[block_m_idx][i], nchan_ism ); +#endif set16_fx( energy_ratio_ism_e[block_m_idx][i], 0, nchan_ism ); } +#ifdef FIX_1161_REDUCE_OMASA_HEAP + set_zero_fx( hOmasaEnergy->energy_ism_fx[block_m_idx], num_freq_bands ); + set16_fx( hOmasaEnergy->energy_ism_fx_e[block_m_idx], 0, num_freq_bands ); +#else set_zero_fx( hOmasaData->energy_ism_fx[block_m_idx], num_freq_bands ); set16_fx( hOmasaData->energy_ism_fx_e[block_m_idx], 0, num_freq_bands ); +#endif + /* Compute CLDFB */ FOR( ts = mrange[0]; ts < mrange[1]; ts++ ) { @@ -1409,6 +1446,7 @@ static void ivas_omasa_energy_and_ratio_est_fx( scale_sig32( Chnl_ImagBuffer_fx[i], CLDFB_NO_CHANNELS_MAX, norm_Chnl ); } q_cldfb = add( q_cldfb, norm_Chnl ); + /* Compute energy */ FOR( i = 0; i < num_freq_bands; i++ ) { @@ -1428,8 +1466,13 @@ static void ivas_omasa_energy_and_ratio_est_fx( tmp64 = W_shl( tmp64, tmpNorm ); tftile_energy_fx = W_extract_h( tmp64 ); tftile_energy_e = sub( tftile_energy_e, tmpNorm ); +#ifdef FIX_1161_REDUCE_OMASA_HEAP + hOmasaEnergy->energy_ism_fx[block_m_idx][i] = BASOP_Util_Add_Mant32Exp( hOmasaEnergy->energy_ism_fx[block_m_idx][i], hOmasaEnergy->energy_ism_fx_e[block_m_idx][i], tftile_energy_fx, tftile_energy_e, &hOmasaEnergy->energy_ism_fx_e[block_m_idx][i] ); + hOmasaEnergy->energy_ratio_ism_fx[block_m_idx][i][k] = BASOP_Util_Add_Mant32Exp( hOmasaEnergy->energy_ratio_ism_fx[block_m_idx][i][k], energy_ratio_ism_e[block_m_idx][i][k], tftile_energy_fx, tftile_energy_e, &energy_ratio_ism_e[block_m_idx][i][k] ); +#else hOmasaData->energy_ism_fx[block_m_idx][i] = BASOP_Util_Add_Mant32Exp( hOmasaData->energy_ism_fx[block_m_idx][i], hOmasaData->energy_ism_fx_e[block_m_idx][i], tftile_energy_fx, tftile_energy_e, &hOmasaData->energy_ism_fx_e[block_m_idx][i] ); hOmasaData->energy_ratio_ism_fx[block_m_idx][i][k] = BASOP_Util_Add_Mant32Exp( hOmasaData->energy_ratio_ism_fx[block_m_idx][i][k], energy_ratio_ism_e[block_m_idx][i][k], tftile_energy_fx, tftile_energy_e, &energy_ratio_ism_e[block_m_idx][i][k] ); +#endif move32(); move32(); } @@ -1444,6 +1487,15 @@ static void ivas_omasa_energy_and_ratio_est_fx( move64(); FOR( j = 0; j < nchan_ism; j++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + hOmasaEnergy->energy_ratio_ism_fx[block_m_idx][i][j] = L_deposit_h( BASOP_Util_Divide3232_Scale( hOmasaEnergy->energy_ratio_ism_fx[block_m_idx][i][j], L_add( hOmasaEnergy->energy_ism_fx[block_m_idx][i], EPSILON_FX ), &temp_e ) ); + move32(); + temp_e = add( temp_e, sub( energy_ratio_ism_e[block_m_idx][i][j], hOmasaEnergy->energy_ism_fx_e[block_m_idx][i] ) ); + + hOmasaEnergy->energy_ratio_ism_fx[block_m_idx][i][j] = L_shl( hOmasaEnergy->energy_ratio_ism_fx[block_m_idx][i][j], sub( temp_e, 1 ) ); /* scaling to q30 */ + move32(); + ism_ratio_sum_fx = W_add( ism_ratio_sum_fx, hOmasaEnergy->energy_ratio_ism_fx[block_m_idx][i][j] ); +#else hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j] = L_deposit_h( BASOP_Util_Divide3232_Scale( hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j], L_add( hOmasaData->energy_ism_fx[block_m_idx][i], EPSILON_FX ), &temp_e ) ); move32(); temp_e = add( temp_e, sub( energy_ratio_ism_e[block_m_idx][i][j], hOmasaData->energy_ism_fx_e[block_m_idx][i] ) ); @@ -1451,13 +1503,18 @@ static void ivas_omasa_energy_and_ratio_est_fx( hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j] = L_shl( hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j], sub( temp_e, 1 ) ); /* scaling to q30 */ move32(); ism_ratio_sum_fx = W_add( ism_ratio_sum_fx, hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j] ); +#endif } IF( ism_ratio_sum_fx == 0 ) { Word16 temp_ism_ratio = BASOP_Util_Divide1616_Scale( 1, nchan_ism, &temp_e ); FOR( j = 0; j < nchan_ism; j++ ) { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + hOmasaEnergy->energy_ratio_ism_fx[block_m_idx][i][j] = L_shl( temp_ism_ratio, add( temp_e, 15 ) ); /*scaling to q30*/ +#else hOmasaData->energy_ratio_ism_fx[block_m_idx][i][j] = L_shl( temp_ism_ratio, add( temp_e, 15 ) ); /*scaling to q30*/ +#endif move32(); } } @@ -1572,6 +1629,7 @@ void computeIntensityVector_enc_fx( } norm = 63; move16(); + IF( intensity_real64[0][i] != 0 ) { norm = s_min( norm, W_norm( intensity_real64[0][i] ) ); @@ -1597,6 +1655,7 @@ void computeIntensityVector_enc_fx( return; } + static void computeReferencePower_omasa_ivas_fx( const Word16 *band_grouping, /* i : Band grouping for estimation */ Word32 Cldfb_RealBuffer[FOA_CHANNELS][CLDFB_NO_CHANNELS_MAX], /* i : Real part of input signal Q6*/ diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index 126bc61f6..428ed19e1 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -877,15 +877,29 @@ typedef struct ivas_omasa_enc_state_structure } OMASA_ENC_STATE, *OMASA_ENC_HANDLE; +#ifdef FIX_1161_REDUCE_OMASA_HEAP +typedef struct ivas_omasa_encoder_energy_struct +{ + Word32 energy_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word16 energy_ism_fx_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; + Word32 q_energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; /* Q30 */ -typedef struct ivas_omasa_encoder_one_data_struct +} OMASA_ENCODER_ENERGY_STATE, *OMASA_ENCODER_ENERGY_HANDLE; + +#endif +typedef struct ivas_omasa_encoder_data_struct { +#ifdef FIX_1161_REDUCE_OMASA_HEAP + OMASA_ENCODER_ENERGY_HANDLE hOmasaEnergy; +#else Word32 energy_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word16 energy_ism_fx_e[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; Word32 energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; /*q30*/ Word32 q_energy_ratio_ism_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS]; /* Q30 */ - Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ - Word16 lp_noise_CPE_fx; /* LP filtered total noise estimation Q8 */ +#endif + Word32 masa_to_total_energy_ratio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Q30 */ + Word16 lp_noise_CPE_fx; /* LP filtered total noise estimation Q8 */ Word16 omasa_stereo_sw_cnt; -- GitLab From 76197112b3c5ee0bcce139cf6e9899dbd5881e80 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 20 Aug 2025 11:18:16 +0200 Subject: [PATCH 2/2] fix: missing instance in porting --- lib_enc/ivas_masa_enc_fx.c | 46 +++++++++++++++++++++++++++++++++---- lib_enc/ivas_omasa_enc_fx.c | 37 +++++++++++++++++++++++------ 2 files changed, 71 insertions(+), 12 deletions(-) diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index 5c61deb71..334feb7c5 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -116,6 +116,7 @@ static void masa_metadata_direction_alignment_fx( MASA_ENCODER_HANDLE hMasa ); * * open and initialize MASA encoder *-----------------------------------------------------------------------*/ + ivas_error ivas_masa_enc_open_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder handle */ ) @@ -261,11 +262,13 @@ ivas_error ivas_masa_enc_open_fx( return error; } + /*-----------------------------------------------------------------------* * ivas_masa_enc_close() * * close MASA encoder *-----------------------------------------------------------------------*/ + void ivas_masa_enc_close_fx( MASA_ENCODER_HANDLE *hMasa /* i/o: MASA metadata structure */ ) @@ -303,6 +306,7 @@ void ivas_masa_enc_close_fx( return; } + /*-----------------------------------------------------------------------* * ivas_masa_encode() * @@ -862,6 +866,8 @@ ivas_error ivas_masa_encode_fx( return IVAS_ERR_OK; } + + /*-----------------------------------------------------------------------* * ivas_masa_estimate_energy_fx() * @@ -873,7 +879,7 @@ void ivas_masa_estimate_energy_fx( Word32 *data_fx[], /* i : Input audio channels Q(q_data) */ const Word16 input_frame, /* i : frame length */ const Word16 nchan_transport, /* i : number of MASA input/transport channels */ - Word16 q_data /* i : q for data_fx */ + Word16 q_data /* i : q for data_fx */ ) { Word32 Input_RealBuffer[MASA_MAX_TRANSPORT_CHANNELS][CLDFB_NO_CHANNELS_MAX]; @@ -1046,7 +1052,6 @@ ivas_error ivas_masa_enc_config_fx( } } - /* Inspect metadata for parameter changes that affect coding. */ detect_metadata_composition_fx( hMasa, &joinedSubframes, &coherencePresent, &isActualTwoDir ); @@ -1089,7 +1094,6 @@ ivas_error ivas_masa_enc_config_fx( { set32_fx( hMasa->data.importanceWeight_fx, ONE_IN_Q30 /*1.0f Q30*/, MASA_FREQUENCY_BANDS ); - IF( EQ_16( hMasa->config.numCodingBands, 5 ) ) { hMasa->data.importanceWeight_fx[4] = 751619277 /*0.7f q30*/; @@ -1258,10 +1262,8 @@ ivas_error ivas_masa_enc_config_fx( } } - masa_sample_rate_band_correction_fx( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, maxBand, (UWord8) GE_32( masa_total_brate, IVAS_384k ), NULL ); - IF( GE_16( hMasa->config.numTwoDirBands, hMasa->config.numCodingBands ) ) { hMasa->config.numTwoDirBands = hMasa->config.numCodingBands; @@ -1304,13 +1306,17 @@ ivas_error ivas_masa_enc_config_fx( } move16(); } + return error; } + + /*-----------------------------------------------------------------------* * ivas_masa_surrcoh_signicant() * * Determine if surrounding coherence is significant in this frame and should be encoded *-----------------------------------------------------------------------*/ + UWord8 ivas_masa_surrcoh_signicant_fx( Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Surround coherence Q31 */ Word32 diffuse_to_total_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i : Diffuse to total ratio Q31 */ @@ -1381,6 +1387,7 @@ UWord8 ivas_masa_surrcoh_signicant_fx( return 0; } + /*-----------------------------------------------------------------------* * Local functions *-----------------------------------------------------------------------*/ @@ -1707,6 +1714,7 @@ static void combine_freqbands_and_subframes_fx( * * *-------------------------------------------------------------------*/ + void ivas_masa_combine_directions_fx( MASA_ENCODER_HANDLE hMasa ) { @@ -2385,6 +2393,7 @@ static void compensate_energy_ratios_fx( return; } + /* If the bit budget is very low, reduce metadata further to either 1 subframe and 5 bands, or 1 band and 4 subframes, based on which works better */ static void reduce_metadata_further_fx( MASA_ENCODER_HANDLE hMasa, @@ -2992,6 +3001,7 @@ static Word16 encode_lfe_to_total_energy_ratio_fx( * * Reconfigure IVAS MASA encoder *-------------------------------------------------------------------*/ + void ivas_masa_enc_reconfigure_fx( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ) @@ -3071,11 +3081,13 @@ void ivas_masa_enc_reconfigure_fx( return; } + /*-------------------------------------------------------------------* * average_masa_metadata() * * Average MASA metadata frame subframe contents: applies aggregation over time *-------------------------------------------------------------------*/ + static void average_masa_metadata_fx( MASA_METADATA_FRAME *hMeta, Word32 energy[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /*i Q(31 - energy_e) */ @@ -3238,6 +3250,7 @@ static void average_masa_metadata_fx( * * Copy MASA metadata frame subframe contents *-------------------------------------------------------------------*/ + static void copy_masa_metadata_subframe_fx( const MASA_METADATA_HANDLE hMetaFrom, /* i : MASA frame metdata to be copied */ const UWord8 sfFrom, /* i : subframe index of the copy source */ @@ -3270,11 +3283,13 @@ static void copy_masa_metadata_subframe_fx( return; } + /*-------------------------------------------------------------------* * copy_masa_metadata() * * Copy MASA metada frame contents *-------------------------------------------------------------------*/ + static void copy_masa_metadata_fx( const MASA_METADATA_HANDLE hMetaFrom, /* i : MASA frame metadata to be copied */ MASA_METADATA_HANDLE hMetaTo /* o : MASA frame metadata copy destination */ @@ -3313,6 +3328,7 @@ static void copy_masa_metadata_fx( return; } + /*-------------------------------------------------------------------* * are_masa_subframes_similar() * @@ -3428,6 +3444,7 @@ static UWord8 are_masa_subframes_similar_fx( } } + /*-------------------------------------------------------------------* * detect_framing_async() * @@ -3435,6 +3452,7 @@ static UWord8 are_masa_subframes_similar_fx( * Analysis result is stored in hMasa->data.sync_state, and * potentially hMasa->masaMetadata is modified *-------------------------------------------------------------------*/ + static void detect_framing_async_fx( MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder structure */ ) @@ -3580,12 +3598,14 @@ static void detect_framing_async_fx( return; } + /*-------------------------------------------------------------------* * masa_metadata_direction_alignment() * * In 2dir MASA metadata, determine the ordering of the directional * fields such that the azi/ele change across time is minimized. *-------------------------------------------------------------------*/ + static void masa_metadata_direction_alignment_fx( MASA_ENCODER_HANDLE hMasa /* i/o: MASA encoder handle */ ) @@ -4058,6 +4078,8 @@ void ivas_merge_masa_metadata_fx( return; } + + static void quantize_ratio_ism_vector_ivas_fx( const Word16 *ratio_ism, /* ratio_ism_e */ Word16 ratio_ism_e, @@ -4243,6 +4265,8 @@ static void quantize_ratio_ism_vector_ivas_fx( return; } + + static Word16 index_slice_enum_fx( const Word16 *ratio_ism_idx, const Word16 nchan_ism ) @@ -4308,6 +4332,8 @@ static void transform_difference_index_ivas_fx( return; } + + static void transform_index_and_GR_encode_ivas_fx( Word16 *diff_idx, /* i : differenc eindex to encode */ const Word16 len, /* i : input length */ @@ -4329,6 +4355,8 @@ static void transform_index_and_GR_encode_ivas_fx( return; } + + static Word16 try_differential_fx( const Word16 numCodingBands, const Word32 *masa_to_total_energy_ratio, /* Q30 */ @@ -4384,6 +4412,7 @@ static Word16 try_differential_fx( return nbits0; } + static void differential_coding_first_subframe_ivas_fx( BSTR_ENC_HANDLE hMetaData, const Word32 *masa_to_total_energy_ratio, // Q30 @@ -4422,6 +4451,8 @@ static void differential_coding_first_subframe_ivas_fx( return; } + + static void independent_coding_ratio_ism_idx_fx( Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], /* i : ISM ratios */ const Word32 *masa_to_total_energy_ratio, /* i : MASA to total ratios, Q30 */ @@ -4445,6 +4476,7 @@ static void independent_coding_ratio_ism_idx_fx( return; } + static void remove_sep_obj_fx( Word16 *diff_idx, /* i/o: array of difference of indexes */ const Word16 nchan_ism, /* i : number of objects */ @@ -4462,6 +4494,7 @@ static void remove_sep_obj_fx( return; } + static void estimate_bits_subband_ism_ratio_fx( const Word16 *ratio_ism_idx, const Word16 *ratio_ism_idx_ref, /* ( i/o ) */ @@ -4506,6 +4539,7 @@ static void estimate_bits_subband_ism_ratio_fx( return; } + static Word16 encode_ratio_ism_subframe_fx( Word16 ratio_ism_idx[MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS], const Word16 nchan_ism, @@ -5290,11 +5324,13 @@ static void ivas_encode_masaism_metadata_fx( return; } + /*-------------------------------------------------------------------* * ivas_merge_masa_transports() * * Merge MASA transport channels *-------------------------------------------------------------------*/ + void ivas_merge_masa_transports_fx( Word32 data_in_f1_fx[][L_FRAME48k], // Qx Word32 *data_in_f2_fx[], // Qx diff --git a/lib_enc/ivas_omasa_enc_fx.c b/lib_enc/ivas_omasa_enc_fx.c index a6e3446a1..838ca1944 100644 --- a/lib_enc/ivas_omasa_enc_fx.c +++ b/lib_enc/ivas_omasa_enc_fx.c @@ -51,9 +51,11 @@ #define OMASA_FEC_MAX 5 + /*------------------------------------------------------------------------- * Local function prototypes *------------------------------------------------------------------------*/ + static void ivas_omasa_param_est_enc_fx( OMASA_ENC_HANDLE hOMasa, OMASA_ENCODER_DATA_HANDLE hOmasaData, @@ -219,13 +221,13 @@ ivas_error ivas_omasa_enc_open_fx( return error; } + /*--------------------------------------------------------------------------* * ivas_omasa_enc_close() * * Close OMASA handle *--------------------------------------------------------------------------*/ - void ivas_omasa_enc_close_fx( OMASA_ENC_HANDLE *hOMasa /* i/o: encoder OMASA handle */ ) @@ -360,6 +362,7 @@ ivas_error ivas_omasa_enc_config_fx( ivas_write_format_fx( st_ivas ); + /* OMASA encoder handle */ test(); test(); IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && st_ivas->hOMasa == NULL ) @@ -375,6 +378,24 @@ ivas_error ivas_omasa_enc_config_fx( st_ivas->hOMasa = NULL; } +#ifdef FIX_1161_REDUCE_OMASA_HEAP + /* OMASA energy handle */ + test(); + test(); + IF( NE_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && st_ivas->hMasa->data.hOmasaData->hOmasaEnergy == NULL ) + { + IF( ( st_ivas->hMasa->data.hOmasaData->hOmasaEnergy = (OMASA_ENCODER_ENERGY_HANDLE) malloc( sizeof( OMASA_ENCODER_ENERGY_STATE ) ) ) == NULL ) + { + return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OMASA energy handle\n" ) ); + } + } + ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && st_ivas->hMasa->data.hOmasaData->hOmasaEnergy != NULL ) + { + free( st_ivas->hMasa->data.hOmasaData->hOmasaEnergy ); + st_ivas->hMasa->data.hOmasaData->hOmasaEnergy = NULL; + } + +#endif st_ivas->hCPE[0]->element_brate = L_sub( ivas_total_brate, ism_total_brate ); move32(); @@ -410,6 +431,7 @@ ivas_error ivas_omasa_enc_config_fx( * * Frame-by-frame config for oMASA *--------------------------------------------------------------------------*/ + void ivas_omasa_set_config_fx( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i : MASA encoder handle */ @@ -492,7 +514,7 @@ void ivas_omasa_enc_fx( OMASA_ENC_HANDLE hOMasa, /* i/o: OMASA encoder handle */ MASA_ENCODER_HANDLE hMasa, /* i/o: MASA encoder handle */ ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handle */ - Word32 *data_in[], /* i/o: Input / transport audio signals q_data*/ + Word32 *data_in[], /* i/o: Input / transport audio signals q_data*/ Word16 q_data, /* i : Q0 Stores the q for data_in */ const Word16 input_frame, /* i : Input frame size */ const Word16 nchan_transport, /* i : Number of transport channels */ @@ -954,11 +976,11 @@ void ivas_set_surplus_brate_enc( /*! r: OMASA energy bitrate flag */ Word16 ivas_omasa_ener_brate_fx( - const Word16 nchan_ism, /* i : number of ISMs */ - const Word32 ivas_total_brate, /* i : IVAS total bitrate */ - Word32 *data_f[], /* i : Input / transport audio signals data_e*/ - const Word16 input_frame, /* i : Input frame size */ - const Word16 data_e /* i : exponent for data_f */ + const Word16 nchan_ism, /* i : number of ISMs */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate */ + Word32 *data_f[], /* i : Input / transport audio signals data_e*/ + const Word16 input_frame, /* i : Input frame size */ + const Word16 data_e /* i : exponent for data_f */ ) { Word16 i, flag_omasa_ener_brate; @@ -966,6 +988,7 @@ Word16 ivas_omasa_ener_brate_fx( Word16 energy_ism_e, energy_masa_e; Word32 temp_32; Word16 temp, temp_e; + flag_omasa_ener_brate = 0; energy_ism_e = 0; energy_masa_e = 0; -- GitLab