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; } }
/// <summary> /// Generate a new <see cref="Reverb3dCommand"/>. /// </summary> /// <param name="bufferOffset">The target buffer offset.</param> /// <param name="parameter">The reverb 3d parameter.</param> /// <param name="state">The reverb 3d state.</param> /// <param name="isEnabled">Set to true if the effect should be active.</param> /// <param name="workBuffer">The work buffer to use for processing.</param> /// <param name="nodeId">The node id associated to this command.</param> /// <param name="newEffectChannelMappingSupported">If set to true, the new effect channel mapping for 5.1 is supported.</param> public void GenerateReverb3dEffect(uint bufferOffset, Reverb3dParameter parameter, Memory <Reverb3dState> state, bool isEnabled, CpuAddress workBuffer, int nodeId, bool newEffectChannelMappingSupported) { if (parameter.IsChannelCountValid()) { Reverb3dCommand command = new Reverb3dCommand(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, newEffectChannelMappingSupported); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); AddCommand(command); } }
public Reverb3dCommand(uint bufferOffset, Reverb3dParameter parameter, Memory <Reverb3dState> state, bool isEnabled, ulong workBuffer, int nodeId) { Enabled = true; IsEffectEnabled = isEnabled; NodeId = nodeId; _parameter = parameter; State = state; WorkBuffer = workBuffer; InputBufferIndices = new ushort[RendererConstants.VoiceChannelCountMax]; OutputBufferIndices = new ushort[RendererConstants.VoiceChannelCountMax]; for (int i = 0; i < Parameter.ChannelCount; i++) { InputBufferIndices[i] = (ushort)(bufferOffset + Parameter.Input[i]); OutputBufferIndices[i] = (ushort)(bufferOffset + Parameter.Output[i]); } }
public Reverb3dCommand(uint bufferOffset, Reverb3dParameter parameter, Memory <Reverb3dState> state, bool isEnabled, ulong workBuffer, int nodeId, bool newEffectChannelMappingSupported) { Enabled = true; IsEffectEnabled = isEnabled; NodeId = nodeId; _parameter = parameter; State = state; WorkBuffer = workBuffer; InputBufferIndices = new ushort[Constants.VoiceChannelCountMax]; OutputBufferIndices = new ushort[Constants.VoiceChannelCountMax]; for (int i = 0; i < Parameter.ChannelCount; i++) { InputBufferIndices[i] = (ushort)(bufferOffset + Parameter.Input[i]); OutputBufferIndices[i] = (ushort)(bufferOffset + Parameter.Output[i]); } // NOTE: We do the opposite as Nintendo here for now to restore previous behaviour // TODO: Update reverb 3d processing and remove this to use RemapLegacyChannelEffectMappingToChannelResourceMapping. DataSourceHelper.RemapChannelResourceMappingToLegacy(newEffectChannelMappingSupported, InputBufferIndices); DataSourceHelper.RemapChannelResourceMappingToLegacy(newEffectChannelMappingSupported, OutputBufferIndices); }
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); }