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
This commit is contained in:
parent
1c49089ff0
commit
f556c80d02
249 changed files with 5614 additions and 2712 deletions
|
@ -0,0 +1,92 @@
|
|||
//
|
||||
// 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.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Parameter.Effect;
|
||||
using Ryujinx.Audio.Renderer.Server.MemoryPool;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using DspAddress = System.UInt64;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
{
|
||||
/// <summary>
|
||||
/// Server state for an auxiliary buffer effect.
|
||||
/// </summary>
|
||||
public class AuxiliaryBufferEffect : BaseEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The auxiliary buffer parameter.
|
||||
/// </summary>
|
||||
public AuxiliaryBufferParameter Parameter;
|
||||
|
||||
/// <summary>
|
||||
/// Auxiliary buffer state.
|
||||
/// </summary>
|
||||
public AuxiliaryBufferAddresses State;
|
||||
|
||||
public override EffectType TargetEffectType => EffectType.AuxiliaryBuffer;
|
||||
|
||||
public override DspAddress GetWorkBuffer(int index)
|
||||
{
|
||||
return WorkBuffers[index].GetReference(true);
|
||||
}
|
||||
|
||||
public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameter parameter, PoolMapper mapper)
|
||||
{
|
||||
Debug.Assert(IsTypeValid(ref parameter));
|
||||
|
||||
UpdateParameterBase(ref parameter);
|
||||
|
||||
Parameter = MemoryMarshal.Cast<byte, AuxiliaryBufferParameter>(parameter.SpecificData)[0];
|
||||
IsEnabled = parameter.IsEnabled;
|
||||
|
||||
updateErrorInfo = new BehaviourParameter.ErrorInfo();
|
||||
|
||||
if (BufferUnmapped || parameter.IsNew)
|
||||
{
|
||||
ulong bufferSize = (ulong)Unsafe.SizeOf<int>() * Parameter.BufferStorageSize + (ulong)Unsafe.SizeOf<AuxiliaryBufferHeader>() * 2;
|
||||
|
||||
bool sendBufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[0], Parameter.SendBufferInfoAddress, bufferSize);
|
||||
bool returnBufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[1], Parameter.ReturnBufferInfoAddress, bufferSize);
|
||||
|
||||
BufferUnmapped = sendBufferUnmapped && returnBufferUnmapped;
|
||||
|
||||
if (!BufferUnmapped)
|
||||
{
|
||||
DspAddress sendDspAddress = WorkBuffers[0].GetReference(false);
|
||||
DspAddress returnDspAddress = WorkBuffers[1].GetReference(false);
|
||||
|
||||
State.SendBufferInfo = sendDspAddress + (uint)Unsafe.SizeOf<AuxiliaryBufferHeader>();
|
||||
State.SendBufferInfoBase = sendDspAddress + (uint)Unsafe.SizeOf<AuxiliaryBufferHeader>() * 2;
|
||||
|
||||
State.ReturnBufferInfo = returnDspAddress + (uint)Unsafe.SizeOf<AuxiliaryBufferHeader>();
|
||||
State.ReturnBufferInfoBase = returnDspAddress + (uint)Unsafe.SizeOf<AuxiliaryBufferHeader>() * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateForCommandGeneration()
|
||||
{
|
||||
UpdateUsageStateForCommandGeneration();
|
||||
}
|
||||
}
|
||||
}
|
257
Ryujinx.Audio/Renderer/Server/Effect/BaseEffect.cs
Normal file
257
Ryujinx.Audio/Renderer/Server/Effect/BaseEffect.cs
Normal file
|
@ -0,0 +1,257 @@
|
|||
//
|
||||
// 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.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Server.MemoryPool;
|
||||
using Ryujinx.Audio.Renderer.Utils;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using static Ryujinx.Audio.Renderer.Common.BehaviourParameter;
|
||||
|
||||
using DspAddress = System.UInt64;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class used as a server state for an effect.
|
||||
/// </summary>
|
||||
public class BaseEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="EffectType"/> of the effect.
|
||||
/// </summary>
|
||||
public EffectType Type;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if the effect must be active.
|
||||
/// </summary>
|
||||
public bool IsEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if the internal effect work buffers used wasn't mapped.
|
||||
/// </summary>
|
||||
public bool BufferUnmapped;
|
||||
|
||||
/// <summary>
|
||||
/// The current state of the effect.
|
||||
/// </summary>
|
||||
public UsageState UsageState;
|
||||
|
||||
/// <summary>
|
||||
/// The target mix id of the effect.
|
||||
/// </summary>
|
||||
public int MixId;
|
||||
|
||||
/// <summary>
|
||||
/// Position of the effect while processing effects.
|
||||
/// </summary>
|
||||
public uint ProcessingOrder;
|
||||
|
||||
/// <summary>
|
||||
/// Array of all the work buffer used by the effect.
|
||||
/// </summary>
|
||||
protected AddressInfo[] WorkBuffers;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="BaseEffect"/>.
|
||||
/// </summary>
|
||||
public BaseEffect()
|
||||
{
|
||||
Type = TargetEffectType;
|
||||
UsageState = UsageState.Invalid;
|
||||
|
||||
IsEnabled = false;
|
||||
BufferUnmapped = false;
|
||||
MixId = Constants.UnusedMixId;
|
||||
ProcessingOrder = uint.MaxValue;
|
||||
|
||||
WorkBuffers = new AddressInfo[2];
|
||||
|
||||
foreach (ref AddressInfo info in WorkBuffers.AsSpan())
|
||||
{
|
||||
info = AddressInfo.Create();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The target <see cref="EffectType"/> handled by this <see cref="BaseEffect"/>.
|
||||
/// </summary>
|
||||
public virtual EffectType TargetEffectType => EffectType.Invalid;
|
||||
|
||||
/// <summary>
|
||||
/// Check if the <see cref="EffectType"/> sent by the user match the internal <see cref="EffectType"/>.
|
||||
/// </summary>
|
||||
/// <param name="parameter">The user parameter.</param>
|
||||
/// <returns>Returns true if the <see cref="EffectType"/> sent by the user matches the internal <see cref="EffectType"/>.</returns>
|
||||
public bool IsTypeValid(ref EffectInParameter parameter)
|
||||
{
|
||||
return parameter.Type == TargetEffectType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the usage state during command generation.
|
||||
/// </summary>
|
||||
protected void UpdateUsageStateForCommandGeneration()
|
||||
{
|
||||
UsageState = IsEnabled ? UsageState.Enabled : UsageState.Disabled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the internal common parameters from a user parameter.
|
||||
/// </summary>
|
||||
/// <param name="parameter">The user parameter.</param>
|
||||
protected void UpdateParameterBase(ref EffectInParameter parameter)
|
||||
{
|
||||
MixId = parameter.MixId;
|
||||
ProcessingOrder = parameter.ProcessingOrder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Force unmap all the work buffers.
|
||||
/// </summary>
|
||||
/// <param name="mapper">The mapper to use.</param>
|
||||
public void ForceUnmapBuffers(PoolMapper mapper)
|
||||
{
|
||||
foreach (ref AddressInfo info in WorkBuffers.AsSpan())
|
||||
{
|
||||
if (info.GetReference(false) != 0)
|
||||
{
|
||||
mapper.ForceUnmap(ref info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the effect needs to be skipped.
|
||||
/// </summary>
|
||||
/// <returns>Returns true if the effect needs to be skipped.</returns>
|
||||
public bool ShouldSkip()
|
||||
{
|
||||
return BufferUnmapped;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the <see cref="BaseEffect"/> state during command generation.
|
||||
/// </summary>
|
||||
public virtual void UpdateForCommandGeneration()
|
||||
{
|
||||
Debug.Assert(Type == TargetEffectType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the internal state from a user parameter.
|
||||
/// </summary>
|
||||
/// <param name="updateErrorInfo">The possible <see cref="ErrorInfo"/> that was generated.</param>
|
||||
/// <param name="parameter">The user parameter.</param>
|
||||
/// <param name="mapper">The mapper to use.</param>
|
||||
public virtual void Update(out ErrorInfo updateErrorInfo, ref EffectInParameter parameter, PoolMapper mapper)
|
||||
{
|
||||
Debug.Assert(IsTypeValid(ref parameter));
|
||||
|
||||
updateErrorInfo = new ErrorInfo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the work buffer DSP address at the given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the work buffer</param>
|
||||
/// <returns>The work buffer DSP address at the given index.</returns>
|
||||
public virtual DspAddress GetWorkBuffer(int index)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the first work buffer DSP address.
|
||||
/// </summary>
|
||||
/// <returns>The first work buffer DSP address.</returns>
|
||||
protected DspAddress GetSingleBuffer()
|
||||
{
|
||||
if (IsEnabled)
|
||||
{
|
||||
return WorkBuffers[0].GetReference(true);
|
||||
}
|
||||
|
||||
if (UsageState != UsageState.Disabled)
|
||||
{
|
||||
DspAddress address = WorkBuffers[0].GetReference(false);
|
||||
ulong size = WorkBuffers[0].Size;
|
||||
|
||||
if (address != 0 && size != 0)
|
||||
{
|
||||
AudioProcessorMemoryManager.InvalidateDataCache(address, size);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Store the output status to the given user output.
|
||||
/// </summary>
|
||||
/// <param name="outStatus">The given user output.</param>
|
||||
/// <param name="isAudioRendererActive">If set to true, the <see cref="AudioRenderSystem"/> is active.</param>
|
||||
public void StoreStatus(ref EffectOutStatus outStatus, bool isAudioRendererActive)
|
||||
{
|
||||
if (isAudioRendererActive)
|
||||
{
|
||||
if (UsageState == UsageState.Disabled)
|
||||
{
|
||||
outStatus.State = EffectOutStatus.EffectState.Disabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
outStatus.State = EffectOutStatus.EffectState.Enabled;
|
||||
}
|
||||
}
|
||||
else if (UsageState == UsageState.New)
|
||||
{
|
||||
outStatus.State = EffectOutStatus.EffectState.Enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
outStatus.State = EffectOutStatus.EffectState.Disabled;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the <see cref="PerformanceDetailType"/> associated to the <see cref="Type"/> of this effect.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="PerformanceDetailType"/> associated to the <see cref="Type"/> of this effect.</returns>
|
||||
public PerformanceDetailType GetPerformanceDetailType()
|
||||
{
|
||||
switch (Type)
|
||||
{
|
||||
case EffectType.BiquadFilter:
|
||||
return PerformanceDetailType.BiquadFilter;
|
||||
case EffectType.AuxiliaryBuffer:
|
||||
return PerformanceDetailType.Aux;
|
||||
case EffectType.Delay:
|
||||
return PerformanceDetailType.Delay;
|
||||
case EffectType.Reverb:
|
||||
return PerformanceDetailType.Reverb;
|
||||
case EffectType.Reverb3d:
|
||||
return PerformanceDetailType.Reverb3d;
|
||||
case EffectType.BufferMix:
|
||||
return PerformanceDetailType.Mix;
|
||||
default:
|
||||
throw new NotImplementedException($"{Type}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
74
Ryujinx.Audio/Renderer/Server/Effect/BiquadFilterEffect.cs
Normal file
74
Ryujinx.Audio/Renderer/Server/Effect/BiquadFilterEffect.cs
Normal file
|
@ -0,0 +1,74 @@
|
|||
//
|
||||
// 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.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Parameter.Effect;
|
||||
using Ryujinx.Audio.Renderer.Server.MemoryPool;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
{
|
||||
/// <summary>
|
||||
/// Server state for a biquad filter effect.
|
||||
/// </summary>
|
||||
public class BiquadFilterEffect : BaseEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The biquad filter parameter.
|
||||
/// </summary>
|
||||
public BiquadFilterEffectParameter Parameter;
|
||||
|
||||
/// <summary>
|
||||
/// The biquad filter state.
|
||||
/// </summary>
|
||||
public Memory<BiquadFilterState> State { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="BiquadFilterEffect"/>.
|
||||
/// </summary>
|
||||
public BiquadFilterEffect()
|
||||
{
|
||||
Parameter = new BiquadFilterEffectParameter();
|
||||
State = new BiquadFilterState[Constants.ChannelCountMax];
|
||||
}
|
||||
|
||||
public override EffectType TargetEffectType => EffectType.BiquadFilter;
|
||||
|
||||
public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameter parameter, PoolMapper mapper)
|
||||
{
|
||||
Debug.Assert(IsTypeValid(ref parameter));
|
||||
|
||||
UpdateParameterBase(ref parameter);
|
||||
|
||||
Parameter = MemoryMarshal.Cast<byte, BiquadFilterEffectParameter>(parameter.SpecificData)[0];
|
||||
IsEnabled = parameter.IsEnabled;
|
||||
|
||||
updateErrorInfo = new BehaviourParameter.ErrorInfo();
|
||||
}
|
||||
|
||||
public override void UpdateForCommandGeneration()
|
||||
{
|
||||
UpdateUsageStateForCommandGeneration();
|
||||
|
||||
Parameter.Status = UsageState.Enabled;
|
||||
}
|
||||
}
|
||||
}
|
56
Ryujinx.Audio/Renderer/Server/Effect/BufferMixEffect.cs
Normal file
56
Ryujinx.Audio/Renderer/Server/Effect/BufferMixEffect.cs
Normal file
|
@ -0,0 +1,56 @@
|
|||
//
|
||||
// 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.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Parameter.Effect;
|
||||
using Ryujinx.Audio.Renderer.Server.MemoryPool;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
{
|
||||
/// <summary>
|
||||
/// Server state for a buffer mix effect.
|
||||
/// </summary>
|
||||
public class BufferMixEffect : BaseEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The buffer mix parameter.
|
||||
/// </summary>
|
||||
public BufferMixParameter Parameter;
|
||||
|
||||
public override EffectType TargetEffectType => EffectType.BufferMix;
|
||||
|
||||
public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameter parameter, PoolMapper mapper)
|
||||
{
|
||||
Debug.Assert(IsTypeValid(ref parameter));
|
||||
|
||||
UpdateParameterBase(ref parameter);
|
||||
|
||||
Parameter = MemoryMarshal.Cast<byte, BufferMixParameter>(parameter.SpecificData)[0];
|
||||
IsEnabled = parameter.IsEnabled;
|
||||
|
||||
updateErrorInfo = new BehaviourParameter.ErrorInfo();
|
||||
}
|
||||
|
||||
public override void UpdateForCommandGeneration()
|
||||
{
|
||||
UpdateUsageStateForCommandGeneration();
|
||||
}
|
||||
}
|
||||
}
|
100
Ryujinx.Audio/Renderer/Server/Effect/DelayEffect.cs
Normal file
100
Ryujinx.Audio/Renderer/Server/Effect/DelayEffect.cs
Normal file
|
@ -0,0 +1,100 @@
|
|||
//
|
||||
// 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.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Parameter.Effect;
|
||||
using Ryujinx.Audio.Renderer.Server.MemoryPool;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using DspAddress = System.UInt64;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
{
|
||||
/// <summary>
|
||||
/// Server state for a delay effect.
|
||||
/// </summary>
|
||||
public class DelayEffect : BaseEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The delay parameter.
|
||||
/// </summary>
|
||||
public DelayParameter Parameter;
|
||||
|
||||
/// <summary>
|
||||
/// The delay state.
|
||||
/// </summary>
|
||||
public Memory<DelayState> State { get; }
|
||||
|
||||
public DelayEffect()
|
||||
{
|
||||
State = new DelayState[1];
|
||||
}
|
||||
|
||||
public override EffectType TargetEffectType => EffectType.Delay;
|
||||
|
||||
public override DspAddress GetWorkBuffer(int index)
|
||||
{
|
||||
return GetSingleBuffer();
|
||||
}
|
||||
|
||||
public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameter parameter, PoolMapper mapper)
|
||||
{
|
||||
Debug.Assert(IsTypeValid(ref parameter));
|
||||
|
||||
ref DelayParameter delayParameter = ref MemoryMarshal.Cast<byte, DelayParameter>(parameter.SpecificData)[0];
|
||||
|
||||
updateErrorInfo = new BehaviourParameter.ErrorInfo();
|
||||
|
||||
if (delayParameter.IsChannelCountMaxValid())
|
||||
{
|
||||
UpdateParameterBase(ref parameter);
|
||||
|
||||
UsageState oldParameterStatus = Parameter.Status;
|
||||
|
||||
Parameter = delayParameter;
|
||||
|
||||
if (delayParameter.IsChannelCountValid())
|
||||
{
|
||||
IsEnabled = parameter.IsEnabled;
|
||||
|
||||
if (oldParameterStatus != UsageState.Enabled)
|
||||
{
|
||||
Parameter.Status = oldParameterStatus;
|
||||
}
|
||||
|
||||
if (BufferUnmapped || parameter.IsNew)
|
||||
{
|
||||
UsageState = UsageState.New;
|
||||
Parameter.Status = UsageState.Invalid;
|
||||
|
||||
BufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[0], parameter.BufferBase, parameter.BufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateForCommandGeneration()
|
||||
{
|
||||
UpdateUsageStateForCommandGeneration();
|
||||
|
||||
Parameter.Status = UsageState.Enabled;
|
||||
}
|
||||
}
|
||||
}
|
82
Ryujinx.Audio/Renderer/Server/Effect/EffectContext.cs
Normal file
82
Ryujinx.Audio/Renderer/Server/Effect/EffectContext.cs
Normal file
|
@ -0,0 +1,82 @@
|
|||
//
|
||||
// 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.Diagnostics;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
{
|
||||
/// <summary>
|
||||
/// Effect context.
|
||||
/// </summary>
|
||||
public class EffectContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Storage for <see cref="BaseEffect"/>.
|
||||
/// </summary>
|
||||
private BaseEffect[] _effects;
|
||||
|
||||
/// <summary>
|
||||
/// The total effect count.
|
||||
/// </summary>
|
||||
private uint _effectCount;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="EffectContext"/>.
|
||||
/// </summary>
|
||||
public EffectContext()
|
||||
{
|
||||
_effects = null;
|
||||
_effectCount = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the <see cref="EffectContext"/>.
|
||||
/// </summary>
|
||||
/// <param name="effectCount">The total effect count.</param>
|
||||
public void Initialize(uint effectCount)
|
||||
{
|
||||
_effectCount = effectCount;
|
||||
_effects = new BaseEffect[effectCount];
|
||||
|
||||
for (int i = 0; i < _effectCount; i++)
|
||||
{
|
||||
_effects[i] = new BaseEffect();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the total effect count.
|
||||
/// </summary>
|
||||
/// <returns>The total effect count.</returns>
|
||||
public uint GetCount()
|
||||
{
|
||||
return _effectCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a reference to a <see cref="BaseEffect"/> at the given <paramref name="index"/>.
|
||||
/// </summary>
|
||||
/// <param name="index">The index to use.</param>
|
||||
/// <returns>A reference to a <see cref="BaseEffect"/> at the given <paramref name="index"/>.</returns>
|
||||
public ref BaseEffect GetEffect(int index)
|
||||
{
|
||||
Debug.Assert(index >= 0 && index < _effectCount);
|
||||
|
||||
return ref _effects[index];
|
||||
}
|
||||
}
|
||||
}
|
99
Ryujinx.Audio/Renderer/Server/Effect/Reverb3dEffect.cs
Normal file
99
Ryujinx.Audio/Renderer/Server/Effect/Reverb3dEffect.cs
Normal file
|
@ -0,0 +1,99 @@
|
|||
//
|
||||
// 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.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Parameter.Effect;
|
||||
using Ryujinx.Audio.Renderer.Server.MemoryPool;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
{
|
||||
/// <summary>
|
||||
/// Server state for a 3D reverberation effect.
|
||||
/// </summary>
|
||||
public class Reverb3dEffect : BaseEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The 3D reverberation parameter.
|
||||
/// </summary>
|
||||
public Reverb3dParameter Parameter;
|
||||
|
||||
/// <summary>
|
||||
/// The 3D reverberation state.
|
||||
/// </summary>
|
||||
public Memory<Reverb3dState> State { get; }
|
||||
|
||||
public Reverb3dEffect()
|
||||
{
|
||||
State = new Reverb3dState[1];
|
||||
}
|
||||
|
||||
public override EffectType TargetEffectType => EffectType.Reverb3d;
|
||||
|
||||
public override ulong GetWorkBuffer(int index)
|
||||
{
|
||||
return GetSingleBuffer();
|
||||
}
|
||||
|
||||
public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameter parameter, PoolMapper mapper)
|
||||
{
|
||||
Debug.Assert(IsTypeValid(ref parameter));
|
||||
|
||||
ref Reverb3dParameter reverbParameter = ref MemoryMarshal.Cast<byte, Reverb3dParameter>(parameter.SpecificData)[0];
|
||||
|
||||
updateErrorInfo = new BehaviourParameter.ErrorInfo();
|
||||
|
||||
if (reverbParameter.IsChannelCountMaxValid())
|
||||
{
|
||||
UpdateParameterBase(ref parameter);
|
||||
|
||||
UsageState oldParameterStatus = Parameter.ParameterStatus;
|
||||
|
||||
Parameter = reverbParameter;
|
||||
|
||||
if (reverbParameter.IsChannelCountValid())
|
||||
{
|
||||
IsEnabled = parameter.IsEnabled;
|
||||
|
||||
if (oldParameterStatus != UsageState.Enabled)
|
||||
{
|
||||
Parameter.ParameterStatus = oldParameterStatus;
|
||||
}
|
||||
|
||||
if (BufferUnmapped || parameter.IsNew)
|
||||
{
|
||||
UsageState = UsageState.New;
|
||||
Parameter.ParameterStatus = UsageState.Invalid;
|
||||
|
||||
BufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[0], parameter.BufferBase, parameter.BufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateForCommandGeneration()
|
||||
{
|
||||
UpdateUsageStateForCommandGeneration();
|
||||
|
||||
Parameter.ParameterStatus = UsageState.Enabled;
|
||||
}
|
||||
}
|
||||
}
|
102
Ryujinx.Audio/Renderer/Server/Effect/ReverbEffect.cs
Normal file
102
Ryujinx.Audio/Renderer/Server/Effect/ReverbEffect.cs
Normal file
|
@ -0,0 +1,102 @@
|
|||
//
|
||||
// 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.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Parameter.Effect;
|
||||
using Ryujinx.Audio.Renderer.Server.MemoryPool;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
{
|
||||
/// <summary>
|
||||
/// Server state for a reverberation effect.
|
||||
/// </summary>
|
||||
public class ReverbEffect : BaseEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The reverberation parameter.
|
||||
/// </summary>
|
||||
public ReverbParameter Parameter;
|
||||
|
||||
/// <summary>
|
||||
/// The reverberation state.
|
||||
/// </summary>
|
||||
public Memory<ReverbState> State { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="ReverbEffect"/>.
|
||||
/// </summary>
|
||||
public ReverbEffect()
|
||||
{
|
||||
State = new ReverbState[1];
|
||||
}
|
||||
|
||||
public override EffectType TargetEffectType => EffectType.Reverb;
|
||||
|
||||
public override ulong GetWorkBuffer(int index)
|
||||
{
|
||||
return GetSingleBuffer();
|
||||
}
|
||||
|
||||
public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameter parameter, PoolMapper mapper)
|
||||
{
|
||||
Debug.Assert(IsTypeValid(ref parameter));
|
||||
|
||||
ref ReverbParameter reverbParameter = ref MemoryMarshal.Cast<byte, ReverbParameter>(parameter.SpecificData)[0];
|
||||
|
||||
updateErrorInfo = new BehaviourParameter.ErrorInfo();
|
||||
|
||||
if (reverbParameter.IsChannelCountMaxValid())
|
||||
{
|
||||
UpdateParameterBase(ref parameter);
|
||||
|
||||
UsageState oldParameterStatus = Parameter.Status;
|
||||
|
||||
Parameter = reverbParameter;
|
||||
|
||||
if (reverbParameter.IsChannelCountValid())
|
||||
{
|
||||
IsEnabled = parameter.IsEnabled;
|
||||
|
||||
if (oldParameterStatus != UsageState.Enabled)
|
||||
{
|
||||
Parameter.Status = oldParameterStatus;
|
||||
}
|
||||
|
||||
if (BufferUnmapped || parameter.IsNew)
|
||||
{
|
||||
UsageState = UsageState.New;
|
||||
Parameter.Status = UsageState.Invalid;
|
||||
|
||||
BufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[0], parameter.BufferBase, parameter.BufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void UpdateForCommandGeneration()
|
||||
{
|
||||
UpdateUsageStateForCommandGeneration();
|
||||
|
||||
Parameter.Status = UsageState.Enabled;
|
||||
}
|
||||
}
|
||||
}
|
45
Ryujinx.Audio/Renderer/Server/Effect/UsageState.cs
Normal file
45
Ryujinx.Audio/Renderer/Server/Effect/UsageState.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// 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/>.
|
||||
//
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
{
|
||||
/// <summary>
|
||||
/// The usage state of an effect.
|
||||
/// </summary>
|
||||
public enum UsageState : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// The effect is in an invalid state.
|
||||
/// </summary>
|
||||
Invalid,
|
||||
|
||||
/// <summary>
|
||||
/// The effect is new.
|
||||
/// </summary>
|
||||
New,
|
||||
|
||||
/// <summary>
|
||||
/// The effect is enabled.
|
||||
/// </summary>
|
||||
Enabled,
|
||||
|
||||
/// <summary>
|
||||
/// The effect is disabled.
|
||||
/// </summary>
|
||||
Disabled
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue