From 5025ccf806cfa376c90fff55bdf2f2ef739c4cff Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 24 Oct 2025 16:10:21 +0300 Subject: [PATCH 1/2] Port float MR 2246 to BASOP main --- lib_com/options.h | 1 + lib_rend/ivas_dirac_ana_fx.c | 24 +++++++++++------ lib_rend/ivas_masa_merge_fx.c | 26 ++++++++++++++++++ lib_rend/ivas_mcmasa_ana_fx.c | 50 +++++++++++++++++++++++++++++++++++ lib_rend/ivas_omasa_ana_fx.c | 8 ++++++ lib_rend/ivas_prot_rend_fx.h | 11 ++++++++ lib_rend/ivas_stat_rend.h | 5 ++++ lib_rend/lib_rend_fx.c | 11 ++++++++ 8 files changed, 128 insertions(+), 8 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 0e364d2b8..741833851 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -117,6 +117,7 @@ #define FIX_RENDERER_STACK /* VA: issue 1322: reduction of renderers' buffers size */ #define FIX_1370_EXTERNAL_ORIENTATION_CHECK /* Nokia: add sanity check for Euler angles for external orientations */ #define NONBE_FIX_1197_OMASA_META_BUFFER /* Nokia: OMASA ISM_MASA_MODE_PARAM_ONE_OBJ history zero in rateswitching - port 251 */ +#define NONBE_1344_REND_MASA_LOW_FS /* Nokia: Issue 1344: Fix sanitizer errors when using IVAS_rend to render MASA with lower sampling rates */ // object-editing feature porting #define TMP_FIX_SPLIT_REND // temporary fix to split-rendering (it follows the later state of the framework but it is needed now because of current test-conditions) diff --git a/lib_rend/ivas_dirac_ana_fx.c b/lib_rend/ivas_dirac_ana_fx.c index 502f4f5ae..37150a6da 100644 --- a/lib_rend/ivas_dirac_ana_fx.c +++ b/lib_rend/ivas_dirac_ana_fx.c @@ -250,16 +250,24 @@ void ivas_dirac_ana_fx( const Word16 nchan_transport, /* i : Number of transport channels */ const Word16 data_q ) { - Word32 elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 energyRatio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; - Word32 surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; + Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS]; /* Estimate MASA parameters from the SBA signals */ - ivas_dirac_param_est_ana_fx( hDirAC, data_fx, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, input_frame, data_q ); - /* Create MASA metadata buffer from the estimated values */ + ivas_dirac_param_est_ana_fx( hDirAC, data_fx, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, input_frame, data_q ); - ivas_create_masa_out_meta_fx( hDirAC->hMasaOut, hDirAC->sph_grid16, nchan_transport, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, Q31, Q31, Q31 ); +#ifdef NONBE_1344_REND_MASA_LOW_FS + /* Add zeros to higher bands in case of lower sampling rates */ + IF( LT_16( hDirAC->nbands, MASA_FREQUENCY_BANDS ) ) + { + ivas_masa_zero_high_bands_fx( hDirAC->nbands, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx ); + } +#endif + + /* Create MASA metadata buffer from the estimated values */ + ivas_create_masa_out_meta_fx( hDirAC->hMasaOut, hDirAC->sph_grid16, nchan_transport, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, Q31, Q31, Q31 ); /* Downmix */ ivas_dirac_dmx_fx( data_fx, input_frame, nchan_transport ); // output Q of data_fx is same as that of input diff --git a/lib_rend/ivas_masa_merge_fx.c b/lib_rend/ivas_masa_merge_fx.c index 432ed8253..94e0325ae 100644 --- a/lib_rend/ivas_masa_merge_fx.c +++ b/lib_rend/ivas_masa_merge_fx.c @@ -37,6 +37,9 @@ #include "ivas_cnst.h" #include "prot_fx.h" #include "wmc_auto.h" +#ifdef NONBE_1344_REND_MASA_LOW_FS +#include "ivas_rom_com.h" +#endif #include "ivas_prot_fx.h" #define INV_UINT8_MAX 8421505 /* 1/UINT8_MAX in Q31 */ @@ -487,6 +490,9 @@ ivas_error masaPrerendOpen_fx( { MASA_PREREND_HANDLE hMasaPrerend; Word16 i; +#ifdef NONBE_1344_REND_MASA_LOW_FS + Word16 maxBin; +#endif ivas_error error; error = IVAS_ERR_OK; @@ -498,6 +504,26 @@ ivas_error masaPrerendOpen_fx( return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MASA prerenderer\n" ) ); } +#ifdef NONBE_1344_REND_MASA_LOW_FS + /* Determine the number of bands and band grouping */ + hMasaPrerend->nbands = MASA_FREQUENCY_BANDS; + move16(); + mvs2s( MASA_band_grouping_24, hMasaPrerend->band_grouping, MASA_FREQUENCY_BANDS + 1 ); + + maxBin = extract_l( Mpy_32_32( input_Fs, INV_CLDFB_BANDWIDTH_Q31 ) ); /* Q0 */ + FOR( i = 1; i < hMasaPrerend->nbands + 1; i++ ) + { + IF( GE_16(hMasaPrerend->band_grouping[i], maxBin) ) + { + hMasaPrerend->band_grouping[i] = maxBin; + move16(); + hMasaPrerend->nbands = i; + move16(); + break; + } + } +#endif + hMasaPrerend->num_Cldfb_instances = numTransports; move16(); FOR( i = 0; i < hMasaPrerend->num_Cldfb_instances; i++ ) diff --git a/lib_rend/ivas_mcmasa_ana_fx.c b/lib_rend/ivas_mcmasa_ana_fx.c index dbaf5b7d9..c4c271dcb 100644 --- a/lib_rend/ivas_mcmasa_ana_fx.c +++ b/lib_rend/ivas_mcmasa_ana_fx.c @@ -486,6 +486,14 @@ void ivas_mcmasa_ana_fx( /* Analysis */ ivas_mcmasa_param_est_ana_fx( hMcMasa, data, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, q_data, input_frame, nchan_inp ); +#ifdef NONBE_1344_REND_MASA_LOW_FS + /* Add zeros to higher bands in case of lower sampling rates */ + IF( LT_16( hMcMasa->nbands, MASA_FREQUENCY_BANDS ) ) + { + ivas_masa_zero_high_bands_fx( hMcMasa->nbands, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx ); + } +#endif + /* Create MASA metadata buffer from the estimated values */ ivas_create_masa_out_meta_fx( hMcMasa->hMasaOut, hMcMasa->sph_grid16, nchan_transport, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, Q31, Q31, Q31 ); @@ -1703,3 +1711,45 @@ void ivas_create_masa_out_meta_fx( return; } + + + + +#ifdef NONBE_1344_REND_MASA_LOW_FS +/*------------------------------------------------------------------------- + * ivas_masa_zero_high_bands() + * + * + *------------------------------------------------------------------------*/ + +void ivas_masa_zero_high_bands_fx( + const Word16 nbands, /* i : Number of frequency bands with estimated values */ + Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated elevation */ + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated azimuth */ + Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated direct-to-total ratio */ + Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated spread coherence */ + Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] /* i/o : Estimated surround coherence */ +) +{ + Word16 sf, band; + + FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + FOR( band = nbands; band < MASA_FREQUENCY_BANDS; band++ ) + { + elevation_m_values_fx[sf][band] = 0; + move32(); + azimuth_m_values_fx[sf][band] = 0; + move32(); + energyRatio_fx[sf][band] = 0; + move32(); + spreadCoherence_fx[sf][band] = 0; + move32(); + surroundingCoherence_fx[sf][band] = 0; + move32(); + } + } + + return; +} +#endif diff --git a/lib_rend/ivas_omasa_ana_fx.c b/lib_rend/ivas_omasa_ana_fx.c index e441b3596..898264c8f 100644 --- a/lib_rend/ivas_omasa_ana_fx.c +++ b/lib_rend/ivas_omasa_ana_fx.c @@ -318,6 +318,14 @@ void ivas_omasa_ana_fx( /* Estimate MASA parameters from the objects */ ivas_omasa_param_est_ana_fx( hOMasa, data_in_f_fx, *data_in_q, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, &energyRatio_q, spreadCoherence_fx, &spreadCoherence_q, surroundingCoherence_fx, &sorroundingCoherence_q, input_frame, nchan_ism ); +#ifdef NONBE_1344_REND_MASA_LOW_FS + /* Add zeros to higher bands in case of lower sampling rates */ + IF( LT_16( hOMasa->nbands, MASA_FREQUENCY_BANDS ) ) + { + ivas_masa_zero_high_bands_fx( hOMasa->nbands, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx ); + } +#endif + /* Create MASA metadata buffer from the estimated values */ ivas_create_masa_out_meta_fx( hOMasa->hMasaOut, hOMasa->sph_grid16, nchan_transport, elevation_m_values_fx, azimuth_m_values_fx, energyRatio_fx, spreadCoherence_fx, surroundingCoherence_fx, Q31, Q31, Q31 ); diff --git a/lib_rend/ivas_prot_rend_fx.h b/lib_rend/ivas_prot_rend_fx.h index 250fea751..964977239 100644 --- a/lib_rend/ivas_prot_rend_fx.h +++ b/lib_rend/ivas_prot_rend_fx.h @@ -1489,6 +1489,17 @@ void ivas_create_masa_out_meta_fx( Word16 surroundingCoherence_q ); +#ifdef NONBE_1344_REND_MASA_LOW_FS +void ivas_masa_zero_high_bands_fx( + const Word16 nbands, /* i : Number of frequency bands with estimated values */ + Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated elevation */ + Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated azimuth */ + Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated direct-to-total ratio */ + Word32 spreadCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated spread coherence */ + Word32 surroundingCoherence_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] /* i/o : Estimated surround coherence */ +); +#endif + ivas_error ivas_dirac_ana_open_fx( DIRAC_ANA_HANDLE *hDirACPtr, /* i/o: DIRAC data handle pointer */ Word32 input_Fs diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index aec8eb3b9..f62bee930 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1681,6 +1681,11 @@ typedef struct ivas_dirac_ana_data_structure typedef struct ivas_masa_prerend_data_structure { +#ifdef NONBE_1344_REND_MASA_LOW_FS + Word16 nbands; + Word16 band_grouping[MASA_FREQUENCY_BANDS + 1]; +#endif + /* CLDFB analysis */ Word16 num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MASA_MAX_TRANSPORT_CHANNELS]; diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index 5827cc275..ad12c9e9f 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -8193,12 +8193,23 @@ static void renderMasaToMasa( Word16 q_add = sub( 31, add( scale_factor, q_cldfb_out ) ); /* Compute channel energy for metadata processing */ +#ifdef NONBE_1344_REND_MASA_LOW_FS + FOR( band_m_idx = 0; band_m_idx < masaInput->hMasaPrerend->nbands; band_m_idx++ ) +#else FOR( band_m_idx = 0; band_m_idx < MASA_FREQUENCY_BANDS; band_m_idx++ ) +#endif { +#ifdef NONBE_1344_REND_MASA_LOW_FS + brange[0] = masaInput->hMasaPrerend->band_grouping[band_m_idx]; + move16(); + brange[1] = masaInput->hMasaPrerend->band_grouping[band_m_idx + 1]; + move16(); +#else brange[0] = MASA_band_grouping_24[band_m_idx]; move16(); brange[1] = MASA_band_grouping_24[band_m_idx + 1]; move16(); +#endif FOR( j = brange[0]; j < brange[1]; j++ ) { FOR( i = 0; i < numAnalysisChannels; i++ ) -- GitLab From 0b8c606b400ec77882b7e3d6354507724471a654 Mon Sep 17 00:00:00 2001 From: lintervo Date: Wed, 5 Nov 2025 13:53:57 +0200 Subject: [PATCH 2/2] Clang format --- lib_rend/ivas_masa_merge_fx.c | 2 +- lib_rend/ivas_mcmasa_ana_fx.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib_rend/ivas_masa_merge_fx.c b/lib_rend/ivas_masa_merge_fx.c index 94e0325ae..144953e26 100644 --- a/lib_rend/ivas_masa_merge_fx.c +++ b/lib_rend/ivas_masa_merge_fx.c @@ -513,7 +513,7 @@ ivas_error masaPrerendOpen_fx( maxBin = extract_l( Mpy_32_32( input_Fs, INV_CLDFB_BANDWIDTH_Q31 ) ); /* Q0 */ FOR( i = 1; i < hMasaPrerend->nbands + 1; i++ ) { - IF( GE_16(hMasaPrerend->band_grouping[i], maxBin) ) + IF( GE_16( hMasaPrerend->band_grouping[i], maxBin ) ) { hMasaPrerend->band_grouping[i] = maxBin; move16(); diff --git a/lib_rend/ivas_mcmasa_ana_fx.c b/lib_rend/ivas_mcmasa_ana_fx.c index 6071f2031..2f607a7b3 100644 --- a/lib_rend/ivas_mcmasa_ana_fx.c +++ b/lib_rend/ivas_mcmasa_ana_fx.c @@ -1713,8 +1713,6 @@ void ivas_create_masa_out_meta_fx( } - - #ifdef NONBE_1344_REND_MASA_LOW_FS /*------------------------------------------------------------------------- * ivas_masa_zero_high_bands() @@ -1723,7 +1721,7 @@ void ivas_create_masa_out_meta_fx( *------------------------------------------------------------------------*/ void ivas_masa_zero_high_bands_fx( - const Word16 nbands, /* i : Number of frequency bands with estimated values */ + const Word16 nbands, /* i : Number of frequency bands with estimated values */ Word32 elevation_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated elevation */ Word32 azimuth_m_values_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated azimuth */ Word32 energyRatio_fx[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated direct-to-total ratio */ -- GitLab