Example #1
0
        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);
        }
Example #2
0
        public DelayLine(uint sampleRate, float delayTimeMax)
        {
            _sampleRate    = sampleRate;
            SampleCountMax = IDelayLine.GetSampleCount(_sampleRate, delayTimeMax);
            _workBuffer    = new float[SampleCountMax];

            SetDelay(delayTimeMax);
        }
Example #3
0
        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;
            }
        }
Example #4
0
        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);
        }
Example #5
0
 public float TapUnsafe(uint sampleIndex, int offset)
 {
     return(IDelayLine.Tap(_workBuffer, (int)_currentSampleIndex, (int)sampleIndex + offset, (int)CurrentSampleCount));
 }
Example #6
0
 public void SetDelay(float delayTime)
 {
     ConfigureDelay(IDelayLine.GetSampleCount(_sampleRate, delayTime));
 }
Example #7
0
        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));
            }
        }
Example #8
0
 public DecayDelay(IDelayLine delayLine)
 {
     _decayRate = 0.0f;
     _delayLine = delayLine;
 }
Example #9
0
 public float TapUnsafe(uint sampleIndex, int offset)
 {
     return(IDelayLine.Tap(_workBuffer, (int)_lastSampleIndex, (int)sampleIndex + offset, (int)SampleCountMax + 1));
 }