From 2ae1d602f5486eb72eeb70b8e375b714bad24936 Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 19 Sep 2025 10:38:44 +0300 Subject: [PATCH 1/2] Fixes issue 1344. --- lib_com/options.h | 1 + lib_rend/ivas_dirac_ana.c | 8 +++++++ lib_rend/ivas_masa_merge.c | 23 ++++++++++++++++++++ lib_rend/ivas_mcmasa_ana.c | 43 ++++++++++++++++++++++++++++++++++++++ lib_rend/ivas_omasa_ana.c | 8 +++++++ lib_rend/ivas_prot_rend.h | 11 ++++++++++ lib_rend/ivas_stat_rend.h | 5 +++++ lib_rend/lib_rend.c | 9 ++++++++ 8 files changed, 108 insertions(+) diff --git a/lib_com/options.h b/lib_com/options.h index 8b761e69b2..caa8210e61 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -176,6 +176,7 @@ #define NONBE_1244_FIX_SWB_BWE_MEMORY /* VA: issue 1244: fix to SWB BWE memory in case of switching from FB coding - pending a review by Huawei */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define NONBE_1328_FIX_NON_LINEARITY /* VA: Fix possible issue when computing bwe_exc_extended and previous frame were almost 0 */ +#define NONBE_1344_REND_MASA_LOW_FS /* Nokia: Issue 1344: Fix sanitizer errors when using IVAS_rend to render MASA with lower sampling rates */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_rend/ivas_dirac_ana.c b/lib_rend/ivas_dirac_ana.c index f6273106de..973182504a 100644 --- a/lib_rend/ivas_dirac_ana.c +++ b/lib_rend/ivas_dirac_ana.c @@ -235,6 +235,14 @@ void ivas_dirac_ana( /* Estimate MASA parameters from the SBA signals */ ivas_dirac_param_est_ana( hDirAC, data_in_f, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, input_frame ); +#ifdef NONBE_1344_REND_MASA_LOW_FS + /* Add zeros to higher bands in case of lower sampling rates */ + if ( hDirAC->nbands < MASA_FREQUENCY_BANDS ) + { + ivas_masa_zero_high_bands( hDirAC->nbands, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence ); + } +#endif + /* Create MASA metadata buffer from the estimated values */ ivas_create_masa_out_meta( hDirAC->hMasaOut, hDirAC->sph_grid16, nchan_transport, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence ); diff --git a/lib_rend/ivas_masa_merge.c b/lib_rend/ivas_masa_merge.c index 37ee8cc7ef..cd5af80ff1 100644 --- a/lib_rend/ivas_masa_merge.c +++ b/lib_rend/ivas_masa_merge.c @@ -37,6 +37,9 @@ #include "ivas_prot.h" #include "ivas_cnst.h" #include "prot.h" +#ifdef NONBE_1344_REND_MASA_LOW_FS +#include "ivas_rom_com.h" +#endif #include "wmc_auto.h" @@ -326,6 +329,9 @@ ivas_error masaPrerendOpen( { MASA_PREREND_HANDLE hMasaPrerend; int16_t i; +#ifdef NONBE_1344_REND_MASA_LOW_FS + int16_t maxBin; +#endif ivas_error error; error = IVAS_ERR_OK; @@ -336,6 +342,23 @@ ivas_error masaPrerendOpen( 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; + mvs2s( MASA_band_grouping_24, hMasaPrerend->band_grouping, 24 + 1 ); + + maxBin = (int16_t) ( input_Fs * INV_CLDFB_BANDWIDTH + 0.5f ); + for ( i = 1; i < hMasaPrerend->nbands + 1; i++ ) + { + if ( hMasaPrerend->band_grouping[i] >= maxBin ) + { + hMasaPrerend->band_grouping[i] = maxBin; + hMasaPrerend->nbands = i; + break; + } + } +#endif + hMasaPrerend->num_Cldfb_instances = numTransports; for ( i = 0; i < hMasaPrerend->num_Cldfb_instances; i++ ) { diff --git a/lib_rend/ivas_mcmasa_ana.c b/lib_rend/ivas_mcmasa_ana.c index 7851921030..6dec9feaa1 100644 --- a/lib_rend/ivas_mcmasa_ana.c +++ b/lib_rend/ivas_mcmasa_ana.c @@ -393,6 +393,14 @@ void ivas_mcmasa_ana( /* Analysis */ ivas_mcmasa_param_est_ana( hMcMasa, data_f, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, input_frame, nchan_inp ); +#ifdef NONBE_1344_REND_MASA_LOW_FS + /* Add zeros to higher bands in case of lower sampling rates */ + if ( hMcMasa->nbands < MASA_FREQUENCY_BANDS ) + { + ivas_masa_zero_high_bands( hMcMasa->nbands, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence ); + } +#endif + /* Create MASA metadata buffer from the estimated values */ ivas_create_masa_out_meta( hMcMasa->hMasaOut, hMcMasa->sph_grid16, nchan_transport, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence ); @@ -1131,3 +1139,38 @@ void ivas_create_masa_out_meta( return; } + + +#ifdef NONBE_1344_REND_MASA_LOW_FS +/*------------------------------------------------------------------------- + * ivas_masa_zero_high_bands() + * + * + *------------------------------------------------------------------------*/ + +void ivas_masa_zero_high_bands( + const int16_t nbands, /* i : Number of frequency bands with estimated values */ + float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated elevation */ + float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated azimuth */ + float energyRatio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated direct-to-total ratio */ + float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated spread coherence */ + float surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] /* i/o : Estimated surround coherence */ +) +{ + int16_t sf, band; + + for (sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++) + { + for ( band = nbands; band < MASA_FREQUENCY_BANDS; band++ ) + { + elevation_m_values[sf][band] = 0.0f; + azimuth_m_values[sf][band] = 0.0f; + energyRatio[sf][band] = 0.0f; + spreadCoherence[sf][band] = 0.0f; + surroundingCoherence[sf][band] = 0.0f; + } + } + + return; +} +#endif diff --git a/lib_rend/ivas_omasa_ana.c b/lib_rend/ivas_omasa_ana.c index e7f58262ed..566099d5b7 100644 --- a/lib_rend/ivas_omasa_ana.c +++ b/lib_rend/ivas_omasa_ana.c @@ -261,6 +261,14 @@ void ivas_omasa_ana( /* Estimate MASA parameters from the objects */ ivas_omasa_param_est_ana( hOMasa, data_in_f, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence, input_frame, nchan_ism ); +#ifdef NONBE_1344_REND_MASA_LOW_FS + /* Add zeros to higher bands in case of lower sampling rates */ + if ( hOMasa->nbands < MASA_FREQUENCY_BANDS ) + { + ivas_masa_zero_high_bands( hOMasa->nbands, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence ); + } +#endif + /* Create MASA metadata buffer from the estimated values */ ivas_create_masa_out_meta( hOMasa->hMasaOut, hOMasa->sph_grid16, nchan_transport, elevation_m_values, azimuth_m_values, energyRatio, spreadCoherence, surroundingCoherence ); diff --git a/lib_rend/ivas_prot_rend.h b/lib_rend/ivas_prot_rend.h index 51a1da9933..cca2f34dc6 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1476,6 +1476,17 @@ void ivas_create_masa_out_meta( float surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] /* i : Estimated surround coherence */ ); +#ifdef NONBE_1344_REND_MASA_LOW_FS +void ivas_masa_zero_high_bands( + const int16_t nbands, /* i : Number of frequency bands with estimated values */ + float elevation_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated elevation */ + float azimuth_m_values[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated azimuth */ + float energyRatio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated direct-to-total ratio */ + float spreadCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS], /* i/o : Estimated spread coherence */ + float surroundingCoherence[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS] /* i/o : Estimated surround coherence */ +); +#endif + ivas_error ivas_dirac_ana_open( DIRAC_ANA_HANDLE *hDirACPtr, /* i/o: DIRAC data handle pointer */ int32_t input_Fs diff --git a/lib_rend/ivas_stat_rend.h b/lib_rend/ivas_stat_rend.h index 69fcb30fb8..5416e980b5 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1526,6 +1526,11 @@ typedef struct ivas_dirac_ana_data_structure typedef struct ivas_masa_prerend_data_structure { +#ifdef NONBE_1344_REND_MASA_LOW_FS + int16_t nbands; + int16_t band_grouping[MASA_FREQUENCY_BANDS + 1]; +#endif + /* CLDFB analysis */ int16_t num_Cldfb_instances; HANDLE_CLDFB_FILTER_BANK cldfbAnaEnc[MASA_MAX_TRANSPORT_CHANNELS]; diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 52994cdba1..78bf020db5 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -7312,10 +7312,19 @@ static void renderMasaToMasa( } /* 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]; + brange[1] = masaInput->hMasaPrerend->band_grouping[band_m_idx + 1]; +#else brange[0] = MASA_band_grouping_24[band_m_idx]; brange[1] = MASA_band_grouping_24[band_m_idx + 1]; +#endif for ( j = brange[0]; j < brange[1]; j++ ) { for ( i = 0; i < numAnalysisChannels; i++ ) -- GitLab From 45010f473cb44fb18a499aaba0ba6ca898c90cdc Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Fri, 19 Sep 2025 10:47:27 +0300 Subject: [PATCH 2/2] Clang format --- lib_rend/ivas_mcmasa_ana.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib_rend/ivas_mcmasa_ana.c b/lib_rend/ivas_mcmasa_ana.c index 6dec9feaa1..2f67607e94 100644 --- a/lib_rend/ivas_mcmasa_ana.c +++ b/lib_rend/ivas_mcmasa_ana.c @@ -1159,7 +1159,7 @@ void ivas_masa_zero_high_bands( { int16_t sf, band; - for (sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++) + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) { for ( band = nbands; band < MASA_FREQUENCY_BANDS; band++ ) { -- GitLab