diff --git a/lib_com/options.h b/lib_com/options.h index 2898dcbc9872749ef40cd2ebc6fc4a802080fca2..9a9f4611ba9567b6df0f3f95a2f4625c1da2092c 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -196,6 +196,7 @@ #define FIX_1383_HEAD_TRACK_SANITIZER /* Nok: issue 1383: Fix head tracking struc values reading in renderer */ #define FIX_1411_IGF_CRASH_BW_SWITCHING /* FhG: Fix for issue 1411: fixes crash that can happen for IGF with BW switching and DTX*/ #define NONBE_MDCT_ST_DTX_FIX_SUBOPT_SPATIAL_CNG /* FhG: Fix MDCT-Stereo comfort noise for certain noise types */ +#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 FIX_HRTF_LOAD_API // solves API conflicts between HRTF and object-editing features diff --git a/lib_rend/ivas_dirac_ana.c b/lib_rend/ivas_dirac_ana.c index f6273106de5b51828202c0d4b1704c2c95f34725..973182504a5cca5f4ab1d3949a9d124f22567756 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 37ee8cc7ef5620e987c5b30f8a854a66272ade8f..997cdc84d156e3f5efa171a446baf87e2bc75f7f 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, MASA_FREQUENCY_BANDS + 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 78519210302b82b9c15d495a3c65b886069bc94b..2f67607e9457a4ee100cceed1d482183c5fd0479 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 be092fe1016b1b73e0f10625c39ba3fa74bb3453..22dfafef1c596a633410239701e439c5021cb33e 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 d20958172afb319f75552cdad93bdc105fad93a4..a92070391a440d4bb42f7f82ae29b9bebfa3dc38 100644 --- a/lib_rend/ivas_prot_rend.h +++ b/lib_rend/ivas_prot_rend.h @@ -1474,6 +1474,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 fe039cacb0dee30993cfc599a09795844e043711..e248c7bdc38c5a41b4f17b6f4aaab2af94668a5f 100644 --- a/lib_rend/ivas_stat_rend.h +++ b/lib_rend/ivas_stat_rend.h @@ -1530,6 +1530,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 e69f43e6c1eb02c8a409c119d02d0ed6d8df7736..d0be488f83b84f2b39ac0d7287f6e3c673db6473 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -7397,10 +7397,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++ )