From 41b104d0fbf1e8cf280ab594f1316d815afdd1d6 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Fri, 29 Sep 2023 07:48:49 -0300 Subject: Fix audio renderer compressor effect (#5742) * Delete DecibelToLinearExtended and fix Log10 function * Fix CopyBuffer and ClearBuffer * Change effect states from class to struct + formatting * Formatting * Make UpdateLowPassFilter readonly * More compressor fixes --- src/Ryujinx.Audio/Renderer/Dsp/FloatingPointHelper.cs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/Ryujinx.Audio/Renderer/Dsp/FloatingPointHelper.cs') diff --git a/src/Ryujinx.Audio/Renderer/Dsp/FloatingPointHelper.cs b/src/Ryujinx.Audio/Renderer/Dsp/FloatingPointHelper.cs index b231dbb6..415e1c19 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/FloatingPointHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/FloatingPointHelper.cs @@ -52,7 +52,7 @@ namespace Ryujinx.Audio.Renderer.Dsp { // NOTE: Nintendo uses an approximation of log10, we don't. // As such, we support the same ranges as Nintendo to avoid unexpected behaviours. - return MathF.Pow(10, MathF.Max(x, 1.0e-10f)); + return MathF.Log10(MathF.Max(x, 1.0e-10f)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -62,7 +62,8 @@ namespace Ryujinx.Audio.Renderer.Dsp foreach (float input in inputs) { - res += (input * input); + float normInput = input * (1f / 32768f); + res += normInput * normInput; } res /= inputs.Length; @@ -81,19 +82,6 @@ namespace Ryujinx.Audio.Renderer.Dsp return MathF.Pow(10.0f, db / 20.0f); } - /// - /// Map decibel to linear in [0, 2] range. - /// - /// The decibel value to convert - /// Converted linear value in [0, 2] range - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float DecibelToLinearExtended(float db) - { - float tmp = MathF.Log2(DecibelToLinear(db)); - - return MathF.Truncate(tmp) + MathF.Pow(2.0f, tmp - MathF.Truncate(tmp)); - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float DegreesToRadians(float degrees) { -- cgit v1.2.3