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; } }
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)); } }