Commit 83634ea8 authored by Tapani Pihlajakuja's avatar Tapani Pihlajakuja
Browse files

Fix BASOP issue 2529 by correcting scalings

parent a8ff39cd
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@
#define FIX_BASOP_2513_EXTRA_RETURN_REND_OPEN           /* Nokia: BASOP issue 2513: Removes extra return block */
#define FIX_BASOP_2514_EFAP_PORTING_ERROR               /* Nokia: BASOP issue 2514: Fix wrongly ported line */
#define FIX_BASOP_2516_REND_CUSTOM_LAYOUT_PORT_BUG      /* Nokia: BASOP issue 2516: Fix porting bug in setting planar state for custom layout in renderer */
#define FIX_BASOP_2529_MASA_RATIO_SCALINGS              /* Nokia: BASOP issue 2529: Fix MASA ratio scalings and verifications */

/* ##################### End NON-BE switches ########################### */

+4 −0
Original line number Diff line number Diff line
@@ -2317,8 +2317,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_Q30 ) ), 2 ) ) // 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++ )
+17 −0
Original line number Diff line number Diff line
@@ -9141,7 +9141,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_Q30 ) ), 2 ) ) // 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();
@@ -9173,16 +9177,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();
        }
    }
+20 −0
Original line number Diff line number Diff line
@@ -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
        }
    }