diff options
| author | Mary <me@thog.eu> | 2021-02-26 01:11:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-26 01:11:56 +0100 |
| commit | f556c80d0230056335632b60c71f1567e177239e (patch) | |
| tree | 748aa6be62b93a8e941e25dbd83f39e1dbb37035 /Ryujinx.Audio.Renderer/Dsp/State | |
| parent | 1c49089ff00fc87dc4872f135dc6a0d36169a970 (diff) | |
Haydn: Part 1 (#2007)
* Haydn: Part 1
Based on my reverse of audio 11.0.0.
As always, core implementation under LGPLv3 for the same reasons as for Amadeus.
This place the bases of a more flexible audio system while making audout & audin accurate.
This have the following improvements:
- Complete reimplementation of audout and audin.
- Audin currently only have a dummy backend.
- Dramatically reduce CPU usage by up to 50% in common cases (SoundIO and OpenAL).
- Audio Renderer now can output to 5.1 devices when supported.
- Audio Renderer init its backend on demand instead of keeping two up all the time.
- All backends implementation are now in their own project.
- Ryujinx.Audio.Renderer was renamed Ryujinx.Audio and was refactored because of this.
As a note, games having issues with OpenAL haven't improved and will not
because of OpenAL design (stopping when buffers finish playing causing
possible audio "pops" when buffers are very small).
* Update for latest hexkyz's edits on Switchbrew
* audren: Rollback channel configuration changes
* Address gdkchan's comments
* Fix typo in OpenAL backend driver
* Address last comments
* Fix a nit
* Address gdkchan's comments
Diffstat (limited to 'Ryujinx.Audio.Renderer/Dsp/State')
| -rw-r--r-- | Ryujinx.Audio.Renderer/Dsp/State/AdpcmLoopContext.cs | 29 | ||||
| -rw-r--r-- | Ryujinx.Audio.Renderer/Dsp/State/AuxiliaryBufferHeader.cs | 60 | ||||
| -rw-r--r-- | Ryujinx.Audio.Renderer/Dsp/State/BiquadFilterState.cs | 28 | ||||
| -rw-r--r-- | Ryujinx.Audio.Renderer/Dsp/State/DelayState.cs | 73 | ||||
| -rw-r--r-- | Ryujinx.Audio.Renderer/Dsp/State/Reverb3dState.cs | 136 | ||||
| -rw-r--r-- | Ryujinx.Audio.Renderer/Dsp/State/ReverbState.cs | 221 |
6 files changed, 0 insertions, 547 deletions
diff --git a/Ryujinx.Audio.Renderer/Dsp/State/AdpcmLoopContext.cs b/Ryujinx.Audio.Renderer/Dsp/State/AdpcmLoopContext.cs deleted file mode 100644 index 695b32d2..00000000 --- a/Ryujinx.Audio.Renderer/Dsp/State/AdpcmLoopContext.cs +++ /dev/null @@ -1,29 +0,0 @@ -// -// Copyright (c) 2019-2021 Ryujinx -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. -// - -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; - } -} diff --git a/Ryujinx.Audio.Renderer/Dsp/State/AuxiliaryBufferHeader.cs b/Ryujinx.Audio.Renderer/Dsp/State/AuxiliaryBufferHeader.cs deleted file mode 100644 index 3cf24302..00000000 --- a/Ryujinx.Audio.Renderer/Dsp/State/AuxiliaryBufferHeader.cs +++ /dev/null @@ -1,60 +0,0 @@ -// -// Copyright (c) 2019-2021 Ryujinx -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. -// - -using Ryujinx.Memory; -using System.Runtime.InteropServices; - -namespace Ryujinx.Audio.Renderer.Dsp.State -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x40)] - public struct AuxiliaryBufferHeader - { - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0xC)] - public struct AuxiliaryBufferInfo - { - private const uint ReadOffsetPosition = 0x0; - private const uint WriteOffsetPosition = 0x4; - - public uint ReadOffset; - public uint WriteOffset; - private uint _reserved; - - 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 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 AuxiliaryBufferInfo BufferInfo; - public unsafe fixed uint Unknown[13]; - } -} diff --git a/Ryujinx.Audio.Renderer/Dsp/State/BiquadFilterState.cs b/Ryujinx.Audio.Renderer/Dsp/State/BiquadFilterState.cs deleted file mode 100644 index 9677333d..00000000 --- a/Ryujinx.Audio.Renderer/Dsp/State/BiquadFilterState.cs +++ /dev/null @@ -1,28 +0,0 @@ -// -// Copyright (c) 2019-2021 Ryujinx -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. -// - -using System.Runtime.InteropServices; - -namespace Ryujinx.Audio.Renderer.Dsp.State -{ - [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x10)] - public struct BiquadFilterState - { - public float Z1; - public float Z2; - } -} diff --git a/Ryujinx.Audio.Renderer/Dsp/State/DelayState.cs b/Ryujinx.Audio.Renderer/Dsp/State/DelayState.cs deleted file mode 100644 index 7b694fb0..00000000 --- a/Ryujinx.Audio.Renderer/Dsp/State/DelayState.cs +++ /dev/null @@ -1,73 +0,0 @@ -// -// Copyright (c) 2019-2021 Ryujinx -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. -// - -using Ryujinx.Audio.Renderer.Dsp.Effect; -using Ryujinx.Audio.Renderer.Parameter.Effect; - -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); - LowPassZ[0] = 0; - } - - 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; - } - } -} diff --git a/Ryujinx.Audio.Renderer/Dsp/State/Reverb3dState.cs b/Ryujinx.Audio.Renderer/Dsp/State/Reverb3dState.cs deleted file mode 100644 index be0f9734..00000000 --- a/Ryujinx.Audio.Renderer/Dsp/State/Reverb3dState.cs +++ /dev/null @@ -1,136 +0,0 @@ -// -// Copyright (c) 2019-2021 Ryujinx -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. -// - -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 BackLeftDelayLine { 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); - BackLeftDelayLine = 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; - } - } - } -} diff --git a/Ryujinx.Audio.Renderer/Dsp/State/ReverbState.cs b/Ryujinx.Audio.Renderer/Dsp/State/ReverbState.cs deleted file mode 100644 index 60d8e284..00000000 --- a/Ryujinx.Audio.Renderer/Dsp/State/ReverbState.cs +++ /dev/null @@ -1,221 +0,0 @@ -// -// Copyright (c) 2019-2021 Ryujinx -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see <https://www.gnu.org/licenses/>. -// - -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 IDelayLine[] FdnDelayLines { get; } - public DecayDelay[] DecayDelays { get; } - public IDelayLine PreDelayLine { get; } - public IDelayLine BackLeftDelayLine { 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().Slice((int)lateMode * 4, 4); - } - - private ReadOnlySpan<float> GetDecayDelayTimesByLateMode(ReverbLateMode lateMode) - { - return DecayDelayTimes.AsSpan().Slice((int)lateMode * 4, 4); - } - - public ReverbState(ref ReverbParameter parameter, ulong workBuffer, bool isLongSizePreDelaySupported) - { - FdnDelayLines = new IDelayLine[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); - BackLeftDelayLine = 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)); - } - } - } -} |
