diff --git a/lib_com/options.h b/lib_com/options.h index 074d039191490122c3490f21950c73cef83ca8a4..53767145621ab8ac4840834a5372aece50d9ee3f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -121,7 +121,7 @@ #define FIX_BASOP_2522_MAP_PARAMS_DIRAC_STEREO /* FhG: BASOP issue 2522: Fix copy and paste error for side_gain calculation in map_params_dirac_to_stereo() */ #define FIX_2505_IVAS_DEC_SEGFAULT /* FhG: BASOP #2505: Add headroom to input of ivas_rend_crendProcessSubframe_fx() for ivas_mdft_fx() calculation */ #define HARMONIZE_DoRTFTn /* VA: harmonize functions DoRTFTn_fx() and DoRTFTn_fx_ivas() */ - +#define FIX_BASOP_2529_MASA_RATIO_SCALINGS /* Nokia: BASOP issue 2529: Fix MASA ratio scalings and verifications */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index 4125e6d3025965a8b4d3d539507b3465f9cd0187..c7f4d147313532d4091e4dc9ea9ce0b9fbee0816 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -2303,9 +2303,17 @@ static void compensate_energy_ratios_fx( move32(); FOR( dir = 0; dir < numDirs; dir++ ) { +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + ratioSum = L_add( ratioSum, L_shr( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], 1 ) ); // accumulate in Q29 +#else ratioSum = L_add( ratioSum, hMeta->directional_meta[dir].energy_ratio_fx[sf][band] ); // Q30 +#endif } +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + ratioSum = L_add( ratioSum, L_shr( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], 1 ) ); // accumulate in Q29 +#else ratioSum = L_add( ratioSum, hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); // Q30 +#endif IF( ratioSum == 0 ) { @@ -2317,8 +2325,12 @@ static void compensate_energy_ratios_fx( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = ONE_IN_Q30; // Q30 move32(); } +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + ELSE IF( GT_32( L_abs( L_sub( ratioSum, ONE_IN_Q29 ) ), 1 ) ) // else if ( ratioSum != 1.0f ) from float with minor rounding tolerance +#else // ELSE IF( NE_32( ratioSum, ONE_IN_Q30 ) ) ELSE /* Removing the check against 1 works well!!! */ +#endif { Word16 exp_diff; FOR( dir = 0; dir < numDirs; dir++ ) @@ -2326,13 +2338,21 @@ static void compensate_energy_ratios_fx( hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = BASOP_Util_Divide3232_Scale_newton( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], ratioSum, &exp_diff ); move32(); +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], sub( exp_diff, Q2 ) ); // back to Q30 +#else hMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( hMeta->directional_meta[dir].energy_ratio_fx[sf][band], sub( exp_diff, Q1 ) ); // Q30 +#endif move32(); } hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = BASOP_Util_Divide3232_Scale_newton( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], ratioSum, &exp_diff ); move32(); +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], sub( exp_diff, Q2 ) ); // back to Q30 +#else hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], sub( exp_diff, Q1 ) ); // Q30 +#endif move32(); } } diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index 72a2eca3e9fdc298206c9d5f7bd6fd028d55464a..1c10f348887aaf67b9cc9df413140d4d045830f6 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -9017,7 +9017,11 @@ static void renderMasaToMasa( IVAS_REND_AudioBuffer outAudio ) { Word16 sf, band, dir, numDirs; +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + Word32 ratioSum_fx; /* Q29 for accumulation */ +#else Word32 ratioSum_fx; /* Q30 */ +#endif MASA_DECODER_EXT_OUT_META_HANDLE outMeta; MASA_METADATA_FRAME *inMeta; Word32 tmpBuffer_fx[MAX_OUTPUT_CHANNELS][L_FRAME48k]; @@ -9145,9 +9149,17 @@ static void renderMasaToMasa( move32(); FOR( dir = 0; dir < numDirs; dir++ ) { +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + ratioSum_fx = L_add( ratioSum_fx, L_shr( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], 1 ) ); // accumulate in Q29 +#else ratioSum_fx = L_add( ratioSum_fx, inMeta->directional_meta[dir].energy_ratio_fx[sf][band] ); +#endif } +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + ratioSum_fx = L_add( ratioSum_fx, L_shr( inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], 1 ) ); // accumulate in Q29 +#else ratioSum_fx = L_add( ratioSum_fx, inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); +#endif IF( ratioSum_fx == 0 ) { @@ -9159,7 +9171,11 @@ static void renderMasaToMasa( inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = ONE_IN_Q30; move32(); } +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + ELSE IF( GT_32( L_abs( L_sub( ratioSum_fx, ONE_IN_Q29 ) ), 1 ) ) // else if ( ratioSum != 1.0f ) from float with minor rounding tolerance +#else ELSE IF( NE_32( ratioSum_fx, ONE_IN_Q30 ) ) +#endif { Word16 tmp_e = 0; move16(); @@ -9168,7 +9184,11 @@ static void renderMasaToMasa( FOR( dir = 0; dir < numDirs; dir++ ) { tmp = BASOP_Util_Divide3232_Scale_newton( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], ratioSum_fx, &tmp_e ); +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + inMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 2 ) ); /* Back to Q30 */ +#else inMeta->directional_meta[dir].energy_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); /* Q30 */ +#endif move32(); } tmp_e = 0; @@ -9176,7 +9196,11 @@ static void renderMasaToMasa( tmp = 0; move32(); tmp = BASOP_Util_Divide3232_Scale_newton( inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band], ratioSum_fx, &tmp_e ); +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 2 ) ); /* Back to Q30 */ +#else inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] = L_shl( tmp, sub( tmp_e, 1 ) ); /* Q30 */ +#endif move32(); } } @@ -9191,16 +9215,29 @@ static void renderMasaToMasa( FOR( dir = 0; dir < numDirs; dir++ ) { outMeta->directionIndex[dir][sf][band] = index_theta_phi_16_fx( &inMeta->directional_meta[dir].elevation_fx[sf][band], &inMeta->directional_meta[dir].azimuth_fx[sf][band], masaInput->hMasaPrerend->sph_grid16 ); +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + outMeta->directToTotalRatio[dir][sf][band] = (UWord8) W_extract_h( W_mult_32_16( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], UINT8_MAX << 1 ) ); +#else outMeta->directToTotalRatio[dir][sf][band] = (UWord8) L_shr( inMeta->directional_meta[dir].energy_ratio_fx[sf][band], Q22 ); +#endif outMeta->diffuseToTotalRatio[sf][band] = (UWord8) sub( outMeta->diffuseToTotalRatio[sf][band], outMeta->directToTotalRatio[dir][sf][band] ); +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + outMeta->spreadCoherence[dir][sf][band] = (UWord8) W_extract_h( W_mult_32_16( L_deposit_h( inMeta->directional_meta[dir].spread_coherence_fx[sf][band] ), UINT8_MAX << 1 ) ); +#else outMeta->spreadCoherence[dir][sf][band] = (UWord8) shr( inMeta->directional_meta[dir].spread_coherence_fx[sf][band], Q7 ); +#endif move16(); move16(); move16(); move16(); } + +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + outMeta->surroundCoherence[sf][band] = (UWord8) W_extract_h( W_mult_32_16( L_deposit_h( inMeta->common_meta.surround_coherence_fx[sf][band] ), UINT8_MAX << 1 ) ); +#else outMeta->surroundCoherence[sf][band] = (UWord8) shr( inMeta->common_meta.surround_coherence_fx[sf][band], Q7 ); +#endif move16(); } } diff --git a/lib_util/masa_file_reader.c b/lib_util/masa_file_reader.c index 6cc7e8a7a853d132a4dc6824262886790ec7d681..04ffdbfaa148982912ab01722bdfe39844fe0086 100644 --- a/lib_util/masa_file_reader.c +++ b/lib_util/masa_file_reader.c @@ -194,7 +194,11 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + hMeta->directional_meta[i].energy_ratio_fx[j][b] = (Word32) ( ( (int64_t) readOther[b] * ONE_IN_Q30 + 254 ) / 255 ); // Q30 +#else hMeta->directional_meta[i].energy_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30 +#endif } /* Spread coherence */ @@ -205,7 +209,11 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + hMeta->directional_meta[i].spread_coherence_fx[j][b] = (Word16) ( ( (int32_t) readOther[b] * ONE_IN_Q15 + 254 ) / 255 ); // Q15 +#else hMeta->directional_meta[i].spread_coherence_fx[j][b] = (Word16) ( readOther[b] * ONE_IN_Q7 ); // Q15 +#endif } } @@ -218,7 +226,11 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + hMeta->common_meta.diffuse_to_total_ratio_fx[j][b] = (Word32) ( ( (int64_t) readOther[b] * ONE_IN_Q30 + 254 ) / 255 ); // Q30 +#else hMeta->common_meta.diffuse_to_total_ratio_fx[j][b] = (Word32) ( readOther[b] * ONE_IN_Q22 ); // Q30 +#endif } /* Surround coherence */ @@ -229,8 +241,12 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + hMeta->common_meta.surround_coherence_fx[j][b] = (Word16) ( ( (int32_t) readOther[b] * ONE_IN_Q15 + 254 ) / 255 ); // Q15 +#else hMeta->common_meta.surround_coherence_fx[j][b] = shl( (Word16) readOther[b], 7 ); // Q8->Q15 move16(); +#endif } /* Remainder-to-total ratio */ @@ -241,8 +257,12 @@ ivas_error MasaFileReader_readNextFrame( for ( b = 0; b < MASA_FREQUENCY_BANDS; b++ ) { +#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS + hMeta->common_meta.remainder_to_total_ratio_fx[j][b] = (Word32) ( ( (int64_t) readOther[b] * ONE_IN_Q30 + 254 ) / 255 ); // Q30 +#else hMeta->common_meta.remainder_to_total_ratio_fx[j][b] = L_shl( (Word32) readOther[b], Q22 ); // Q8 -> Q30 move32(); +#endif } }