diff options
| author | TSR Berry <20988865+TSRBerry@users.noreply.github.com> | 2023-04-08 01:22:00 +0200 |
|---|---|---|
| committer | Mary <thog@protonmail.com> | 2023-04-27 23:51:14 +0200 |
| commit | cee712105850ac3385cd0091a923438167433f9f (patch) | |
| tree | 4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /Ryujinx.Audio/Renderer/Dsp/State | |
| parent | cd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff) | |
Move solution and projects to src
Diffstat (limited to 'Ryujinx.Audio/Renderer/Dsp/State')
| -rw-r--r-- | Ryujinx.Audio/Renderer/Dsp/State/AdpcmLoopContext.cs | 12 | ||||
| -rw-r--r-- | Ryujinx.Audio/Renderer/Dsp/State/AuxiliaryBufferHeader.cs | 74 | ||||
| -rw-r--r-- | Ryujinx.Audio/Renderer/Dsp/State/BiquadFilterState.cs | 13 | ||||
| -rw-r--r-- | Ryujinx.Audio/Renderer/Dsp/State/CompressorState.cs | 51 | ||||
| -rw-r--r-- | Ryujinx.Audio/Renderer/Dsp/State/DelayState.cs | 67 | ||||
| -rw-r--r-- | Ryujinx.Audio/Renderer/Dsp/State/LimiterState.cs | 31 | ||||
| -rw-r--r-- | Ryujinx.Audio/Renderer/Dsp/State/Reverb3dState.cs | 119 | ||||
| -rw-r--r-- | Ryujinx.Audio/Renderer/Dsp/State/ReverbState.cs | 204 |
8 files changed, 0 insertions, 571 deletions
diff --git a/Ryujinx.Audio/Renderer/Dsp/State/AdpcmLoopContext.cs b/Ryujinx.Audio/Renderer/Dsp/State/AdpcmLoopContext.cs deleted file mode 100644 index 821a135e..00000000 --- a/Ryujinx.Audio/Renderer/Dsp/State/AdpcmLoopContext.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Runtime.InteropServices; - -namespace Ryujinx.Audio.Renderer.Dsp.State -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 6)] - public struct AdpcmLoopContext - { - public short PredScale; - public short History0; - public short History1; - } -}
\ No newline at end of file diff --git a/Ryujinx.Audio/Renderer/Dsp/State/AuxiliaryBufferHeader.cs b/Ryujinx.Audio/Renderer/Dsp/State/AuxiliaryBufferHeader.cs deleted file mode 100644 index 4e8d11e4..00000000 --- a/Ryujinx.Audio/Renderer/Dsp/State/AuxiliaryBufferHeader.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Ryujinx.Memory; -using System.Runtime.InteropServices; - -namespace Ryujinx.Audio.Renderer.Dsp.State -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x80)] - public struct AuxiliaryBufferHeader - { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x40)] - public struct AuxiliaryBufferInfo - { - private const uint ReadOffsetPosition = 0x0; - private const uint WriteOffsetPosition = 0x4; - private const uint LostSampleCountPosition = 0x8; - private const uint TotalSampleCountPosition = 0xC; - - public uint ReadOffset; - public uint WriteOffset; - public uint LostSampleCount; - public uint TotalSampleCount; - private unsafe fixed uint _unknown[12]; - - public static uint GetReadOffset(IVirtualMemoryManager manager, ulong bufferAddress) - { - return manager.Read<uint>(bufferAddress + ReadOffsetPosition); - } - - public static uint GetWriteOffset(IVirtualMemoryManager manager, ulong bufferAddress) - { - return manager.Read<uint>(bufferAddress + WriteOffsetPosition); - } - - public static uint GetLostSampleCount(IVirtualMemoryManager manager, ulong bufferAddress) - { - return manager.Read<uint>(bufferAddress + LostSampleCountPosition); - } - - public static uint GetTotalSampleCount(IVirtualMemoryManager manager, ulong bufferAddress) - { - return manager.Read<uint>(bufferAddress + TotalSampleCountPosition); - } - - public static void SetReadOffset(IVirtualMemoryManager manager, ulong bufferAddress, uint value) - { - manager.Write(bufferAddress + ReadOffsetPosition, value); - } - - public static void SetWriteOffset(IVirtualMemoryManager manager, ulong bufferAddress, uint value) - { - manager.Write(bufferAddress + WriteOffsetPosition, value); - } - - public static void SetLostSampleCount(IVirtualMemoryManager manager, ulong bufferAddress, uint value) - { - manager.Write(bufferAddress + LostSampleCountPosition, value); - } - - public static void SetTotalSampleCount(IVirtualMemoryManager manager, ulong bufferAddress, uint value) - { - manager.Write(bufferAddress + TotalSampleCountPosition, value); - } - - public static void Reset(IVirtualMemoryManager manager, ulong bufferAddress) - { - // NOTE: Lost sample count is never reset, since REV10. - manager.Write(bufferAddress + ReadOffsetPosition, 0UL); - manager.Write(bufferAddress + TotalSampleCountPosition, 0); - } - } - - public AuxiliaryBufferInfo CpuBufferInfo; - public AuxiliaryBufferInfo DspBufferInfo; - } -}
\ No newline at end of file diff --git a/Ryujinx.Audio/Renderer/Dsp/State/BiquadFilterState.cs b/Ryujinx.Audio/Renderer/Dsp/State/BiquadFilterState.cs deleted file mode 100644 index 4220e6d5..00000000 --- a/Ryujinx.Audio/Renderer/Dsp/State/BiquadFilterState.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.InteropServices; - -namespace Ryujinx.Audio.Renderer.Dsp.State -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x10)] - public struct BiquadFilterState - { - public float State0; - public float State1; - public float State2; - public float State3; - } -}
\ No newline at end of file diff --git a/Ryujinx.Audio/Renderer/Dsp/State/CompressorState.cs b/Ryujinx.Audio/Renderer/Dsp/State/CompressorState.cs deleted file mode 100644 index 76aff807..00000000 --- a/Ryujinx.Audio/Renderer/Dsp/State/CompressorState.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Ryujinx.Audio.Renderer.Dsp.Effect; -using Ryujinx.Audio.Renderer.Parameter.Effect; - -namespace Ryujinx.Audio.Renderer.Dsp.State -{ - public class CompressorState - { - public ExponentialMovingAverage InputMovingAverage; - public float Unknown4; - public ExponentialMovingAverage CompressionGainAverage; - public float CompressorGainReduction; - public float Unknown10; - public float Unknown14; - public float PreviousCompressionEmaAlpha; - public float MakeupGain; - public float OutputGain; - - public CompressorState(ref CompressorParameter parameter) - { - InputMovingAverage = new ExponentialMovingAverage(0.0f); - Unknown4 = 1.0f; - CompressionGainAverage = new ExponentialMovingAverage(1.0f); - - UpdateParameter(ref parameter); - } - - public void UpdateParameter(ref CompressorParameter parameter) - { - float threshold = parameter.Threshold; - float ratio = 1.0f / parameter.Ratio; - float attackCoefficient = parameter.AttackCoefficient; - float makeupGain; - - if (parameter.MakeupGainEnabled) - { - makeupGain = (threshold * 0.5f * (ratio - 1.0f)) - 3.0f; - } - else - { - makeupGain = 0.0f; - } - - PreviousCompressionEmaAlpha = attackCoefficient; - MakeupGain = makeupGain; - CompressorGainReduction = (1.0f - ratio) / Constants.ChannelCountMax; - Unknown10 = threshold - 1.5f; - Unknown14 = threshold + 1.5f; - OutputGain = FloatingPointHelper.DecibelToLinearExtended(parameter.OutputGain + makeupGain); - } - } -} diff --git a/Ryujinx.Audio/Renderer/Dsp/State/DelayState.cs b/Ryujinx.Audio/Renderer/Dsp/State/DelayState.cs deleted file mode 100644 index 2a1e7f83..00000000 --- a/Ryujinx.Audio/Renderer/Dsp/State/DelayState.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Ryujinx.Audio.Renderer.Dsp.Effect; -using Ryujinx.Audio.Renderer.Parameter.Effect; -using System.Runtime.CompilerServices; - -namespace Ryujinx.Audio.Renderer.Dsp.State -{ - public class DelayState - { - public DelayLine[] DelayLines { get; } - public float[] LowPassZ { get; set; } - public float FeedbackGain { get; private set; } - public float DelayFeedbackBaseGain { get; private set; } - public float DelayFeedbackCrossGain { get; private set; } - public float LowPassFeedbackGain { get; private set; } - public float LowPassBaseGain { get; private set; } - - private const int FixedPointPrecision = 14; - - public DelayState(ref DelayParameter parameter, ulong workBuffer) - { - DelayLines = new DelayLine[parameter.ChannelCount]; - LowPassZ = new float[parameter.ChannelCount]; - - uint sampleRate = (uint)FixedPointHelper.ToInt(parameter.SampleRate, FixedPointPrecision) / 1000; - - for (int i = 0; i < DelayLines.Length; i++) - { - DelayLines[i] = new DelayLine(sampleRate, parameter.DelayTimeMax); - DelayLines[i].SetDelay(parameter.DelayTime); - } - - UpdateParameter(ref parameter); - } - - public void UpdateParameter(ref DelayParameter parameter) - { - FeedbackGain = FixedPointHelper.ToFloat(parameter.FeedbackGain, FixedPointPrecision) * 0.98f; - - float channelSpread = FixedPointHelper.ToFloat(parameter.ChannelSpread, FixedPointPrecision); - - DelayFeedbackBaseGain = (1.0f - channelSpread) * FeedbackGain; - - if (parameter.ChannelCount == 4 || parameter.ChannelCount == 6) - { - DelayFeedbackCrossGain = channelSpread * 0.5f * FeedbackGain; - } - else - { - DelayFeedbackCrossGain = channelSpread * FeedbackGain; - } - - LowPassFeedbackGain = 0.95f * FixedPointHelper.ToFloat(parameter.LowPassAmount, FixedPointPrecision); - LowPassBaseGain = 1.0f - LowPassFeedbackGain; - } - - public void UpdateLowPassFilter(ref float tempRawRef, uint channelCount) - { - for (int i = 0; i < channelCount; i++) - { - float lowPassResult = LowPassFeedbackGain * LowPassZ[i] + Unsafe.Add(ref tempRawRef, i) * LowPassBaseGain; - - LowPassZ[i] = lowPassResult; - DelayLines[i].Update(lowPassResult); - } - } - } -}
\ No newline at end of file diff --git a/Ryujinx.Audio/Renderer/Dsp/State/LimiterState.cs b/Ryujinx.Audio/Renderer/Dsp/State/LimiterState.cs deleted file mode 100644 index 0560757c..00000000 --- a/Ryujinx.Audio/Renderer/Dsp/State/LimiterState.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Ryujinx.Audio.Renderer.Dsp.Effect; -using Ryujinx.Audio.Renderer.Parameter.Effect; -using System; - -namespace Ryujinx.Audio.Renderer.Dsp.State -{ - public class LimiterState - { - public ExponentialMovingAverage[] DetectorAverage; - public ExponentialMovingAverage[] CompressionGainAverage; - public float[] DelayedSampleBuffer; - public int[] DelayedSampleBufferPosition; - - public LimiterState(ref LimiterParameter parameter, ulong workBuffer) - { - DetectorAverage = new ExponentialMovingAverage[parameter.ChannelCount]; - CompressionGainAverage = new ExponentialMovingAverage[parameter.ChannelCount]; - DelayedSampleBuffer = new float[parameter.ChannelCount * parameter.DelayBufferSampleCountMax]; - DelayedSampleBufferPosition = new int[parameter.ChannelCount]; - - DetectorAverage.AsSpan().Fill(new ExponentialMovingAverage(0.0f)); - CompressionGainAverage.AsSpan().Fill(new ExponentialMovingAverage(1.0f)); - DelayedSampleBufferPosition.AsSpan().Fill(0); - DelayedSampleBuffer.AsSpan().Fill(0.0f); - - UpdateParameter(ref parameter); - } - - public void UpdateParameter(ref LimiterParameter parameter) { } - } -}
\ No newline at end of file diff --git a/Ryujinx.Audio/Renderer/Dsp/State/Reverb3dState.cs b/Ryujinx.Audio/Renderer/Dsp/State/Reverb3dState.cs deleted file mode 100644 index c0646603..00000000 --- a/Ryujinx.Audio/Renderer/Dsp/State/Reverb3dState.cs +++ /dev/null @@ -1,119 +0,0 @@ -using Ryujinx.Audio.Renderer.Dsp.Effect; -using Ryujinx.Audio.Renderer.Parameter.Effect; -using System; - -namespace Ryujinx.Audio.Renderer.Dsp.State -{ - public class Reverb3dState - { - private readonly float[] FdnDelayMinTimes = new float[4] { 5.0f, 6.0f, 13.0f, 14.0f }; - private readonly float[] FdnDelayMaxTimes = new float[4] { 45.704f, 82.782f, 149.94f, 271.58f }; - private readonly float[] DecayDelayMaxTimes1 = new float[4] { 17.0f, 13.0f, 9.0f, 7.0f }; - private readonly float[] DecayDelayMaxTimes2 = new float[4] { 19.0f, 11.0f, 10.0f, 6.0f }; - private readonly float[] EarlyDelayTimes = new float[20] { 0.017136f, 0.059154f, 0.16173f, 0.39019f, 0.42526f, 0.45541f, 0.68974f, 0.74591f, 0.83384f, 0.8595f, 0.0f, 0.075024f, 0.16879f, 0.2999f, 0.33744f, 0.3719f, 0.59901f, 0.71674f, 0.81786f, 0.85166f }; - public readonly float[] EarlyGain = new float[20] { 0.67096f, 0.61027f, 1.0f, 0.35680f, 0.68361f, 0.65978f, 0.51939f, 0.24712f, 0.45945f, 0.45021f, 0.64196f, 0.54879f, 0.92925f, 0.38270f, 0.72867f, 0.69794f, 0.5464f, 0.24563f, 0.45214f, 0.44042f }; - - public IDelayLine[] FdnDelayLines { get; } - public DecayDelay[] DecayDelays1 { get; } - public DecayDelay[] DecayDelays2 { get; } - public IDelayLine PreDelayLine { get; } - public IDelayLine FrontCenterDelayLine { get; } - public float DryGain { get; private set; } - public uint[] EarlyDelayTime { get; private set; } - public float PreviousPreDelayValue { get; set; } - public float PreviousPreDelayGain { get; private set; } - public float TargetPreDelayGain { get; private set; } - public float EarlyReflectionsGain { get; private set; } - public float LateReverbGain { get; private set; } - public uint ReflectionDelayTime { get; private set; } - public float EchoLateReverbDecay { get; private set; } - public float[] DecayDirectFdnGain { get; private set; } - public float[] DecayCurrentFdnGain { get; private set; } - public float[] DecayCurrentOutputGain { get; private set; } - public float[] PreviousFeedbackOutputDecayed { get; private set; } - - public Reverb3dState(ref Reverb3dParameter parameter, ulong workBuffer) - { - FdnDelayLines = new IDelayLine[4]; - DecayDelays1 = new DecayDelay[4]; - DecayDelays2 = new DecayDelay[4]; - DecayDirectFdnGain = new float[4]; - DecayCurrentFdnGain = new float[4]; - DecayCurrentOutputGain = new float[4]; - PreviousFeedbackOutputDecayed = new float[4]; - - uint sampleRate = parameter.SampleRate / 1000; - - for (int i = 0; i < 4; i++) - { - FdnDelayLines[i] = new DelayLine3d(sampleRate, FdnDelayMaxTimes[i]); - DecayDelays1[i] = new DecayDelay(new DelayLine3d(sampleRate, DecayDelayMaxTimes1[i])); - DecayDelays2[i] = new DecayDelay(new DelayLine3d(sampleRate, DecayDelayMaxTimes2[i])); - } - - PreDelayLine = new DelayLine3d(sampleRate, 400); - FrontCenterDelayLine = new DelayLine3d(sampleRate, 5); - - UpdateParameter(ref parameter); - } - - public void UpdateParameter(ref Reverb3dParameter parameter) - { - uint sampleRate = parameter.SampleRate / 1000; - - EarlyDelayTime = new uint[20]; - DryGain = parameter.DryGain; - PreviousFeedbackOutputDecayed.AsSpan().Fill(0); - PreviousPreDelayValue = 0; - - EarlyReflectionsGain = FloatingPointHelper.Pow10(Math.Min(parameter.RoomGain + parameter.ReflectionsGain, 5000.0f) / 2000.0f); - LateReverbGain = FloatingPointHelper.Pow10(Math.Min(parameter.RoomGain + parameter.ReverbGain, 5000.0f) / 2000.0f); - - float highFrequencyRoomGain = FloatingPointHelper.Pow10(parameter.RoomHf / 2000.0f); - - if (highFrequencyRoomGain < 1.0f) - { - float tempA = 1.0f - highFrequencyRoomGain; - float tempB = 2.0f - ((2.0f * highFrequencyRoomGain) * FloatingPointHelper.Cos(256.0f * parameter.HfReference / parameter.SampleRate)); - float tempC = MathF.Sqrt(MathF.Pow(tempB, 2) - (4.0f * (1.0f - highFrequencyRoomGain) * (1.0f - highFrequencyRoomGain))); - - PreviousPreDelayGain = (tempB - tempC) / (2.0f * tempA); - TargetPreDelayGain = 1.0f - PreviousPreDelayGain; - } - else - { - PreviousPreDelayGain = 0.0f; - TargetPreDelayGain = 1.0f; - } - - ReflectionDelayTime = IDelayLine.GetSampleCount(sampleRate, 1000.0f * (parameter.ReflectionDelay + parameter.ReverbDelayTime)); - EchoLateReverbDecay = 0.6f * parameter.Diffusion * 0.01f; - - for (int i = 0; i < FdnDelayLines.Length; i++) - { - FdnDelayLines[i].SetDelay(FdnDelayMinTimes[i] + (parameter.Density / 100 * (FdnDelayMaxTimes[i] - FdnDelayMinTimes[i]))); - - uint tempSampleCount = FdnDelayLines[i].CurrentSampleCount + DecayDelays1[i].CurrentSampleCount + DecayDelays2[i].CurrentSampleCount; - - float tempA = (-60.0f * tempSampleCount) / (parameter.DecayTime * parameter.SampleRate); - float tempB = tempA / parameter.HfDecayRatio; - float tempC = FloatingPointHelper.Cos(128.0f * 0.5f * parameter.HfReference / parameter.SampleRate) / FloatingPointHelper.Sin(128.0f * 0.5f * parameter.HfReference / parameter.SampleRate); - float tempD = FloatingPointHelper.Pow10((tempB - tempA) / 40.0f); - float tempE = FloatingPointHelper.Pow10((tempB + tempA) / 40.0f) * 0.7071f; - - DecayDirectFdnGain[i] = tempE * ((tempD * tempC) + 1.0f) / (tempC + tempD); - DecayCurrentFdnGain[i] = tempE * (1.0f - (tempD * tempC)) / (tempC + tempD); - DecayCurrentOutputGain[i] = (tempC - tempD) / (tempC + tempD); - - DecayDelays1[i].SetDecayRate(EchoLateReverbDecay); - DecayDelays2[i].SetDecayRate(EchoLateReverbDecay * -0.9f); - } - - for (int i = 0; i < EarlyDelayTime.Length; i++) - { - uint sampleCount = Math.Min(IDelayLine.GetSampleCount(sampleRate, (parameter.ReflectionDelay * 1000.0f) + (EarlyDelayTimes[i] * 1000.0f * ((parameter.ReverbDelayTime * 0.9998f) + 0.02f))), PreDelayLine.SampleCountMax); - EarlyDelayTime[i] = sampleCount; - } - } - } -}
\ No newline at end of file diff --git a/Ryujinx.Audio/Renderer/Dsp/State/ReverbState.cs b/Ryujinx.Audio/Renderer/Dsp/State/ReverbState.cs deleted file mode 100644 index 1ffabe05..00000000 --- a/Ryujinx.Audio/Renderer/Dsp/State/ReverbState.cs +++ /dev/null @@ -1,204 +0,0 @@ -using Ryujinx.Audio.Renderer.Common; -using Ryujinx.Audio.Renderer.Dsp.Effect; -using Ryujinx.Audio.Renderer.Parameter.Effect; -using System; - -namespace Ryujinx.Audio.Renderer.Dsp.State -{ - public class ReverbState - { - private static readonly float[] FdnDelayTimes = new float[20] - { - // Room - 53.953247f, 79.192566f, 116.238770f, 130.615295f, - // Hall - 53.953247f, 79.192566f, 116.238770f, 170.615295f, - // Plate - 5f, 10f, 5f, 10f, - // Cathedral - 47.03f, 71f, 103f, 170f, - // Max delay (Hall is the one with the highest values so identical to Hall) - 53.953247f, 79.192566f, 116.238770f, 170.615295f, - }; - - private static readonly float[] DecayDelayTimes = new float[20] - { - // Room - 7f, 9f, 13f, 17f, - // Hall - 7f, 9f, 13f, 17f, - // Plate (no decay) - 1f, 1f, 1f, 1f, - // Cathedral - 7f, 7f, 13f, 9f, - // Max delay (Hall is the one with the highest values so identical to Hall) - 7f, 9f, 13f, 17f, - }; - - private static readonly float[] EarlyDelayTimes = new float[50] - { - // Room - 0.0f, 3.5f, 2.8f, 3.9f, 2.7f, 13.4f, 7.9f, 8.4f, 9.9f, 12.0f, - // Chamber - 0.0f, 11.8f, 5.5f, 11.2f, 10.4f, 38.1f, 22.2f, 29.6f, 21.2f, 24.8f, - // Hall - 0.0f, 41.5f, 20.5f, 41.3f, 0.0f, 29.5f, 33.8f, 45.2f, 46.8f, 0.0f, - // Cathedral - 33.1f, 43.3f, 22.8f, 37.9f, 14.9f, 35.3f, 17.9f, 34.2f, 0.0f, 43.3f, - // Disabled - 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f - }; - - private static readonly float[] EarlyGainBase = new float[50] - { - // Room - 0.70f, 0.68f, 0.70f, 0.68f, 0.70f, 0.68f, 0.70f, 0.68f, 0.68f, 0.68f, - // Chamber - 0.70f, 0.68f, 0.70f, 0.68f, 0.70f, 0.68f, 0.68f, 0.68f, 0.68f, 0.68f, - // Hall - 0.50f, 0.70f, 0.70f, 0.68f, 0.50f, 0.68f, 0.68f, 0.70f, 0.68f, 0.00f, - // Cathedral - 0.93f, 0.92f, 0.87f, 0.86f, 0.94f, 0.81f, 0.80f, 0.77f, 0.76f, 0.65f, - // Disabled - 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f - }; - - private static readonly float[] PreDelayTimes = new float[5] - { - // Room - 12.5f, - // Chamber - 40.0f, - // Hall - 50.0f, - // Cathedral - 50.0f, - // Disabled - 0.0f - }; - - public DelayLine[] FdnDelayLines { get; } - public DecayDelay[] DecayDelays { get; } - public DelayLine PreDelayLine { get; } - public DelayLine FrontCenterDelayLine { get; } - public uint[] EarlyDelayTime { get; } - public float[] EarlyGain { get; } - public uint PreDelayLineDelayTime { get; private set; } - - public float[] HighFrequencyDecayDirectGain { get; } - public float[] HighFrequencyDecayPreviousGain { get; } - public float[] PreviousFeedbackOutput { get; } - - public const int EarlyModeCount = 10; - - private const int FixedPointPrecision = 14; - - private ReadOnlySpan<float> GetFdnDelayTimesByLateMode(ReverbLateMode lateMode) - { - return FdnDelayTimes.AsSpan((int)lateMode * 4, 4); - } - - private ReadOnlySpan<float> GetDecayDelayTimesByLateMode(ReverbLateMode lateMode) - { - return DecayDelayTimes.AsSpan((int)lateMode * 4, 4); - } - - public ReverbState(ref ReverbParameter parameter, ulong workBuffer, bool isLongSizePreDelaySupported) - { - FdnDelayLines = new DelayLine[4]; - DecayDelays = new DecayDelay[4]; - EarlyDelayTime = new uint[EarlyModeCount]; - EarlyGain = new float[EarlyModeCount]; - HighFrequencyDecayDirectGain = new float[4]; - HighFrequencyDecayPreviousGain = new float[4]; - PreviousFeedbackOutput = new float[4]; - - ReadOnlySpan<float> fdnDelayTimes = GetFdnDelayTimesByLateMode(ReverbLateMode.Limit); - ReadOnlySpan<float> decayDelayTimes = GetDecayDelayTimesByLateMode(ReverbLateMode.Limit); - - uint sampleRate = (uint)FixedPointHelper.ToFloat((uint)parameter.SampleRate, FixedPointPrecision); - - for (int i = 0; i < 4; i++) - { - FdnDelayLines[i] = new DelayLine(sampleRate, fdnDelayTimes[i]); - DecayDelays[i] = new DecayDelay(new DelayLine(sampleRate, decayDelayTimes[i])); - } - - float preDelayTimeMax = 150.0f; - - if (isLongSizePreDelaySupported) - { - preDelayTimeMax = 350.0f; - } - - PreDelayLine = new DelayLine(sampleRate, preDelayTimeMax); - FrontCenterDelayLine = new DelayLine(sampleRate, 5.0f); - - UpdateParameter(ref parameter); - } - - public void UpdateParameter(ref ReverbParameter parameter) - { - uint sampleRate = (uint)FixedPointHelper.ToFloat((uint)parameter.SampleRate, FixedPointPrecision); - - float preDelayTimeInMilliseconds = FixedPointHelper.ToFloat(parameter.PreDelayTime, FixedPointPrecision); - float earlyGain = FixedPointHelper.ToFloat(parameter.EarlyGain, FixedPointPrecision); - float coloration = FixedPointHelper.ToFloat(parameter.Coloration, FixedPointPrecision); - float decayTime = FixedPointHelper.ToFloat(parameter.DecayTime, FixedPointPrecision); - - for (int i = 0; i < 10; i++) - { - EarlyDelayTime[i] = Math.Min(IDelayLine.GetSampleCount(sampleRate, EarlyDelayTimes[i] + preDelayTimeInMilliseconds), PreDelayLine.SampleCountMax) + 1; - EarlyGain[i] = EarlyGainBase[i] * earlyGain; - } - - if (parameter.ChannelCount == 2) - { - EarlyGain[4] = EarlyGain[4] * 0.5f; - EarlyGain[5] = EarlyGain[5] * 0.5f; - } - - PreDelayLineDelayTime = Math.Min(IDelayLine.GetSampleCount(sampleRate, PreDelayTimes[(int)parameter.EarlyMode] + preDelayTimeInMilliseconds), PreDelayLine.SampleCountMax); - - ReadOnlySpan<float> fdnDelayTimes = GetFdnDelayTimesByLateMode(parameter.LateMode); - ReadOnlySpan<float> decayDelayTimes = GetDecayDelayTimesByLateMode(parameter.LateMode); - - float highFrequencyDecayRatio = FixedPointHelper.ToFloat(parameter.HighFrequencyDecayRatio, FixedPointPrecision); - float highFrequencyUnknownValue = FloatingPointHelper.Cos(1280.0f / sampleRate); - - for (int i = 0; i < 4; i++) - { - FdnDelayLines[i].SetDelay(fdnDelayTimes[i]); - DecayDelays[i].SetDelay(decayDelayTimes[i]); - - float tempA = -3 * (DecayDelays[i].CurrentSampleCount + FdnDelayLines[i].CurrentSampleCount); - float tempB = tempA / (decayTime * sampleRate); - float tempC; - float tempD; - - if (highFrequencyDecayRatio < 0.995f) - { - float tempE = FloatingPointHelper.Pow10((((1.0f / highFrequencyDecayRatio) - 1.0f) * 2) / 100 * (tempB / 10)); - float tempF = 1.0f - tempE; - float tempG = 2.0f - (tempE * 2 * highFrequencyUnknownValue); - float tempH = MathF.Sqrt((tempG * tempG) - (tempF * tempF * 4)); - - tempC = (tempG - tempH) / (tempF * 2); - tempD = 1.0f - tempC; - } - else - { - // no high frequency decay ratio - tempC = 0.0f; - tempD = 1.0f; - } - - HighFrequencyDecayDirectGain[i] = FloatingPointHelper.Pow10(tempB / 1000) * tempD * 0.7071f; - HighFrequencyDecayPreviousGain[i] = tempC; - PreviousFeedbackOutput[i] = 0.0f; - - DecayDelays[i].SetDecayRate(0.6f * (1.0f - coloration)); - } - } - } -}
\ No newline at end of file |
