From afad5e2e9dbe01d95c603136b839ab82f14e3a53 Mon Sep 17 00:00:00 2001 From: Jouni Paulus Date: Tue, 21 Mar 2023 13:58:36 +0100 Subject: [PATCH] fix issue 373: MSAN error in decoding MASA to EXT. issue caused by missing init at lower sampling rates --- lib_com/ivas_cnst.h | 3 +++ lib_com/ivas_masa_com.c | 26 ++++++++++++++++++++++++++ lib_com/ivas_prot.h | 3 +++ lib_com/options.h | 1 + lib_dec/ivas_masa_dec.c | 12 ++++++++++++ lib_enc/ivas_masa_enc.c | 4 ++++ lib_util/masa_file_writer.c | 2 ++ 7 files changed, 51 insertions(+) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index a1716d0741..905972e44e 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -942,6 +942,9 @@ typedef enum #ifdef FIX_350_MASA_DELAY_COMP #define DELAY_MASA_PARAM_DEC_SFR 2 /* Delay to be compensation for MASA parameters in the decoder (subframes) */ +#ifdef FIX_373_MASA_DELAY_COMP_MSAN +#define SPH_IDX_FRONT ( MASA_NO_POINTS_EQUATOR / 2 ) /* Spherical index corresponding to front direction for setting as default value */ +#endif #endif #define DIRAC_SLOT_NS 1250000L /* time duration of a time slot, 1.25ms (==DELAY_RENERER_NS/MAX_PARAM_SPATIAL_SUBFRAMES) */ diff --git a/lib_com/ivas_masa_com.c b/lib_com/ivas_masa_com.c index 86f7676378..bd0336ad43 100644 --- a/lib_com/ivas_masa_com.c +++ b/lib_com/ivas_masa_com.c @@ -314,6 +314,10 @@ void masa_sample_rate_band_correction( int16_t *band_mapping, /* i/o: Band mapping used and modified */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: QMetadata structure for modification */ const int32_t sampling_rate /* i : Sampling rate */ +#ifdef FIX_373_MASA_DELAY_COMP_MSAN + , + MASA_DECODER_EXT_OUT_META_HANDLE hExtOutMeta /* i/o: MASA decoder metadata ext out buffer */ +#endif ) { uint8_t band, sf; @@ -386,6 +390,28 @@ void masa_sample_rate_band_correction( hQMetaData->twoDirBands[band] = 0; } } +#ifdef FIX_373_MASA_DELAY_COMP_MSAN + if ( hExtOutMeta != NULL ) + { + /* in decoder, zero the EXT out MASA meta buffer */ + for ( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ ) + { + for ( band = config->numCodingBands; band < MASA_FREQUENCY_BANDS; band++ ) + { + hExtOutMeta->directionIndex[0][sf][band] = SPH_IDX_FRONT; + hExtOutMeta->directToTotalRatio[0][sf][band] = 0u; + hExtOutMeta->spreadCoherence[0][sf][band] = 0u; + + hExtOutMeta->directionIndex[1][sf][band] = SPH_IDX_FRONT; + hExtOutMeta->directToTotalRatio[1][sf][band] = 0u; + hExtOutMeta->spreadCoherence[1][sf][band] = 0u; + + hExtOutMeta->surroundCoherence[sf][band] = 0u; + hExtOutMeta->diffuseToTotalRatio[sf][band] = UINT8_MAX; + } + } + } +#endif return; } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index a0506e7473..dccf26abd2 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -4534,6 +4534,9 @@ void masa_sample_rate_band_correction( int16_t *band_mapping, /* i/o: Band mapping used and modified */ IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: QMetadata structure for modification */ const int32_t sampling_rate /* i : sampling rate */ +#ifdef FIX_373_MASA_DELAY_COMP_MSAN + , MASA_DECODER_EXT_OUT_META_HANDLE hExtOutMeta /* i/o: MASA decoder metadata ext out buffer */ +#endif ); void invdct4_transform( diff --git a/lib_com/options.h b/lib_com/options.h index 8f87cd3fd2..219f2c1935 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -152,6 +152,7 @@ #define TD5 /* Eri: Contribution 17: Extended metadata for 6 DoF rendering in TD renderer */ #define TD5_FIX_INVALID_MEMORY_ACCESS /* FhG: Resolves segfault in case IVAS_REND_InitConfig gets initialized with rendererConfigEnabled:=false && ISM are being rendered */ #define FIX_371_DELAY_REPORT /* Issue 371: div. by zero with -no_delay_cmp */ +#define FIX_373_MASA_DELAY_COMP_MSAN /* Nokia: Issue 373: MASA audio/meta delay compensation. MSAN bugfix */ #ifdef FIX_I109_ORIENTATION_TRACKING #define OTR_REFERENCE_VECTOR_TRACKING /* FhG: enables the reference position orientation tracking mode */ diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index b8b7b74ffc..0f134a581a 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -492,7 +492,19 @@ static ivas_error ivas_masa_dec_config( ivas_set_qmetadata_maxbit_req( st_ivas->hQMetaData, st_ivas->ivas_format ); +#ifdef FIX_373_MASA_DELAY_COMP_MSAN + if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_EXTERNAL ) + { + /* need to apply the sampling rate correction also for the EXT output MASA meta buffer */ + masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hQMetaData, st_ivas->hDecoderConfig->output_Fs, hMasa->data.extOutMeta ); + } + else + { + masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hQMetaData, st_ivas->hDecoderConfig->output_Fs, NULL ); + } +#else masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, st_ivas->hQMetaData, st_ivas->hDecoderConfig->output_Fs ); +#endif return error; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index dca9be4010..67f74fec63 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -589,7 +589,11 @@ ivas_error ivas_masa_enc_config( ivas_set_qmetadata_maxbit_req( hQMetaData, ivas_format ); +#ifdef FIX_373_MASA_DELAY_COMP_MSAN + masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, st_ivas->hEncoderConfig->input_Fs, NULL ); +#else masa_sample_rate_band_correction( &( hMasa->config ), hMasa->data.band_mapping, hQMetaData, st_ivas->hEncoderConfig->input_Fs ); +#endif /* Transmit stereo signals using a mono downmix at lowest bitrates */ if ( ivas_format == MASA_FORMAT && st_ivas->nCPE == 1 && st_ivas->hCPE[0]->hStereoDft != NULL && st_ivas->hCPE[0]->hStereoDft->hConfig != NULL ) diff --git a/lib_util/masa_file_writer.c b/lib_util/masa_file_writer.c index 5667968ece..74429f9185 100644 --- a/lib_util/masa_file_writer.c +++ b/lib_util/masa_file_writer.c @@ -67,8 +67,10 @@ struct MasaFileWriter *-----------------------------------------------------------------------*/ #ifndef FIX_350_MASA_DELAY_COMP +#ifndef FIX_373_MASA_DELAY_COMP_MSAN #define SPH_IDX_FRONT ( MASA_NO_POINTS_EQUATOR / 2 ) /* Spherical index corresponding to front direction for setting as default value */ #endif +#endif /*-----------------------------------------------------------------------* * Local functions -- GitLab