Commit 24b2cd2c authored by Tapani Pihlajakuja's avatar Tapani Pihlajakuja
Browse files

Remove saturation and instead accumulate in Q29 for proper normalization.

parent 5c9a7b86
Loading
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -2304,13 +2304,13 @@ static void compensate_energy_ratios_fx(
            FOR( dir = 0; dir < numDirs; dir++ )
            {
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                ratioSum = L_add_sat( ratioSum, hMeta->directional_meta[dir].energy_ratio_fx[sf][band] ); // Q30
                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_sat( ratioSum, hMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] ); // Q30
            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
@@ -2326,7 +2326,7 @@ static void compensate_energy_ratios_fx(
                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 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!!! */
@@ -2338,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();
            }
        }
+11 −3
Original line number Diff line number Diff line
@@ -9126,13 +9126,13 @@ static void renderMasaToMasa(
            FOR( dir = 0; dir < numDirs; dir++ )
            {
#ifdef FIX_BASOP_2529_MASA_RATIO_SCALINGS
                ratioSum_fx = L_add_sat( ratioSum_fx, inMeta->directional_meta[dir].energy_ratio_fx[sf][band] );
                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_sat( ratioSum_fx, inMeta->common_meta.diffuse_to_total_ratio_fx[sf][band] );
            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
@@ -9148,7 +9148,7 @@ static void renderMasaToMasa(
                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 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
@@ -9160,7 +9160,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;
@@ -9168,7 +9172,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();
            }
        }