From e67772070064dd794f83a3396c0073ad2b2abd37 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 3 Aug 2023 15:21:33 +0300 Subject: [PATCH 1/8] Implementation of JBM for OMASA. --- lib_com/ivas_prot.h | 32 ++++ lib_dec/ivas_ism_renderer.c | 160 ++++++++++++++++++- lib_dec/ivas_jbm_dec.c | 134 ++++++++++++++++ lib_dec/ivas_masa_dec.c | 13 ++ lib_dec/ivas_objectRenderer_internal.c | 43 +++++ lib_dec/ivas_omasa_dec.c | 97 ++++++++++- lib_dec/ivas_stat_dec.h | 3 + lib_rend/ivas_dirac_dec_binaural_functions.c | 30 +++- 8 files changed, 503 insertions(+), 9 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 80996fb819..d5ea0487a7 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -5767,12 +5767,34 @@ ivas_error ivas_omasa_dirac_td_binaural( const int16_t output_frame /* i : output frame length per channel */ ); +#ifdef MASA_AND_OBJECTS +ivas_error ivas_omasa_dirac_td_binaural_jbm( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nSamplesAsked, /* i : number of samples requested */ + uint16_t *nSamplesRendered, /* o : number of samples rendered */ + uint16_t *nSamplesAvailable, /* o : number of samples still to render */ + const int16_t nchan_transport, /* i : number of transport channels */ + float *output_f[] /* o : rendered time signal */ +); +#endif + void ivas_omasa_dirac_rend( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float output[][L_FRAME48k], /* o : output synthesis signal */ const int16_t output_frame /* i : output frame length per channel */ ); +#ifdef MASA_AND_OBJECTS +void ivas_omasa_dirac_rend_jbm( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nSamplesAsked, /* i : number of samples requested */ + uint16_t *nSamplesRendered, /* o : number of samples rendered */ + uint16_t *nSamplesAvailable, /* o : number of samples still to render */ + const int16_t nchan_transport, /* i : number of transport channels */ + float *output_f[] /* o : rendered time signal */ +); +#endif + void ivas_omasa_preProcessStereoTransportsForMovedObjects( Decoder_Struct *st_ivas, float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], @@ -5796,6 +5818,16 @@ void ivas_omasa_separate_object_render( const int16_t output_frame /* i : output frame length per channel */ ); +#ifdef MASA_AND_OBJECTS +void ivas_omasa_separate_object_render_jbm( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const uint16_t nSamplesRendered, /* i : number of samples rendered */ + float *output_f[], /* o : rendered time signal */ + const int16_t subframes_rendered, /* i : number of subframes rendered */ + const int16_t slots_rendered /* i : number of CLDFB slots rendered */ +); +#endif + void ivas_omasa_set_edited_objects( Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ ); diff --git a/lib_dec/ivas_ism_renderer.c b/lib_dec/ivas_ism_renderer.c index 33d3598e0e..9b82c24a6b 100644 --- a/lib_dec/ivas_ism_renderer.c +++ b/lib_dec/ivas_ism_renderer.c @@ -365,7 +365,6 @@ ivas_error ivas_omasa_separate_object_renderer_open( set_f( st_ivas->hIsmRendererData->prev_gains[i], 0.0f, MAX_OUTPUT_CHANNELS ); } - // Todo OMASA JBM: This needs touches for VOIP path at least. Current version is mostly an adapted copy from ivas_ism_renderer_open() if ( st_ivas->hDecoderConfig->voip_active ) { init_interpolator_length = NS2SA( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_CLDFB_TIMESLOTS * CLDFB_SLOT_NS ); @@ -382,6 +381,7 @@ ivas_error ivas_omasa_separate_object_renderer_open( { st_ivas->hIsmRendererData->interpolator[i] = (float) i / ( (float) interpolator_length ); } + st_ivas->hIsmRendererData->interpolator_length = interpolator_length; st_ivas->hMasaIsmData->delayBuffer_size = (int16_t) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES ); @@ -464,7 +464,6 @@ void ivas_omasa_separate_object_renderer_close( * Rendering separated objects and mixing them to the parametrically rendered signals *-------------------------------------------------------------------------*/ -// Todo OMASA JBM: This might need adjustments void ivas_omasa_separate_object_render( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float input_f[][L_FRAME48k], /* i : separated object signal */ @@ -569,4 +568,161 @@ void ivas_omasa_separate_object_render( return; } + +/*-------------------------------------------------------------------------* + * ivas_omasa_separate_object_render_jbm() + * + * Rendering separated objects and mixing them to the parametrically rendered signals for JBM + *-------------------------------------------------------------------------*/ + +void ivas_omasa_separate_object_render_jbm( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + const uint16_t nSamplesRendered, /* i : number of samples rendered */ + float *output_f[], /* o : rendered time signal */ + const int16_t subframes_rendered, /* i : number of subframes rendered */ + const int16_t slots_rendered /* i : number of CLDFB slots rendered */ +) +{ + VBAP_HANDLE hVBAPdata; + DIRAC_REND_HANDLE hDirACRend; + SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom; + int16_t nchan_out_woLFE, num_lfe; + ISM_RENDERER_HANDLE hRendererData; + int16_t j, k, j2; + int16_t obj; + float gains[MAX_OUTPUT_CHANNELS]; + float g1, g2; + int16_t lfe_index; + int16_t azimuth, elevation; + int16_t num_objects; + uint8_t single_separated; + float *input_f[MAX_TRANSPORT_CHANNELS]; + float *output_f_local[MAX_OUTPUT_CHANNELS]; + int16_t offsetSamples; + int16_t n_samples_sf, md_idx; + int16_t slots_to_render, first_sf, last_sf, subframe_idx; + + hVBAPdata = st_ivas->hVBAPdata; + hDirACRend = st_ivas->hDirACRend; + hSpatParamRendCom = st_ivas->hSpatParamRendCom; + nchan_out_woLFE = st_ivas->hIntSetup.nchan_out_woLFE; + num_lfe = st_ivas->hIntSetup.num_lfe; + hRendererData = st_ivas->hIsmRendererData; + lfe_index = hDirACRend->hOutSetup.index_lfe[0]; + + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + single_separated = 1; + num_objects = 1; + } + else + { + single_separated = 0; + num_objects = st_ivas->nchan_ism; + } + + offsetSamples = slots_rendered * hSpatParamRendCom->slot_size; + + for ( j = 0; j < nchan_out_woLFE + num_lfe; j++ ) + { + output_f_local[j] = output_f[j]; + } + + for ( obj = 0; obj < num_objects; obj++ ) + { + input_f[obj] = &st_ivas->hTcBuffer->tc[obj + 2][offsetSamples]; + } + + slots_to_render = nSamplesRendered / hSpatParamRendCom->slot_size; + first_sf = subframes_rendered; + last_sf = first_sf; + + while ( slots_to_render > 0 ) + { + slots_to_render -= hSpatParamRendCom->subframe_nbslots[last_sf]; + last_sf++; + } + + for ( obj = 0; obj < num_objects; obj++ ) + { + /* Delay the signal to match CLDFB delay. Delay the whole buffer with the first rendering call of the stretched buffer. */ + if ( slots_rendered == 0 ) + { + int16_t tcBufferSize; + + tcBufferSize = hSpatParamRendCom->num_slots * hSpatParamRendCom->slot_size; + delay_signal( input_f[obj], tcBufferSize, st_ivas->hMasaIsmData->delayBuffer[obj], st_ivas->hMasaIsmData->delayBuffer_size ); + } + + offsetSamples = 0; + + for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ ) + { + n_samples_sf = hSpatParamRendCom->subframe_nbslots[subframe_idx] * hSpatParamRendCom->slot_size; + if ( n_samples_sf != hRendererData->interpolator_length ) + { + for ( k = 0; k < n_samples_sf; k++ ) + { + hRendererData->interpolator[k] = (float) k / ( (float) n_samples_sf ); + } + hRendererData->interpolator_length = n_samples_sf; + } + + md_idx = hSpatParamRendCom->render_to_md_map[subframe_idx]; + + if ( single_separated ) + { + azimuth = st_ivas->hMasaIsmData->azimuth_separated_ism[md_idx]; + elevation = st_ivas->hMasaIsmData->elevation_separated_ism[md_idx]; + } + else + { + azimuth = st_ivas->hMasaIsmData->azimuth_ism[obj][md_idx]; + elevation = st_ivas->hMasaIsmData->elevation_ism[obj][md_idx]; + } + + if ( st_ivas->hOutSetup.is_planar_setup ) + { + /* If no elevation support in output format, then rendering should be done with zero elevation */ + elevation = 0; + } + + if ( hVBAPdata != NULL ) + { + vbap_determine_gains( hVBAPdata, gains, azimuth, elevation, 1 ); + } + else + { + ivas_dirac_dec_get_response( azimuth, elevation, gains, hDirACRend->hOutSetup.ambisonics_order ); + } + + for ( j = 0; j < nchan_out_woLFE; j++ ) + { + if ( hDirACRend->hOutSetup.num_lfe > 0 ) + { + j2 = j + ( j >= lfe_index ); + } + else + { + j2 = j; + } + + if ( fabsf( gains[j] ) > 0.0f || fabsf( hRendererData->prev_gains[obj][j] ) > 0.0f ) + { + for ( k = 0; k < n_samples_sf; k++ ) + { + g1 = hRendererData->interpolator[k]; + g2 = 1.0f - g1; + output_f_local[j2][k + offsetSamples] += ( g1 * gains[j] + g2 * hRendererData->prev_gains[obj][j] ) * input_f[obj][k + offsetSamples]; + } + } + hRendererData->prev_gains[obj][j] = gains[j]; + } + + offsetSamples += n_samples_sf; + } + } + + return; +} #endif diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 276fdff4e3..87d947a21c 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -77,7 +77,11 @@ ivas_error ivas_jbm_dec_tc( float output[MAX_TRANSPORT_CHANNELS][L_FRAME48k]; /* 'float' buffer for transport channels, MAX_TRANSPORT_CHANNELS channels */ int16_t nchan_remapped; float output_lfe_ch[L_FRAME48k]; +#ifdef MASA_AND_OBJECTS + int16_t nb_bits_metadata[MAX_SCE + 1]; +#else int16_t nb_bits_metadata[MAX_SCE]; +#endif int32_t output_Fs, ivas_total_brate; AUDIO_CONFIG output_config; ivas_error error; @@ -85,6 +89,9 @@ ivas_error ivas_jbm_dec_tc( #ifdef VLBR_20MS_MD int16_t num_md_sub_frames; #endif +#ifdef MASA_AND_OBJECTS + int32_t ism_total_brate; +#endif error = IVAS_ERR_OK; @@ -331,6 +338,80 @@ ivas_error ivas_jbm_dec_tc( #endif } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + int16_t nchan_ism, nchan_transport_ism; + int16_t dirac_bs_md_write_idx; + + st = st_ivas->hCPE[0]->hCoreCoder[0]; + set_s( nb_bits_metadata, 0, MAX_SCE + 1 ); + + /* Set the number of objects for the parametric rendering */ + dirac_bs_md_write_idx = 0; + if ( st_ivas->hDirAC != NULL ) + { + st_ivas->hSpatParamRendCom->numIsmDirections = 0; + if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC && st_ivas->ism_mode != ISM_MASA_MODE_MASA_ONE_OBJ ) + { + st_ivas->hSpatParamRendCom->numIsmDirections = st_ivas->nchan_ism; + } + + dirac_bs_md_write_idx = st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx; /* Store the write-index for this frame */ + } + + /* MASA metadata decoding */ + if ( ( error = ivas_masa_decode( st_ivas, st, &nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Configuration of combined-format bit-budget distribution */ + ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate ); + + st->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] ); + + /* set ISM parameters and decode ISM metadata in OMASA format */ + if ( ( error = ivas_omasa_ism_metadata_dec( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* decode ISM channels */ + for ( n = 0; n < nchan_transport_ism; n++ ) + { + if ( ( error = ivas_sce_dec( st_ivas, n, &output[st_ivas->nchan_transport + n], output_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) + { + return error; + } + } + + /* decode MASA channels */ + if ( ( error = ivas_cpe_dec( st_ivas, 0, output, output_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + { + return error; + } + + if ( st_ivas->hCPE[0]->nchan_out == 1 ) + { + mvr2r( output[0], output[1], output_frame ); /* Copy mono signal to stereo output channels */ + } + + /* HP filtering */ + for ( n = 0; n < getNumChanSynthesis( st_ivas ); n++ ) + { + hp20( output[n], output_frame, st_ivas->mem_hp20_out[n], output_Fs ); + } + + if ( st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + { + ivas_mono_downmix_render_passive( st_ivas, output, output_frame ); + } + + /* Set edited object positions, if editing enabled */ + ivas_omasa_set_edited_objects( st_ivas ); + } +#endif else if ( st_ivas->ivas_format == MC_FORMAT ) { st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; @@ -642,6 +723,21 @@ ivas_error ivas_jbm_dec_feed_tc_to_renderer( { ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + n_render_timeslots *= (st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size); + } + ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); + + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + ivas_ism_dec_digest_tc( st_ivas ); + } + } +#endif else if ( st_ivas->ivas_format == MC_FORMAT ) { if ( st_ivas->mc_mode == MC_MODE_MCT ) @@ -878,6 +974,31 @@ ivas_error ivas_jbm_dec_render( ivas_sba_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output ); } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + nchan_remapped = st_ivas->nchan_transport; + + if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC ) + { + if ( ( ivas_omasa_dirac_td_binaural_jbm( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + ivas_dirac_dec_binaural_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); + } + } + else if ( st_ivas->renderer_type == RENDERER_DIRAC ) + { + ivas_omasa_dirac_rend_jbm( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output ); + } + } +#endif else if ( st_ivas->ivas_format == MC_FORMAT ) { if ( st_ivas->mc_mode == MC_MODE_MCT ) @@ -1512,6 +1633,19 @@ int16_t ivas_jbm_dec_get_num_tc_channels( } } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ || st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ) + { + num_tc++; + } + else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + num_tc += st_ivas->nchan_ism; + } + } +#endif else if ( st_ivas->ivas_format == MC_FORMAT ) { if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_MONO ) diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 7027d49250..b96ada7789 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -674,8 +674,21 @@ ivas_error ivas_masa_dec_open( { buffer_mode = TC_BUFFER_MODE_BUFFER; } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + { + buffer_mode = TC_BUFFER_MODE_BUFFER; + } +#endif nchan_to_allocate = ivas_jbm_dec_get_num_tc_channels( st_ivas ); +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) + { + nchan_to_allocate = 1; + } +#endif + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_to_allocate, nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_dec/ivas_objectRenderer_internal.c b/lib_dec/ivas_objectRenderer_internal.c index 497ae240f2..45cb04ce21 100644 --- a/lib_dec/ivas_objectRenderer_internal.c +++ b/lib_dec/ivas_objectRenderer_internal.c @@ -155,6 +155,23 @@ ivas_error ivas_td_binaural_renderer_sf( int16_t ism_md_subframe_update_jbm; int16_t c_indx, nS; +#ifdef MASA_AND_OBJECTS + int16_t nchan_ism_internal, nchan_ism, ch_offset; + + /* Set the number of ISMs */ + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + nchan_ism_internal = st_ivas->nchan_ism; + nchan_ism = st_ivas->nchan_ism; + ch_offset = 2; + } + else + { + nchan_ism_internal = st_ivas->hTcBuffer->nchan_transport_internal; + nchan_ism = st_ivas->nchan_transport; + ch_offset = 0; + } +#endif /* Number of subframes to delay metadata to sync with audio */ if ( st_ivas->hDecoderConfig->Opt_delay_comp ) @@ -166,15 +183,29 @@ ivas_error ivas_td_binaural_renderer_sf( ism_md_subframe_update_jbm = st_ivas->hTcBuffer->nb_subframes - 2; } +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + ism_md_subframe_update_jbm = max( 0, st_ivas->hTcBuffer->nb_subframes - 4 ); /* Todo Nokia: Update this value to match the value of nonJBM rendering. */ + } +#endif + for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ ) { p_reverb_signal[ch] = reverb_signal[ch]; } +#ifdef MASA_AND_OBJECTS + for ( ch = 0; ch < nchan_ism_internal; ch++ ) + { + tc_local[ch] = st_ivas->hTcBuffer->tc[ch + ch_offset] + st_ivas->hTcBuffer->n_samples_rendered; + } +#else for ( ch = 0; ch < st_ivas->hTcBuffer->nchan_transport_internal; ch++ ) { tc_local[ch] = st_ivas->hTcBuffer->tc[ch] + st_ivas->hTcBuffer->n_samples_rendered; } +#endif for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ ) { @@ -202,7 +233,11 @@ ivas_error ivas_td_binaural_renderer_sf( /* Update object position(s) */ c_indx = 0; +#ifdef MASA_AND_OBJECTS + for ( nS = 0; nS < nchan_ism; nS++ ) +#else for ( nS = 0; nS < st_ivas->nchan_transport; nS++ ) +#endif { if ( !( st_ivas->ivas_format == MC_FORMAT && nS == LFE_CHANNEL ) ) /* Skip LFE for MC */ { @@ -213,7 +248,11 @@ ivas_error ivas_td_binaural_renderer_sf( } if ( subframe_idx == ism_md_subframe_update_jbm ) { +#ifdef MASA_AND_OBJECTS + TDREND_Update_object_positions( st_ivas->hBinRendererTd, nchan_ism, st_ivas->ivas_format, st_ivas->hIsmMetaData ); +#else TDREND_Update_object_positions( st_ivas->hBinRendererTd, st_ivas->nchan_transport, st_ivas->ivas_format, st_ivas->hIsmMetaData ); +#endif } /* Update the listener's location/orientation */ @@ -244,7 +283,11 @@ ivas_error ivas_td_binaural_renderer_sf( } +#ifdef MASA_AND_OBJECTS + for ( ch = 0; ch < nchan_ism_internal; ch++ ) +#else for ( ch = 0; ch < st_ivas->hTcBuffer->nchan_transport_internal; ch++ ) +#endif { tc_local[ch] += output_frame; } diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 7cff26a856..1d52b844ef 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -44,6 +44,13 @@ #ifdef MASA_AND_OBJECTS +/*------------------------------------------------------------------------- + * Local constants + *------------------------------------------------------------------------*/ + +#define OMASA_TDREND_MATCHING_GAIN 0.7943f + + /*-------------------------------------------------------------------* * ivas_omasa_data_open() * @@ -559,7 +566,6 @@ ivas_error ivas_omasa_ism_metadata_dec( * Rendering in OMASA format *--------------------------------------------------------------------------*/ -// Todo OMASA JBM: This might need adjustments void ivas_omasa_dirac_rend( Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ float output[][L_FRAME48k], /* o : output synthesis signal */ @@ -593,6 +599,35 @@ void ivas_omasa_dirac_rend( } +/*--------------------------------------------------------------------------* + * ivas_omasa_dirac_rend_jbm() + * + * Rendering in OMASA format for JBM + *--------------------------------------------------------------------------*/ + +void ivas_omasa_dirac_rend_jbm( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nSamplesAsked, /* i : number of samples requested */ + uint16_t *nSamplesRendered, /* o : number of samples rendered */ + uint16_t *nSamplesAvailable, /* o : number of samples still to render */ + const int16_t nchan_transport, /* i : number of transport channels */ + float *output_f[] /* o : rendered time signal */ +) +{ + int16_t subframes_rendered; + int16_t slots_rendered; + + subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered; + + ivas_dirac_dec_render( st_ivas, nchan_transport, nSamplesAsked, nSamplesRendered, nSamplesAvailable, output_f ); + + ivas_omasa_separate_object_render_jbm( st_ivas, *nSamplesRendered, output_f, subframes_rendered, slots_rendered ); + + return; +} + + /*--------------------------------------------------------------------------* * ivas_omasa_dirac_td_binaural() * @@ -607,7 +642,7 @@ ivas_error ivas_omasa_dirac_td_binaural( { int16_t n; float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; - float gain = 0.7943f; /* Todo Nokia: Temporary gain for roughly matching the loudness of other processing paths. */ + float gain = OMASA_TDREND_MATCHING_GAIN; ivas_error error; float *p_sepobj[MAX_NUM_OBJECTS]; @@ -641,4 +676,62 @@ ivas_error ivas_omasa_dirac_td_binaural( return IVAS_ERR_OK; } + + +/*--------------------------------------------------------------------------* + * ivas_omasa_dirac_td_binaural_render() + * + * Binaural rendering in OMASA format for JBM + *--------------------------------------------------------------------------*/ + +ivas_error ivas_omasa_dirac_td_binaural_jbm( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + const uint16_t nSamplesAsked, /* i : number of samples requested */ + uint16_t *nSamplesRendered, /* o : number of samples rendered */ + uint16_t *nSamplesAvailable, /* o : number of samples still to render */ + const int16_t nchan_transport, /* i : number of transport channels */ + float *output_f[] /* o : rendered time signal */ +) +{ + int16_t n; + float data_separated_objects[MAX_NUM_OBJECTS][L_FRAME48k]; + float gain = OMASA_TDREND_MATCHING_GAIN; + ivas_error error; + float *p_sepobj[MAX_NUM_OBJECTS]; + float *tc_local[MAX_TRANSPORT_CHANNELS]; + + for ( n = 0; n < MAX_NUM_OBJECTS; n++ ) + { + p_sepobj[n] = &data_separated_objects[n][0]; + } + + /* Delay the object signals to match the CLDFB delay. Delay the whole buffer with the first rendering call of the stretched buffer. */ + if ( st_ivas->hSpatParamRendCom->slots_rendered == 0 ) + { + int16_t tcBufferSize; + + tcBufferSize = st_ivas->hSpatParamRendCom->num_slots * st_ivas->hSpatParamRendCom->slot_size; + + for ( n = 0; n < st_ivas->nchan_ism; n++ ) + { + tc_local[n] = st_ivas->hTcBuffer->tc[n + 2]; + v_multc( tc_local[n], gain, tc_local[n], tcBufferSize ); + delay_signal( tc_local[n], tcBufferSize, st_ivas->hMasaIsmData->delayBuffer[n], st_ivas->hMasaIsmData->delayBuffer_size ); + } + } + + ivas_dirac_dec_binaural_render( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, nchan_transport, output_f ); + + if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK ) + { + return error; + } + + for ( n = 0; n < BINAURAL_CHANNELS; n++ ) + { + v_add( output_f[n], p_sepobj[n], output_f[n], *nSamplesRendered ); + } + + return IVAS_ERR_OK; +} #endif diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index 89a2bb07a8..13600d3a73 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -777,6 +777,9 @@ typedef struct renderer_struct { float prev_gains[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; float *interpolator; +#ifdef MASA_AND_OBJECTS + int16_t interpolator_length; +#endif float gains[MAX_CICP_CHANNELS - 1][MAX_OUTPUT_CHANNELS]; } ISM_RENDERER_DATA, *ISM_RENDERER_HANDLE; diff --git a/lib_rend/ivas_dirac_dec_binaural_functions.c b/lib_rend/ivas_dirac_dec_binaural_functions.c index c729f964ad..7b83adf1f0 100644 --- a/lib_rend/ivas_dirac_dec_binaural_functions.c +++ b/lib_rend/ivas_dirac_dec_binaural_functions.c @@ -121,7 +121,7 @@ static void ivas_dirac_dec_binaural_formulate_input_and_target_covariance_matric #endif #ifdef MASA_AND_OBJECTS -static void ivas_dirac_dec_binaural_determine_processing_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, float Rmat[3][3], const int16_t isHeadtracked, const int16_t nchanSeparateChannels, const MASA_ISM_DATA_HANDLE hMasaIsmData ); +static void ivas_dirac_dec_binaural_determine_processing_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, float Rmat[3][3], const int16_t subframe, const int16_t isHeadtracked, const int16_t nchanSeparateChannels, const MASA_ISM_DATA_HANDLE hMasaIsmData ); #else static void ivas_dirac_dec_binaural_determine_processing_matrices( DIRAC_DEC_BIN_HANDLE hDiracDecBin, SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, float Rmat[3][3], const int16_t isHeadtracked ); #endif @@ -339,9 +339,27 @@ ivas_error ivas_dirac_dec_init_binaural_data( if ( st_ivas->hDecoderConfig->voip_active == 1 && st_ivas->hTcBuffer == NULL ) { int16_t nchan_to_allocate; +#ifdef MASA_AND_OBJECTS + int16_t n_samples_granularity; +#endif nchan_to_allocate = 2 * BINAURAL_CHANNELS; +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + nchan_to_allocate = 2 * BINAURAL_CHANNELS + 2; + } + + n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ + } + + if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, ivas_jbm_dec_get_num_tc_channels( st_ivas ), nchan_to_allocate, nchan_to_allocate, n_samples_granularity ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, TC_BUFFER_MODE_RENDERER, ivas_jbm_dec_get_num_tc_channels( st_ivas ), nchan_to_allocate, nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -950,7 +968,7 @@ static void ivas_dirac_dec_binaural_internal( { nchanSeparateChannels = (uint8_t) st_ivas->nchan_ism; } - ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat, + ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat, subframe, hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); #else @@ -1031,7 +1049,7 @@ static void ivas_dirac_dec_binaural_internal( subFrameTotalEne, IIReneLimiter, st_ivas->hMasaIsmData ); - ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_local, + ivas_dirac_dec_binaural_determine_processing_matrices( hDiracDecBin, hSpatParamRendCom, &config_data, max_band_decorr, Rmat_local, subframe, hCombinedOrientationData && hCombinedOrientationData->enableCombinedOrientation[subframe] > 0, nchanSeparateChannels, st_ivas->hMasaIsmData ); #else @@ -2205,6 +2223,9 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( PARAMBIN_REND_CONFIG_HANDLE hConfig, const int16_t max_band_decorr, float Rmat[3][3], +#ifdef MASA_AND_OBJECTS + const int16_t subframe, +#endif const int16_t isHeadtracked #ifdef MASA_AND_OBJECTS , @@ -2245,8 +2266,7 @@ static void ivas_dirac_dec_binaural_determine_processing_matrices( #ifdef MASA_AND_OBJECTS ism_mode = hConfig->ism_mode; - // Todo OMASA JBM: This is probably not correct now. We should get the index from JBM - dirac_read_idx = hSpatParamRendCom->dirac_read_idx; + dirac_read_idx = hSpatParamRendCom->render_to_md_map[subframe]; #endif #ifdef MASA_AND_OBJECTS -- GitLab From a15f04f01a88af275a8bbf603f698e0262abb3ee Mon Sep 17 00:00:00 2001 From: advasila Date: Wed, 9 Aug 2023 10:33:03 +0300 Subject: [PATCH 2/8] fix for WB input --- lib_com/options.h | 2 +- lib_enc/ivas_masa_enc.c | 53 +++++++++++++++++++++++++++++++++--- lib_enc/ivas_qmetadata_enc.c | 3 +- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index e08160f768..141c4f39c9 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -216,7 +216,7 @@ #define FIX_625_IDX_OOB /* FhG: Fix index out-of-bounds UBSAN error (issue 625) */ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ - +#define FIX_WB_OMASA /* Nokia: fixes OMASA for WB input */ /* ################## End BE DEVELOPMENT switches ######################### */ diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index 18590f5cc0..44a92d013a 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -3522,15 +3522,23 @@ static void ivas_encode_masaism_metadata( int16_t tmp, rotate; int16_t n_ism_tmp, i; OMASA_ENCODER_DATA_HANDLE hOmasaData = hMasa->data.hOmasaData; + #ifdef FIX_WB_OMASA + int16_t nbands_work; + #endif /* use the values from hQMetaData */ numCodingBands = (uint8_t) hQMetaData->q_direction->cfg.nbands; numSf = (int8_t) hQMetaData->q_direction->cfg.nblocks; - +#ifdef FIX_WB_OMASA + nbands_work = min( numCodingBands, omasa_nbands ); + if ( numCodingBands == 1 ) +#else if ( numCodingBands != omasa_nbands ) +#endif { +#ifndef FIX_WB_OMASA assert( numCodingBands == 1 ); - +#endif for ( sf = 0; sf < numSf; sf++ ) { if ( sum_f( hOmasaData->energy_ism[sf], omasa_nbands ) == 0.0f ) @@ -3570,11 +3578,20 @@ static void ivas_encode_masaism_metadata( } } } +#ifdef FIX_WB_OMASA + else if (numSf == 1) +#else else if ( numSf != omasa_nblocks ) +#endif { +#ifndef FIX_WB_OMASA assert( numSf == 1 ); - +#endif +#ifdef FIX_WB_OMASA + for ( band = 0; band < nbands_work; band++ ) +#else for ( band = 0; band < numCodingBands; band++ ) +#endif { energy_ism = 0.0f; /* ISM energy for current subband */ for ( obj = 0; obj < nchan_ism; obj++ ) @@ -3614,12 +3631,28 @@ static void ivas_encode_masaism_metadata( hQMetaData->masa_to_total_energy_ratio[0][band] = eneBand / ( eneBand + energy_ism + EPSILON ); } } + +#ifdef FIX_WB_OMASA + for ( band = nbands_work; band < numCodingBands; band++ ) + { + hQMetaData->masa_to_total_energy_ratio[0][band] = 1.0f; + + for ( obj = 0; obj < nchan_ism; obj++ ) + { + hOmasaData->energy_ratio_ism[0][band][obj] = hOmasaData->energy_ratio_ism[0][nbands_work-1][obj]; + } + } +#endif } else { for ( sf = 0; sf < numSf; sf++ ) { +#ifdef FIX_WB_OMASA + for ( band = 0; band < nbands_work; band++ ) +#else for ( band = 0; band < numCodingBands; band++ ) +#endif { if ( hOmasaData->energy_ism[sf][band] == 0.0f ) { @@ -3638,6 +3671,18 @@ static void ivas_encode_masaism_metadata( hQMetaData->masa_to_total_energy_ratio[sf][band] = eneBand / ( eneBand + hOmasaData->energy_ism[sf][band] + EPSILON ); } } + + #ifdef FIX_WB_OMASA + for ( band = nbands_work; band < numCodingBands; band++ ) + { + hQMetaData->masa_to_total_energy_ratio[sf][band] = 1.0f; + + for ( obj = 0; obj < nchan_ism; obj++ ) + { + hOmasaData->energy_ratio_ism[sf][band][obj] = hOmasaData->energy_ratio_ism[sf][nbands_work-1][obj]; + } + } +#endif } } @@ -3664,7 +3709,6 @@ static void ivas_encode_masaism_metadata( /* Quantize ISM ratios */ quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], nchan_ism, hQMetaData->masa_to_total_energy_ratio[sf][band], idx_separated_object ); - if ( n_ism_tmp == numCodingBands && ratio_ism_idx[band][idx_separated_object] != 0 && hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) { i = 0; @@ -3691,6 +3735,7 @@ static void ivas_encode_masaism_metadata( { /* rotate components */ rotate = 1; + for ( band = 0; band < numCodingBands; band++ ) { if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 6be126ac83..9754e4174f 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -6405,7 +6405,8 @@ void ivas_omasa_encode_masa_to_total( BSTR_ENC_HANDLE hMetaData, const int16_t low_bitrate_mode, const int16_t nbands, - const int16_t nblocks ) + const int16_t nblocks +) { int16_t i, j, k; float data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; -- GitLab From ea5e4a39f8675a741379867c2da686cff355adfa Mon Sep 17 00:00:00 2001 From: advasila Date: Wed, 9 Aug 2023 17:48:31 +0300 Subject: [PATCH 3/8] fix FCB ACELP in OMASA --- lib_com/bits_alloc.c | 63 +++++++++++++++++++++++++++++++------------- lib_com/options.h | 2 +- 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index 56e523b392..addfdcbadc 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -394,6 +394,9 @@ static ivas_error acelp_FCB_allocator( int16_t nBits_tmp; int16_t *p_fixed_cdk_index; ivas_error error; +#ifdef FIX_ACELP_TABLE + int16_t max_n; +#endif error = IVAS_ERR_OK; @@ -424,12 +427,31 @@ static ivas_error acelp_FCB_allocator( } /* distribute the bit-budget equally between subframes */ +#ifdef FIX_ACELP_TABLE + if ( L_subfr > L_SUBFR ) /* access fast_FCB_bits_2sfr */ + { + max_n = 6; + } + else + { + max_n = ACELP_FIXED_CDK_NB; + } + for ( cdbk = 0; cdbk < max_n; cdbk++ ) + { + if ( fcb_table( cdbk, L_subfr ) * nb_subfr > *nBits ) + { + break; + } + } + cdbk--; +#else cdbk = 0; while ( fcb_table( cdbk, L_subfr ) * nb_subfr <= *nBits ) { cdbk++; } cdbk--; +#endif #ifdef DEBUGGING if ( cdbk < 0 && coder_type != TRANSITION ) @@ -453,31 +475,36 @@ static ivas_error acelp_FCB_allocator( nBits_tmp = 0; } *nBits -= nBits_tmp * nb_subfr; - - /* try to increase the FCB bit-budget of the first subframe(s) */ - step = fcb_table( cdbk + 1, L_subfr ) - nBits_tmp; - while ( *nBits >= step ) +#ifdef FIX_ACELP_TABLE + if ( cdbk < ACELP_FIXED_CDK_NB - 1 ) { - ( *p_fixed_cdk_index )++; - *nBits -= step; - p_fixed_cdk_index++; - } - - /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ - step = fcb_table( fixed_cdk_index[sfr] + 1, L_subfr ) - fcb_table( fixed_cdk_index[sfr], L_subfr ); - if ( *nBits >= step && cdbk >= 0 ) - { - fixed_cdk_index[sfr]++; - *nBits -= step; +#endif + /* try to increase the FCB bit-budget of the first subframe(s) */ + step = fcb_table( cdbk + 1, L_subfr ) - nBits_tmp; + while ( *nBits >= step ) + { + ( *p_fixed_cdk_index )++; + *nBits -= step; + p_fixed_cdk_index++; + } - if ( *nBits >= step && fixed_cdk_index[sfr + 1] == fixed_cdk_index[sfr] - 1 ) + /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ + step = fcb_table( fixed_cdk_index[sfr] + 1, L_subfr ) - fcb_table( fixed_cdk_index[sfr], L_subfr ); + if ( *nBits >= step && cdbk >= 0 ) { - sfr++; fixed_cdk_index[sfr]++; *nBits -= step; + + if ( *nBits >= step && fixed_cdk_index[sfr + 1] == fixed_cdk_index[sfr] - 1 ) + { + sfr++; + fixed_cdk_index[sfr]++; + *nBits -= step; + } } +#ifdef FIX_ACELP_TABLE } - +#endif /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */ if ( tc_subfr >= L_SUBFR ) { diff --git a/lib_com/options.h b/lib_com/options.h index 141c4f39c9..42ec363ac3 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -217,7 +217,7 @@ #define MASA_AND_OBJECTS /* Nokia: Combination of MASA and objects */ #define FIX_WB_OMASA /* Nokia: fixes OMASA for WB input */ - +#define FIX_ACELP_TABLE /* Nokia: fixes over-indexing in FCB ACELP in OMASA when the separated object is inactive */ /* ################## End BE DEVELOPMENT switches ######################### */ -- GitLab From fdfb89b8e08944759dfa1dbc6b1696c9ed5ad756 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 10 Aug 2023 10:29:31 +0300 Subject: [PATCH 4/8] Fixes rate switching in OMASA JBM. --- lib_com/ivas_prot.h | 12 ++++++ lib_dec/ivas_init_dec.c | 8 +++- lib_dec/ivas_jbm_dec.c | 32 ++++++++++++++++ lib_dec/ivas_masa_dec.c | 83 ++++++++++++++++++++++++++++++++++++++++ lib_dec/ivas_omasa_dec.c | 6 ++- 5 files changed, 137 insertions(+), 4 deletions(-) diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index d5ea0487a7..a74bcbf482 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4963,7 +4963,13 @@ void ivas_masa_enc_reconfigure( ); ivas_error ivas_masa_dec_reconfigure( +#ifdef MASA_AND_OBJECTS + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ + int16_t *data /* o : flushed PCM samples */ +#else Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#endif ); ivas_error ivas_masa_encode( @@ -5655,7 +5661,13 @@ ivas_error ivas_omasa_enc_config( ); ivas_error ivas_omasa_dec_config( +#ifdef MASA_AND_OBJECTS + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ + int16_t *data /* o : flushed PCM samples */ +#else Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#endif ); void ivas_omasa_set_config( diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 73c66b5379..b5b6c7ad9e 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -326,7 +326,11 @@ ivas_error ivas_dec_setup( } else { +#ifdef MASA_AND_OBJECTS + if ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered ,data ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) +#endif { return error; } @@ -335,7 +339,7 @@ ivas_error ivas_dec_setup( } else { - if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_dec_config( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } @@ -358,7 +362,7 @@ ivas_error ivas_dec_setup( /* reconfigure in case a change of operation mode is detected */ if ( ( ivas_total_brate > IVAS_SID_5k2 && ivas_total_brate != st_ivas->hDecoderConfig->last_ivas_total_brate ) || ( st_ivas->ini_active_frame == 0 ) ) { - if ( ( error = ivas_omasa_dec_config( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_omasa_dec_config( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 87d947a21c..b14896757d 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -1319,6 +1319,38 @@ ivas_error ivas_jbm_dec_flush_renderer( return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong MC_MODE in VoIP renderer flushing!" ); } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->ivas_format == MASA_ISM_FORMAT || st_ivas->ivas_format == MASA_FORMAT ) + { + if ( ism_mode_old == ISM_MASA_MODE_DISC ) + { + float *tc_local[MAX_TRANSPORT_CHANNELS]; + + for ( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ ) + { + tc_local[ch_idx] = &st_ivas->hTcBuffer->tc[ch_idx + 2][hTcBuffer->n_samples_rendered]; + mvr2r( st_ivas->hMasaIsmData->delayBuffer[ch_idx], tc_local[ch_idx], st_ivas->hMasaIsmData->delayBuffer_size ); + } + + if ( st_ivas->nchan_ism > 0 ) + { + if ( ( ivas_td_binaural_renderer_sf( st_ivas, p_output, hTcBuffer->n_samples_granularity ) ) != IVAS_ERR_OK ) + { + return error; + } + } + else + { + for ( ch_idx = 0; ch_idx < st_ivas->hDecoderConfig->nchan_out; ch_idx++ ) + { + set_zero( p_output[ch_idx], (int16_t) (*nSamplesRendered) ); + } + st_ivas->hTcBuffer->slots_rendered += 1; + st_ivas->hTcBuffer->subframes_rendered += 1; + } + } + } +#endif else { return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong IVAS format in VoIP renderer flushing!" ); diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index b96ada7789..73bd571053 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1282,7 +1282,13 @@ static int16_t decode_lfe_to_total_energy_ratio( *-------------------------------------------------------------------*/ ivas_error ivas_masa_dec_reconfigure( +#ifdef MASA_AND_OBJECTS + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ + int16_t *data /* o : flushed PCM samples */ +#else Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ +#endif ) { int16_t n, tmp, num_bits; @@ -1304,6 +1310,18 @@ ivas_error ivas_masa_dec_reconfigure( ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate; last_ivas_total_brate = st_ivas->hDecoderConfig->last_ivas_total_brate; +#ifdef MASA_AND_OBJECTS + if ( st_ivas->hDecoderConfig->voip_active == 1 ) + { + if ( st_ivas->hSpatParamRendCom != NULL && st_ivas->hSpatParamRendCom->slot_size == st_ivas->hTcBuffer->n_samples_granularity ) + { + mvs2s( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes; + st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered; + } + } +#endif + ivas_init_dec_get_num_cldfb_instances( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old ); /* renderer might have changed, reselect */ @@ -1323,7 +1341,11 @@ ivas_error ivas_masa_dec_reconfigure( return error; } } +#ifdef MASA_AND_OBJECTS + else if ( st_ivas->renderer_type == RENDERER_DISABLE || st_ivas->renderer_type == RENDERER_MONO_DOWNMIX ) +#else else if ( st_ivas->renderer_type == RENDERER_DISABLE ) +#endif { if ( st_ivas->hDirAC != NULL ) { @@ -1505,23 +1527,84 @@ ivas_error ivas_masa_dec_reconfigure( int16_t tc_nchan_to_allocate; int16_t tc_nchan_transport; TC_BUFFER_MODE buffer_mode_new; +#ifdef MASA_AND_OBJECTS + int16_t n_samples_granularity; + n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); +#endif buffer_mode_new = ivas_jbm_dec_get_tc_buffer_mode( st_ivas ); tc_nchan_transport = ivas_jbm_dec_get_num_tc_channels( st_ivas ); tc_nchan_to_allocate = tc_nchan_transport; if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC ) { +#ifdef MASA_AND_OBJECTS + if ( st_ivas->ivas_format == MASA_ISM_FORMAT ) + { + tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS + 2; + } + else + { + tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS; + } + + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + n_samples_granularity = NS2SA( st_ivas->hDecoderConfig->output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES ); /* Use the same granularity as tdrend */ + + if ( n_samples_granularity > st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_set_discard_samples( st_ivas ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } + else if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode != ISM_MASA_MODE_DISC ) + { + if ( n_samples_granularity < st_ivas->hTcBuffer->n_samples_granularity ) + { + if ( ( error = ivas_jbm_dec_flush_renderer( st_ivas, n_samples_granularity, st_ivas->renderer_type, st_ivas->intern_config, &st_ivas->hIntSetup, MC_MODE_NONE, ISM_MASA_MODE_DISC, nSamplesRendered, data ) ) != IVAS_ERR_OK ) + { + return error; + } + } + } +#else tc_nchan_to_allocate = 2 * BINAURAL_CHANNELS; +#endif } if ( tc_nchan_transport != st_ivas->hTcBuffer->nchan_transport_jbm || tc_nchan_to_allocate != st_ivas->hTcBuffer->nchan_transport_internal || buffer_mode_new != st_ivas->hTcBuffer->tc_buffer_mode ) { +#ifdef MASA_AND_OBJECTS + if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, buffer_mode_new, tc_nchan_transport, tc_nchan_to_allocate, tc_nchan_to_allocate, n_samples_granularity ) ) != IVAS_ERR_OK ) +#else if ( ( error = ivas_jbm_dec_tc_buffer_reconfigure( st_ivas, buffer_mode_new, tc_nchan_transport, tc_nchan_to_allocate, tc_nchan_to_allocate, NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ) != IVAS_ERR_OK ) +#endif { return error; } } + +#ifdef MASA_AND_OBJECTS + if ( st_ivas->hSpatParamRendCom != NULL && st_ivas->hSpatParamRendCom->slot_size == st_ivas->hTcBuffer->n_samples_granularity ) + { + mvs2s( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); + st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes; + st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered; + } + + if ( st_ivas->ivas_format == MASA_ISM_FORMAT && st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) + { + int16_t granularityMultiplier = st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size; + + for ( n = 0; n < MAX_JBM_SUBFRAMES_5MS; n++ ) + { + st_ivas->hSpatParamRendCom->subframe_nbslots[n] = st_ivas->hTcBuffer->subframe_nbslots[n] * granularityMultiplier; + } + } +#endif } return error; diff --git a/lib_dec/ivas_omasa_dec.c b/lib_dec/ivas_omasa_dec.c index 1d52b844ef..b04a44c539 100644 --- a/lib_dec/ivas_omasa_dec.c +++ b/lib_dec/ivas_omasa_dec.c @@ -151,7 +151,9 @@ void ivas_omasa_data_close( *--------------------------------------------------------------------------*/ ivas_error ivas_omasa_dec_config( - Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */ + Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */ + uint16_t *nSamplesRendered, /* o : number of samples flushed from the previous frame (JBM) */ + int16_t *data /* o : flushed PCM samples */ ) { int16_t k, sce_id, nSCE_old, nchan_hp20_old, numCldfbAnalyses_old, numCldfbSyntheses_old, n_MD; @@ -192,7 +194,7 @@ ivas_error ivas_omasa_dec_config( { st_ivas->hCPE[0]->nchan_out = 1; } - else if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + else if ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From 27df9a6ce10aad42188b98d3de59d03c00626165 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Thu, 10 Aug 2023 10:20:59 +0200 Subject: [PATCH 5/8] clang format fixes --- lib_dec/ivas_init_dec.c | 4 ++-- lib_dec/ivas_jbm_dec.c | 4 ++-- lib_enc/ivas_masa_enc.c | 16 ++++++++-------- lib_enc/ivas_qmetadata_enc.c | 3 +-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index b5b6c7ad9e..9396b0e427 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -327,9 +327,9 @@ ivas_error ivas_dec_setup( else { #ifdef MASA_AND_OBJECTS - if ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered ,data ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_masa_dec_reconfigure( st_ivas, nSamplesRendered, data ) ) != IVAS_ERR_OK ) #else - if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) + if ( ( error = ivas_masa_dec_reconfigure( st_ivas ) ) != IVAS_ERR_OK ) #endif { return error; diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index b14896757d..95be3d8703 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -728,7 +728,7 @@ ivas_error ivas_jbm_dec_feed_tc_to_renderer( { if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC && st_ivas->ism_mode == ISM_MASA_MODE_DISC ) { - n_render_timeslots *= (st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size); + n_render_timeslots *= ( st_ivas->hTcBuffer->n_samples_granularity / st_ivas->hSpatParamRendCom->slot_size ); } ivas_sba_dec_digest_tc( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available ); @@ -1343,7 +1343,7 @@ ivas_error ivas_jbm_dec_flush_renderer( { for ( ch_idx = 0; ch_idx < st_ivas->hDecoderConfig->nchan_out; ch_idx++ ) { - set_zero( p_output[ch_idx], (int16_t) (*nSamplesRendered) ); + set_zero( p_output[ch_idx], (int16_t) ( *nSamplesRendered ) ); } st_ivas->hTcBuffer->slots_rendered += 1; st_ivas->hTcBuffer->subframes_rendered += 1; diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index e7dc93d13d..a43fad2bdd 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -3527,9 +3527,9 @@ static void ivas_encode_masaism_metadata( int16_t tmp, rotate; int16_t n_ism_tmp, i; OMASA_ENCODER_DATA_HANDLE hOmasaData = hMasa->data.hOmasaData; - #ifdef FIX_WB_OMASA +#ifdef FIX_WB_OMASA int16_t nbands_work; - #endif +#endif /* use the values from hQMetaData */ numCodingBands = (uint8_t) hQMetaData->q_direction->cfg.nbands; @@ -3584,7 +3584,7 @@ static void ivas_encode_masaism_metadata( } } #ifdef FIX_WB_OMASA - else if (numSf == 1) + else if ( numSf == 1 ) #else else if ( numSf != omasa_nblocks ) #endif @@ -3641,11 +3641,11 @@ static void ivas_encode_masaism_metadata( for ( band = nbands_work; band < numCodingBands; band++ ) { hQMetaData->masa_to_total_energy_ratio[0][band] = 1.0f; - + for ( obj = 0; obj < nchan_ism; obj++ ) { - hOmasaData->energy_ratio_ism[0][band][obj] = hOmasaData->energy_ratio_ism[0][nbands_work-1][obj]; - } + hOmasaData->energy_ratio_ism[0][band][obj] = hOmasaData->energy_ratio_ism[0][nbands_work - 1][obj]; + } } #endif } @@ -3677,14 +3677,14 @@ static void ivas_encode_masaism_metadata( } } - #ifdef FIX_WB_OMASA +#ifdef FIX_WB_OMASA for ( band = nbands_work; band < numCodingBands; band++ ) { hQMetaData->masa_to_total_energy_ratio[sf][band] = 1.0f; for ( obj = 0; obj < nchan_ism; obj++ ) { - hOmasaData->energy_ratio_ism[sf][band][obj] = hOmasaData->energy_ratio_ism[sf][nbands_work-1][obj]; + hOmasaData->energy_ratio_ism[sf][band][obj] = hOmasaData->energy_ratio_ism[sf][nbands_work - 1][obj]; } } #endif diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 9754e4174f..6be126ac83 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -6405,8 +6405,7 @@ void ivas_omasa_encode_masa_to_total( BSTR_ENC_HANDLE hMetaData, const int16_t low_bitrate_mode, const int16_t nbands, - const int16_t nblocks -) + const int16_t nblocks ) { int16_t i, j, k; float data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; -- GitLab From 0c0c9fd18379a6e1cb0262be90107bc6fbd5496f Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Thu, 10 Aug 2023 11:08:05 +0200 Subject: [PATCH 6/8] remove code changes under switches FIX_WB_OMASA and FIX_ACELP_TABLE: these will be provided separately. --- lib_com/bits_alloc.c | 62 +++++++++++------------------------------ lib_com/options.h | 3 -- lib_enc/ivas_masa_enc.c | 48 ------------------------------- 3 files changed, 17 insertions(+), 96 deletions(-) diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index addfdcbadc..5b41e37862 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -394,9 +394,6 @@ static ivas_error acelp_FCB_allocator( int16_t nBits_tmp; int16_t *p_fixed_cdk_index; ivas_error error; -#ifdef FIX_ACELP_TABLE - int16_t max_n; -#endif error = IVAS_ERR_OK; @@ -427,31 +424,12 @@ static ivas_error acelp_FCB_allocator( } /* distribute the bit-budget equally between subframes */ -#ifdef FIX_ACELP_TABLE - if ( L_subfr > L_SUBFR ) /* access fast_FCB_bits_2sfr */ - { - max_n = 6; - } - else - { - max_n = ACELP_FIXED_CDK_NB; - } - for ( cdbk = 0; cdbk < max_n; cdbk++ ) - { - if ( fcb_table( cdbk, L_subfr ) * nb_subfr > *nBits ) - { - break; - } - } - cdbk--; -#else cdbk = 0; while ( fcb_table( cdbk, L_subfr ) * nb_subfr <= *nBits ) { cdbk++; } cdbk--; -#endif #ifdef DEBUGGING if ( cdbk < 0 && coder_type != TRANSITION ) @@ -475,36 +453,30 @@ static ivas_error acelp_FCB_allocator( nBits_tmp = 0; } *nBits -= nBits_tmp * nb_subfr; -#ifdef FIX_ACELP_TABLE - if ( cdbk < ACELP_FIXED_CDK_NB - 1 ) + /* try to increase the FCB bit-budget of the first subframe(s) */ + step = fcb_table( cdbk + 1, L_subfr ) - nBits_tmp; + while ( *nBits >= step ) { -#endif - /* try to increase the FCB bit-budget of the first subframe(s) */ - step = fcb_table( cdbk + 1, L_subfr ) - nBits_tmp; - while ( *nBits >= step ) - { - ( *p_fixed_cdk_index )++; - *nBits -= step; - p_fixed_cdk_index++; - } + ( *p_fixed_cdk_index )++; + *nBits -= step; + p_fixed_cdk_index++; + } - /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ - step = fcb_table( fixed_cdk_index[sfr] + 1, L_subfr ) - fcb_table( fixed_cdk_index[sfr], L_subfr ); - if ( *nBits >= step && cdbk >= 0 ) + /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ + step = fcb_table( fixed_cdk_index[sfr] + 1, L_subfr ) - fcb_table( fixed_cdk_index[sfr], L_subfr ); + if ( *nBits >= step && cdbk >= 0 ) + { + fixed_cdk_index[sfr]++; + *nBits -= step; + + if ( *nBits >= step && fixed_cdk_index[sfr + 1] == fixed_cdk_index[sfr] - 1 ) { + sfr++; fixed_cdk_index[sfr]++; *nBits -= step; - - if ( *nBits >= step && fixed_cdk_index[sfr + 1] == fixed_cdk_index[sfr] - 1 ) - { - sfr++; - fixed_cdk_index[sfr]++; - *nBits -= step; - } } -#ifdef FIX_ACELP_TABLE } -#endif + /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */ if ( tc_subfr >= L_SUBFR ) { diff --git a/lib_com/options.h b/lib_com/options.h index 2c10ee249e..bbeae143d5 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -230,9 +230,6 @@ #define FIX_663_PARAM_ISM_EXT /* FhG: Issue 663: ParamISM EXT output improvement */ #define FIX_673_OMASA_OBJ_MD_SYNC /* Nokia: Fix issue 673 by updating metadata in the third subframe to account for audio delay. */ -#define FIX_WB_OMASA /* Nokia: fixes OMASA for WB input */ -#define FIX_ACELP_TABLE /* Nokia: fixes over-indexing in FCB ACELP in OMASA when the separated object is inactive */ - /* ################## End BE DEVELOPMENT switches ######################### */ /* #################### Start NON-BE CR switches ########################## */ diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index a43fad2bdd..c6927388f1 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -3527,23 +3527,13 @@ static void ivas_encode_masaism_metadata( int16_t tmp, rotate; int16_t n_ism_tmp, i; OMASA_ENCODER_DATA_HANDLE hOmasaData = hMasa->data.hOmasaData; -#ifdef FIX_WB_OMASA - int16_t nbands_work; -#endif /* use the values from hQMetaData */ numCodingBands = (uint8_t) hQMetaData->q_direction->cfg.nbands; numSf = (int8_t) hQMetaData->q_direction->cfg.nblocks; -#ifdef FIX_WB_OMASA - nbands_work = min( numCodingBands, omasa_nbands ); - if ( numCodingBands == 1 ) -#else if ( numCodingBands != omasa_nbands ) -#endif { -#ifndef FIX_WB_OMASA assert( numCodingBands == 1 ); -#endif for ( sf = 0; sf < numSf; sf++ ) { if ( sum_f( hOmasaData->energy_ism[sf], omasa_nbands ) == 0.0f ) @@ -3583,20 +3573,10 @@ static void ivas_encode_masaism_metadata( } } } -#ifdef FIX_WB_OMASA - else if ( numSf == 1 ) -#else else if ( numSf != omasa_nblocks ) -#endif { -#ifndef FIX_WB_OMASA assert( numSf == 1 ); -#endif -#ifdef FIX_WB_OMASA - for ( band = 0; band < nbands_work; band++ ) -#else for ( band = 0; band < numCodingBands; band++ ) -#endif { energy_ism = 0.0f; /* ISM energy for current subband */ for ( obj = 0; obj < nchan_ism; obj++ ) @@ -3636,28 +3616,12 @@ static void ivas_encode_masaism_metadata( hQMetaData->masa_to_total_energy_ratio[0][band] = eneBand / ( eneBand + energy_ism + EPSILON ); } } - -#ifdef FIX_WB_OMASA - for ( band = nbands_work; band < numCodingBands; band++ ) - { - hQMetaData->masa_to_total_energy_ratio[0][band] = 1.0f; - - for ( obj = 0; obj < nchan_ism; obj++ ) - { - hOmasaData->energy_ratio_ism[0][band][obj] = hOmasaData->energy_ratio_ism[0][nbands_work - 1][obj]; - } - } -#endif } else { for ( sf = 0; sf < numSf; sf++ ) { -#ifdef FIX_WB_OMASA - for ( band = 0; band < nbands_work; band++ ) -#else for ( band = 0; band < numCodingBands; band++ ) -#endif { if ( hOmasaData->energy_ism[sf][band] == 0.0f ) { @@ -3676,18 +3640,6 @@ static void ivas_encode_masaism_metadata( hQMetaData->masa_to_total_energy_ratio[sf][band] = eneBand / ( eneBand + hOmasaData->energy_ism[sf][band] + EPSILON ); } } - -#ifdef FIX_WB_OMASA - for ( band = nbands_work; band < numCodingBands; band++ ) - { - hQMetaData->masa_to_total_energy_ratio[sf][band] = 1.0f; - - for ( obj = 0; obj < nchan_ism; obj++ ) - { - hOmasaData->energy_ratio_ism[sf][band][obj] = hOmasaData->energy_ratio_ism[sf][nbands_work - 1][obj]; - } - } -#endif } } -- GitLab From 0ff4eeaca62a079dadabb281f3c72a8f89ba7624 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 10 Aug 2023 09:18:23 +0000 Subject: [PATCH 7/8] Remove whitespace changes to reduce unnecessary code difference. --- lib_com/bits_alloc.c | 1 + lib_com/options.h | 3 ++- lib_enc/ivas_masa_enc.c | 5 ++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index 5b41e37862..56e523b392 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -453,6 +453,7 @@ static ivas_error acelp_FCB_allocator( nBits_tmp = 0; } *nBits -= nBits_tmp * nb_subfr; + /* try to increase the FCB bit-budget of the first subframe(s) */ step = fcb_table( cdbk + 1, L_subfr ) - nBits_tmp; while ( *nBits >= step ) diff --git a/lib_com/options.h b/lib_com/options.h index bbeae143d5..4b7274c878 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -152,7 +152,7 @@ #define CONTROL_METADATA_REVERB /* Philips: reverb configuration change to binary format */ #ifdef CONTROL_METADATA_REVERB #define EARLY_REFLECTIONS /* Philips/Qualcomm: early reflections extension to reverb configuration */ -#define CONTROL_METADATA_DIRECTIVITY /* Ericsson: Directivity renderer configuration */ +#define CONTROL_METADATA_DIRECTIVITY /* Ericsson: Directivity renderer configuration */ #endif #define VLBR_20MS_MD /* Dlb: SBA VLBR 20ms Optimization*/ #define SBA_MODE_CLEANUP_2 /* Dlb : changes part of fix issue #523 for unused signaling bit in SBA SID*/ @@ -230,6 +230,7 @@ #define FIX_663_PARAM_ISM_EXT /* FhG: Issue 663: ParamISM EXT output improvement */ #define FIX_673_OMASA_OBJ_MD_SYNC /* Nokia: Fix issue 673 by updating metadata in the third subframe to account for audio delay. */ + /* ################## End BE DEVELOPMENT switches ######################### */ /* #################### Start NON-BE CR switches ########################## */ diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index c6927388f1..461a43f80e 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -3531,9 +3531,11 @@ static void ivas_encode_masaism_metadata( /* use the values from hQMetaData */ numCodingBands = (uint8_t) hQMetaData->q_direction->cfg.nbands; numSf = (int8_t) hQMetaData->q_direction->cfg.nblocks; + if ( numCodingBands != omasa_nbands ) { assert( numCodingBands == 1 ); + for ( sf = 0; sf < numSf; sf++ ) { if ( sum_f( hOmasaData->energy_ism[sf], omasa_nbands ) == 0.0f ) @@ -3576,6 +3578,7 @@ static void ivas_encode_masaism_metadata( else if ( numSf != omasa_nblocks ) { assert( numSf == 1 ); + for ( band = 0; band < numCodingBands; band++ ) { energy_ism = 0.0f; /* ISM energy for current subband */ @@ -3666,6 +3669,7 @@ static void ivas_encode_masaism_metadata( /* Quantize ISM ratios */ quantize_ratio_ism_vector( ratio_ism[band], ratio_ism_idx[band], nchan_ism, hQMetaData->masa_to_total_energy_ratio[sf][band], idx_separated_object ); + if ( n_ism_tmp == numCodingBands && ratio_ism_idx[band][idx_separated_object] != 0 && hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) { i = 0; @@ -3692,7 +3696,6 @@ static void ivas_encode_masaism_metadata( { /* rotate components */ rotate = 1; - for ( band = 0; band < numCodingBands; band++ ) { if ( hQMetaData->masa_to_total_energy_ratio[sf][band] < MASA2TOTAL_THR ) -- GitLab From c8c9fecd2e8afd392e0e11e352db2646596521fc Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 10 Aug 2023 20:21:10 +0300 Subject: [PATCH 8/8] Add missing merge fix --- lib_dec/ivas_jbm_dec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_dec/ivas_jbm_dec.c b/lib_dec/ivas_jbm_dec.c index 875b981aaf..55af4b5905 100644 --- a/lib_dec/ivas_jbm_dec.c +++ b/lib_dec/ivas_jbm_dec.c @@ -408,8 +408,10 @@ ivas_error ivas_jbm_dec_tc( ivas_mono_downmix_render_passive( st_ivas, output, output_frame ); } +#ifndef FIX_657_REMOVE_EDITING /* Set edited object positions, if editing enabled */ ivas_omasa_set_edited_objects( st_ivas ); +#endif } #endif else if ( st_ivas->ivas_format == MC_FORMAT ) -- GitLab