diff --git a/src/Ryujinx.Audio/AudioManager.cs b/src/Ryujinx.Audio/AudioManager.cs index 9f2a05b09..370d3d098 100644 --- a/src/Ryujinx.Audio/AudioManager.cs +++ b/src/Ryujinx.Audio/AudioManager.cs @@ -16,17 +16,17 @@ namespace Ryujinx.Audio /// /// Events signaled when the driver played audio buffers. /// - private ManualResetEvent[] _updateRequiredEvents; + private readonly ManualResetEvent[] _updateRequiredEvents; /// /// Action to execute when the driver played audio buffers. /// - private Action[] _actions; + private readonly Action[] _actions; /// /// The worker thread in charge of handling sessions update. /// - private Thread _workerThread; + private readonly Thread _workerThread; private bool _isRunning; @@ -44,7 +44,7 @@ namespace Ryujinx.Audio _workerThread = new Thread(Update) { - Name = "AudioManager.Worker" + Name = "AudioManager.Worker", }; } @@ -115,6 +115,7 @@ namespace Ryujinx.Audio public void Dispose() { + GC.SuppressFinalize(this); Dispose(true); } @@ -129,4 +130,4 @@ namespace Ryujinx.Audio } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Backends/Common/BackendHelper.cs b/src/Ryujinx.Audio/Backends/Common/BackendHelper.cs index 30db340fa..124d8364f 100644 --- a/src/Ryujinx.Audio/Backends/Common/BackendHelper.cs +++ b/src/Ryujinx.Audio/Backends/Common/BackendHelper.cs @@ -23,4 +23,4 @@ namespace Ryujinx.Audio.Backends.Common return bufferSize / GetSampleSize(format) / channelCount; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Backends/Common/DynamicRingBuffer.cs b/src/Ryujinx.Audio/Backends/Common/DynamicRingBuffer.cs index d17303cd3..05dd2162a 100644 --- a/src/Ryujinx.Audio/Backends/Common/DynamicRingBuffer.cs +++ b/src/Ryujinx.Audio/Backends/Common/DynamicRingBuffer.cs @@ -163,4 +163,4 @@ namespace Ryujinx.Audio.Backends.Common } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Backends/Common/HardwareDeviceSessionOutputBase.cs b/src/Ryujinx.Audio/Backends/Common/HardwareDeviceSessionOutputBase.cs index 6fb3bee02..5599c0827 100644 --- a/src/Ryujinx.Audio/Backends/Common/HardwareDeviceSessionOutputBase.cs +++ b/src/Ryujinx.Audio/Backends/Common/HardwareDeviceSessionOutputBase.cs @@ -66,14 +66,11 @@ namespace Ryujinx.Audio.Backends.Common return false; } - if (buffer.Data == null) - { - buffer.Data = samples; - } + buffer.Data ??= samples; return true; } public virtual void UnregisterBuffer(AudioBuffer buffer) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Backends/CompatLayer/CompatLayerHardwareDeviceDriver.cs b/src/Ryujinx.Audio/Backends/CompatLayer/CompatLayerHardwareDeviceDriver.cs index 22919f1e1..3f3806c3e 100644 --- a/src/Ryujinx.Audio/Backends/CompatLayer/CompatLayerHardwareDeviceDriver.cs +++ b/src/Ryujinx.Audio/Backends/CompatLayer/CompatLayerHardwareDeviceDriver.cs @@ -6,14 +6,13 @@ using Ryujinx.Common.Logging; using Ryujinx.Memory; using System; using System.Threading; - using static Ryujinx.Audio.Integration.IHardwareDeviceDriver; namespace Ryujinx.Audio.Backends.CompatLayer { public class CompatLayerHardwareDeviceDriver : IHardwareDeviceDriver { - private IHardwareDeviceDriver _realDriver; + private readonly IHardwareDeviceDriver _realDriver; public static bool IsSupported => true; @@ -24,6 +23,7 @@ namespace Ryujinx.Audio.Backends.CompatLayer public void Dispose() { + GC.SuppressFinalize(this); _realDriver.Dispose(); } @@ -49,7 +49,7 @@ namespace Ryujinx.Audio.Backends.CompatLayer 6 => SelectHardwareChannelCount(2), 2 => SelectHardwareChannelCount(1), 1 => throw new ArgumentException("No valid channel configuration found!"), - _ => throw new ArgumentException($"Invalid targetChannelCount {targetChannelCount}") + _ => throw new ArgumentException($"Invalid targetChannelCount {targetChannelCount}"), }; } @@ -110,7 +110,7 @@ namespace Ryujinx.Audio.Backends.CompatLayer { Logger.Warning?.Print(LogClass.Audio, "The selected audio backend doesn't support audio input, fallback to dummy..."); - return new DummyHardwareDeviceSessionInput(this, memoryManager, sampleFormat, sampleRate, channelCount); + return new DummyHardwareDeviceSessionInput(this, memoryManager); } throw new NotImplementedException(); @@ -138,12 +138,12 @@ namespace Ryujinx.Audio.Backends.CompatLayer if (direction == Direction.Input) { - Logger.Warning?.Print(LogClass.Audio, $"The selected audio backend doesn't support the requested audio input configuration, fallback to dummy..."); + Logger.Warning?.Print(LogClass.Audio, "The selected audio backend doesn't support the requested audio input configuration, fallback to dummy..."); // TODO: We currently don't support audio input upsampling/downsampling, implement this. realSession.Dispose(); - return new DummyHardwareDeviceSessionInput(this, memoryManager, sampleFormat, sampleRate, channelCount); + return new DummyHardwareDeviceSessionInput(this, memoryManager); } // It must be a HardwareDeviceSessionOutputBase. @@ -183,4 +183,4 @@ namespace Ryujinx.Audio.Backends.CompatLayer return direction == Direction.Input || direction == Direction.Output; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Backends/CompatLayer/CompatLayerHardwareDeviceSession.cs b/src/Ryujinx.Audio/Backends/CompatLayer/CompatLayerHardwareDeviceSession.cs index f22a7a690..a9acabec9 100644 --- a/src/Ryujinx.Audio/Backends/CompatLayer/CompatLayerHardwareDeviceSession.cs +++ b/src/Ryujinx.Audio/Backends/CompatLayer/CompatLayerHardwareDeviceSession.cs @@ -8,9 +8,9 @@ namespace Ryujinx.Audio.Backends.CompatLayer { class CompatLayerHardwareDeviceSession : HardwareDeviceSessionOutputBase { - private HardwareDeviceSessionOutputBase _realSession; - private SampleFormat _userSampleFormat; - private uint _userChannelCount; + private readonly HardwareDeviceSessionOutputBase _realSession; + private readonly SampleFormat _userSampleFormat; + private readonly uint _userChannelCount; public CompatLayerHardwareDeviceSession(HardwareDeviceSessionOutputBase realSession, SampleFormat userSampleFormat, uint userChannelCount) : base(realSession.MemoryManager, realSession.RequestedSampleFormat, realSession.RequestedSampleRate, userChannelCount) { @@ -116,11 +116,11 @@ namespace Ryujinx.Audio.Backends.CompatLayer samples = MemoryMarshal.Cast(samplesPCM16).ToArray(); } - AudioBuffer fakeBuffer = new AudioBuffer + AudioBuffer fakeBuffer = new() { BufferTag = buffer.BufferTag, DataPointer = buffer.DataPointer, - DataSize = (ulong)samples.Length + DataSize = (ulong)samples.Length, }; bool result = _realSession.RegisterBuffer(fakeBuffer, samples); @@ -159,4 +159,4 @@ namespace Ryujinx.Audio.Backends.CompatLayer return _realSession.WasBufferFullyConsumed(buffer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Backends/CompatLayer/Downmixing.cs b/src/Ryujinx.Audio/Backends/CompatLayer/Downmixing.cs index 6959c1588..ffd427a5e 100644 --- a/src/Ryujinx.Audio/Backends/CompatLayer/Downmixing.cs +++ b/src/Ryujinx.Audio/Backends/CompatLayer/Downmixing.cs @@ -31,18 +31,18 @@ namespace Ryujinx.Audio.Backends.CompatLayer private const int Minus6dBInQ15 = (int)(0.501f * RawQ15One); private const int Minus12dBInQ15 = (int)(0.251f * RawQ15One); - private static readonly int[] DefaultSurroundToStereoCoefficients = new int[4] + private static readonly int[] _defaultSurroundToStereoCoefficients = new int[4] { RawQ15One, Minus3dBInQ15, Minus12dBInQ15, - Minus3dBInQ15 + Minus3dBInQ15, }; - private static readonly int[] DefaultStereoToMonoCoefficients = new int[2] + private static readonly int[] _defaultStereoToMonoCoefficients = new int[2] { Minus6dBInQ15, - Minus6dBInQ15 + Minus6dBInQ15, }; private const int SurroundChannelCount = 6; @@ -114,12 +114,12 @@ namespace Ryujinx.Audio.Backends.CompatLayer public static short[] DownMixStereoToMono(ReadOnlySpan data) { - return DownMixStereoToMono(DefaultStereoToMonoCoefficients, data); + return DownMixStereoToMono(_defaultStereoToMonoCoefficients, data); } public static short[] DownMixSurroundToStereo(ReadOnlySpan data) { - return DownMixSurroundToStereo(DefaultSurroundToStereoCoefficients, data); + return DownMixSurroundToStereo(_defaultSurroundToStereoCoefficients, data); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceDriver.cs b/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceDriver.cs index 641640f0e..bac21c448 100644 --- a/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceDriver.cs +++ b/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceDriver.cs @@ -1,16 +1,16 @@ using Ryujinx.Audio.Common; using Ryujinx.Audio.Integration; using Ryujinx.Memory; +using System; using System.Threading; - using static Ryujinx.Audio.Integration.IHardwareDeviceDriver; namespace Ryujinx.Audio.Backends.Dummy { public class DummyHardwareDeviceDriver : IHardwareDeviceDriver { - private ManualResetEvent _updateRequiredEvent; - private ManualResetEvent _pauseEvent; + private readonly ManualResetEvent _updateRequiredEvent; + private readonly ManualResetEvent _pauseEvent; public static bool IsSupported => true; @@ -36,10 +36,8 @@ namespace Ryujinx.Audio.Backends.Dummy { return new DummyHardwareDeviceSessionOutput(this, memoryManager, sampleFormat, sampleRate, channelCount, volume); } - else - { - return new DummyHardwareDeviceSessionInput(this, memoryManager, sampleFormat, sampleRate, channelCount); - } + + return new DummyHardwareDeviceSessionInput(this, memoryManager); } public ManualResetEvent GetUpdateRequiredEvent() @@ -54,6 +52,7 @@ namespace Ryujinx.Audio.Backends.Dummy public void Dispose() { + GC.SuppressFinalize(this); Dispose(true); } @@ -86,4 +85,4 @@ namespace Ryujinx.Audio.Backends.Dummy return channelCount == 1 || channelCount == 2 || channelCount == 6; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceSessionInput.cs b/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceSessionInput.cs index 845713a19..f51a63393 100644 --- a/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceSessionInput.cs +++ b/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceSessionInput.cs @@ -8,10 +8,10 @@ namespace Ryujinx.Audio.Backends.Dummy class DummyHardwareDeviceSessionInput : IHardwareDeviceSession { private float _volume; - private IHardwareDeviceDriver _manager; - private IVirtualMemoryManager _memoryManager; + private readonly IHardwareDeviceDriver _manager; + private readonly IVirtualMemoryManager _memoryManager; - public DummyHardwareDeviceSessionInput(IHardwareDeviceDriver manager, IVirtualMemoryManager memoryManager, SampleFormat requestedSampleFormat, uint requestedSampleRate, uint requestedChannelCount) + public DummyHardwareDeviceSessionInput(IHardwareDeviceDriver manager, IVirtualMemoryManager memoryManager) { _volume = 1.0f; _manager = manager; @@ -64,4 +64,4 @@ namespace Ryujinx.Audio.Backends.Dummy return true; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceSessionOutput.cs b/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceSessionOutput.cs index 8e2c949ec..1c248faaa 100644 --- a/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceSessionOutput.cs +++ b/src/Ryujinx.Audio/Backends/Dummy/DummyHardwareDeviceSessionOutput.cs @@ -9,7 +9,7 @@ namespace Ryujinx.Audio.Backends.Dummy internal class DummyHardwareDeviceSessionOutput : HardwareDeviceSessionOutputBase { private float _volume; - private IHardwareDeviceDriver _manager; + private readonly IHardwareDeviceDriver _manager; private ulong _playedSampleCount; @@ -59,4 +59,4 @@ namespace Ryujinx.Audio.Backends.Dummy return true; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Common/AudioBuffer.cs b/src/Ryujinx.Audio/Common/AudioBuffer.cs index b79401b77..87a7d5f32 100644 --- a/src/Ryujinx.Audio/Common/AudioBuffer.cs +++ b/src/Ryujinx.Audio/Common/AudioBuffer.cs @@ -34,4 +34,4 @@ namespace Ryujinx.Audio.Common /// public byte[] Data; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Common/AudioDeviceSession.cs b/src/Ryujinx.Audio/Common/AudioDeviceSession.cs index 0191f7ccd..a0e04c80d 100644 --- a/src/Ryujinx.Audio/Common/AudioDeviceSession.cs +++ b/src/Ryujinx.Audio/Common/AudioDeviceSession.cs @@ -23,7 +23,7 @@ namespace Ryujinx.Audio.Common /// /// Array of all buffers currently used or released. /// - private AudioBuffer[] _buffers; + private readonly AudioBuffer[] _buffers; /// /// The server index inside (appended but not queued to device driver). @@ -58,17 +58,17 @@ namespace Ryujinx.Audio.Common /// /// The released buffer event. /// - private IWritableEvent _bufferEvent; + private readonly IWritableEvent _bufferEvent; /// /// The session on the device driver. /// - private IHardwareDeviceSession _hardwareDeviceSession; + private readonly IHardwareDeviceSession _hardwareDeviceSession; /// /// Max number of buffers that can be registered to the device driver at a time. /// - private uint _bufferRegisteredLimit; + private readonly uint _bufferRegisteredLimit; /// /// Create a new . @@ -311,9 +311,9 @@ namespace Ryujinx.Audio.Common return false; } - public bool AppendUacBuffer(AudioBuffer buffer, uint handle) + public static bool AppendUacBuffer(AudioBuffer buffer, uint handle) { - // NOTE: On hardware, there is another RegisterBuffer method taking an handle. + // NOTE: On hardware, there is another RegisterBuffer method taking a handle. // This variant of the call always return false (stubbed?) as a result this logic will never succeed. return false; @@ -425,10 +425,8 @@ namespace Ryujinx.Audio.Common { return 0; } - else - { - return _hardwareDeviceSession.GetPlayedSampleCount(); - } + + return _hardwareDeviceSession.GetPlayedSampleCount(); } /// @@ -515,4 +513,4 @@ namespace Ryujinx.Audio.Common } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Common/AudioDeviceState.cs b/src/Ryujinx.Audio/Common/AudioDeviceState.cs index b3f968da2..8705e802e 100644 --- a/src/Ryujinx.Audio/Common/AudioDeviceState.cs +++ b/src/Ryujinx.Audio/Common/AudioDeviceState.cs @@ -13,6 +13,6 @@ namespace Ryujinx.Audio.Common /// /// The audio device is stopped. /// - Stopped + Stopped, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Common/AudioInputConfiguration.cs b/src/Ryujinx.Audio/Common/AudioInputConfiguration.cs index d3cfdd47b..078c3a394 100644 --- a/src/Ryujinx.Audio/Common/AudioInputConfiguration.cs +++ b/src/Ryujinx.Audio/Common/AudioInputConfiguration.cs @@ -24,6 +24,6 @@ namespace Ryujinx.Audio.Common /// /// Reserved/unused. /// - private ushort _reserved; + private readonly ushort _reserved; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Common/AudioOutputConfiguration.cs b/src/Ryujinx.Audio/Common/AudioOutputConfiguration.cs index e17e17576..594f12250 100644 --- a/src/Ryujinx.Audio/Common/AudioOutputConfiguration.cs +++ b/src/Ryujinx.Audio/Common/AudioOutputConfiguration.cs @@ -34,4 +34,4 @@ namespace Ryujinx.Audio.Common /// public AudioDeviceState AudioOutState; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Common/AudioUserBuffer.cs b/src/Ryujinx.Audio/Common/AudioUserBuffer.cs index 50ab67fa3..bb71165ff 100644 --- a/src/Ryujinx.Audio/Common/AudioUserBuffer.cs +++ b/src/Ryujinx.Audio/Common/AudioUserBuffer.cs @@ -33,4 +33,4 @@ namespace Ryujinx.Audio.Common /// public ulong DataOffset; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Common/SampleFormat.cs b/src/Ryujinx.Audio/Common/SampleFormat.cs index 901410a24..39e525e87 100644 --- a/src/Ryujinx.Audio/Common/SampleFormat.cs +++ b/src/Ryujinx.Audio/Common/SampleFormat.cs @@ -38,6 +38,6 @@ namespace Ryujinx.Audio.Common /// /// ADPCM sample format. (Also known as GC-ADPCM) /// - Adpcm = 6 + Adpcm = 6, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Constants.cs b/src/Ryujinx.Audio/Constants.cs index cde87744f..eb5b39013 100644 --- a/src/Ryujinx.Audio/Constants.cs +++ b/src/Ryujinx.Audio/Constants.cs @@ -172,4 +172,4 @@ namespace Ryujinx.Audio 0.707f, }; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Input/AudioInputManager.cs b/src/Ryujinx.Audio/Input/AudioInputManager.cs index 63cbe031f..4d1796c96 100644 --- a/src/Ryujinx.Audio/Input/AudioInputManager.cs +++ b/src/Ryujinx.Audio/Input/AudioInputManager.cs @@ -24,7 +24,7 @@ namespace Ryujinx.Audio.Input /// /// The session ids allocation table. /// - private int[] _sessionIds; + private readonly int[] _sessionIds; /// /// The device driver. @@ -39,7 +39,7 @@ namespace Ryujinx.Audio.Input /// /// The session instances. /// - private AudioInputSystem[] _sessions; + private readonly AudioInputSystem[] _sessions; /// /// The count of active sessions. @@ -166,6 +166,7 @@ namespace Ryujinx.Audio.Input /// /// If true, filter disconnected devices /// The list of all audio inputs name +#pragma warning disable CA1822 // Mark member as static public string[] ListAudioIns(bool filtered) { if (filtered) @@ -173,8 +174,9 @@ namespace Ryujinx.Audio.Input // TODO: Detect if the driver supports audio input } - return new string[] { Constants.DefaultDeviceInputName }; + return new[] { Constants.DefaultDeviceInputName }; } +#pragma warning restore CA1822 /// /// Open a new . @@ -205,7 +207,7 @@ namespace Ryujinx.Audio.Input IHardwareDeviceSession deviceSession = _deviceDriver.OpenDeviceSession(IHardwareDeviceDriver.Direction.Input, memoryManager, sampleFormat, parameter.SampleRate, parameter.ChannelCount); - AudioInputSystem audioIn = new AudioInputSystem(this, _lock, deviceSession, _sessionsBufferEvents[sessionId]); + AudioInputSystem audioIn = new(this, _lock, deviceSession, _sessionsBufferEvents[sessionId]); ResultCode result = audioIn.Initialize(inputDeviceName, sampleFormat, ref parameter, sessionId); @@ -238,6 +240,8 @@ namespace Ryujinx.Audio.Input public void Dispose() { + GC.SuppressFinalize(this); + if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0) { Dispose(true); @@ -263,4 +267,4 @@ namespace Ryujinx.Audio.Input } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Input/AudioInputSystem.cs b/src/Ryujinx.Audio/Input/AudioInputSystem.cs index 33364e28a..34623b34f 100644 --- a/src/Ryujinx.Audio/Input/AudioInputSystem.cs +++ b/src/Ryujinx.Audio/Input/AudioInputSystem.cs @@ -18,7 +18,7 @@ namespace Ryujinx.Audio.Input /// /// The session the . /// - private AudioDeviceSession _session; + private readonly AudioDeviceSession _session; /// /// The target device name of the . @@ -43,7 +43,7 @@ namespace Ryujinx.Audio.Input /// /// The owning this. /// - private AudioInputManager _manager; + private readonly AudioInputManager _manager; /// /// The lock of the parent. @@ -90,11 +90,13 @@ namespace Ryujinx.Audio.Input { return ResultCode.DeviceNotFound; } - else if (configuration.SampleRate != 0 && configuration.SampleRate != Constants.TargetSampleRate) + + if (configuration.SampleRate != 0 && configuration.SampleRate != Constants.TargetSampleRate) { return ResultCode.UnsupportedSampleRate; } - else if (configuration.ChannelCount != 0 && configuration.ChannelCount != 1 && configuration.ChannelCount != 2 && configuration.ChannelCount != 6) + + if (configuration.ChannelCount != 0 && configuration.ChannelCount != 1 && configuration.ChannelCount != 2 && configuration.ChannelCount != 6) { return ResultCode.UnsupportedChannelConfiguration; } @@ -185,11 +187,11 @@ namespace Ryujinx.Audio.Input { lock (_parentLock) { - AudioBuffer buffer = new AudioBuffer + AudioBuffer buffer = new() { BufferTag = bufferTag, DataPointer = userBuffer.Data, - DataSize = userBuffer.DataSize + DataSize = userBuffer.DataSize, }; if (_session.AppendBuffer(buffer)) @@ -213,14 +215,14 @@ namespace Ryujinx.Audio.Input { lock (_parentLock) { - AudioBuffer buffer = new AudioBuffer + AudioBuffer buffer = new() { BufferTag = bufferTag, DataPointer = userBuffer.Data, - DataSize = userBuffer.DataSize + DataSize = userBuffer.DataSize, }; - if (_session.AppendUacBuffer(buffer, handle)) + if (AudioDeviceSession.AppendUacBuffer(buffer, handle)) { return ResultCode.Success; } @@ -373,6 +375,8 @@ namespace Ryujinx.Audio.Input public void Dispose() { + GC.SuppressFinalize(this); + if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0) { Dispose(true); @@ -389,4 +393,4 @@ namespace Ryujinx.Audio.Input } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Integration/HardwareDeviceImpl.cs b/src/Ryujinx.Audio/Integration/HardwareDeviceImpl.cs index 552f1ab24..576954b96 100644 --- a/src/Ryujinx.Audio/Integration/HardwareDeviceImpl.cs +++ b/src/Ryujinx.Audio/Integration/HardwareDeviceImpl.cs @@ -6,12 +6,12 @@ namespace Ryujinx.Audio.Integration { public class HardwareDeviceImpl : IHardwareDevice { - private IHardwareDeviceSession _session; - private uint _channelCount; - private uint _sampleRate; + private readonly IHardwareDeviceSession _session; + private readonly uint _channelCount; + private readonly uint _sampleRate; private uint _currentBufferTag; - private byte[] _buffer; + private readonly byte[] _buffer; public HardwareDeviceImpl(IHardwareDeviceDriver deviceDriver, uint channelCount, uint sampleRate, float volume) { @@ -36,7 +36,7 @@ namespace Ryujinx.Audio.Integration DataSize = (ulong)_buffer.Length, }); - _currentBufferTag = _currentBufferTag % 4; + _currentBufferTag %= 4; } public void SetVolume(float volume) @@ -61,6 +61,7 @@ namespace Ryujinx.Audio.Integration public void Dispose() { + GC.SuppressFinalize(this); Dispose(true); } @@ -72,4 +73,4 @@ namespace Ryujinx.Audio.Integration } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Integration/IHardwareDevice.cs b/src/Ryujinx.Audio/Integration/IHardwareDevice.cs index 300de8c5d..f9ade9dbc 100644 --- a/src/Ryujinx.Audio/Integration/IHardwareDevice.cs +++ b/src/Ryujinx.Audio/Integration/IHardwareDevice.cs @@ -52,4 +52,4 @@ namespace Ryujinx.Audio.Integration return channelCount != Constants.ChannelCountMax; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Integration/IHardwareDeviceDriver.cs b/src/Ryujinx.Audio/Integration/IHardwareDeviceDriver.cs index 4ed179519..9c812fb9a 100644 --- a/src/Ryujinx.Audio/Integration/IHardwareDeviceDriver.cs +++ b/src/Ryujinx.Audio/Integration/IHardwareDeviceDriver.cs @@ -13,7 +13,7 @@ namespace Ryujinx.Audio.Integration public enum Direction { Input, - Output + Output, } IHardwareDeviceSession OpenDeviceSession(Direction direction, IVirtualMemoryManager memoryManager, SampleFormat sampleFormat, uint sampleRate, uint channelCount, float volume = 1f); @@ -33,4 +33,4 @@ namespace Ryujinx.Audio.Integration return this; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Integration/IHardwareDeviceSession.cs b/src/Ryujinx.Audio/Integration/IHardwareDeviceSession.cs index 400daec00..f29c109cb 100644 --- a/src/Ryujinx.Audio/Integration/IHardwareDeviceSession.cs +++ b/src/Ryujinx.Audio/Integration/IHardwareDeviceSession.cs @@ -25,4 +25,4 @@ namespace Ryujinx.Audio.Integration void PrepareToClose(); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Integration/IWritableEvent.cs b/src/Ryujinx.Audio/Integration/IWritableEvent.cs index 9a12e3d28..a3b3bc0bc 100644 --- a/src/Ryujinx.Audio/Integration/IWritableEvent.cs +++ b/src/Ryujinx.Audio/Integration/IWritableEvent.cs @@ -15,4 +15,4 @@ namespace Ryujinx.Audio.Integration /// void Clear(); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Output/AudioOutputManager.cs b/src/Ryujinx.Audio/Output/AudioOutputManager.cs index bc2fc6f43..5232357bb 100644 --- a/src/Ryujinx.Audio/Output/AudioOutputManager.cs +++ b/src/Ryujinx.Audio/Output/AudioOutputManager.cs @@ -24,7 +24,7 @@ namespace Ryujinx.Audio.Output /// /// The session ids allocation table. /// - private int[] _sessionIds; + private readonly int[] _sessionIds; /// /// The device driver. @@ -39,7 +39,7 @@ namespace Ryujinx.Audio.Output /// /// The session instances. /// - private AudioOutputSystem[] _sessions; + private readonly AudioOutputSystem[] _sessions; /// /// The count of active sessions. @@ -165,10 +165,12 @@ namespace Ryujinx.Audio.Output /// Get the list of all audio outputs name. /// /// The list of all audio outputs name +#pragma warning disable CA1822 // Mark member as static public string[] ListAudioOuts() { - return new string[] { Constants.DefaultDeviceOutputName }; + return new[] { Constants.DefaultDeviceOutputName }; } +#pragma warning restore CA1822 /// /// Open a new . @@ -182,6 +184,7 @@ namespace Ryujinx.Audio.Output /// The user configuration /// The applet resource user id of the application /// The process handle of the application + /// The volume level to request /// A reporting an error or a success public ResultCode OpenAudioOut(out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, @@ -200,7 +203,7 @@ namespace Ryujinx.Audio.Output IHardwareDeviceSession deviceSession = _deviceDriver.OpenDeviceSession(IHardwareDeviceDriver.Direction.Output, memoryManager, sampleFormat, parameter.SampleRate, parameter.ChannelCount, volume); - AudioOutputSystem audioOut = new AudioOutputSystem(this, _lock, deviceSession, _sessionsBufferEvents[sessionId]); + AudioOutputSystem audioOut = new(this, _lock, deviceSession, _sessionsBufferEvents[sessionId]); ResultCode result = audioOut.Initialize(inputDeviceName, sampleFormat, ref parameter, sessionId); @@ -268,6 +271,8 @@ namespace Ryujinx.Audio.Output public void Dispose() { + GC.SuppressFinalize(this); + if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0) { Dispose(true); @@ -293,4 +298,4 @@ namespace Ryujinx.Audio.Output } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Output/AudioOutputSystem.cs b/src/Ryujinx.Audio/Output/AudioOutputSystem.cs index 8378f33f8..f9b9bdcf1 100644 --- a/src/Ryujinx.Audio/Output/AudioOutputSystem.cs +++ b/src/Ryujinx.Audio/Output/AudioOutputSystem.cs @@ -18,7 +18,7 @@ namespace Ryujinx.Audio.Output /// /// The session the . /// - private AudioDeviceSession _session; + private readonly AudioDeviceSession _session; /// /// The target device name of the . @@ -43,7 +43,7 @@ namespace Ryujinx.Audio.Output /// /// The owning this. /// - private AudioOutputManager _manager; + private readonly AudioOutputManager _manager; /// /// THe lock of the parent. @@ -90,11 +90,13 @@ namespace Ryujinx.Audio.Output { return ResultCode.DeviceNotFound; } - else if (configuration.SampleRate != 0 && configuration.SampleRate != Constants.TargetSampleRate) + + if (configuration.SampleRate != 0 && configuration.SampleRate != Constants.TargetSampleRate) { return ResultCode.UnsupportedSampleRate; } - else if (configuration.ChannelCount != 0 && configuration.ChannelCount != 1 && configuration.ChannelCount != 2 && configuration.ChannelCount != 6) + + if (configuration.ChannelCount != 0 && configuration.ChannelCount != 1 && configuration.ChannelCount != 2 && configuration.ChannelCount != 6) { return ResultCode.UnsupportedChannelConfiguration; } @@ -185,11 +187,11 @@ namespace Ryujinx.Audio.Output { lock (_parentLock) { - AudioBuffer buffer = new AudioBuffer + AudioBuffer buffer = new() { BufferTag = bufferTag, DataPointer = userBuffer.Data, - DataSize = userBuffer.DataSize + DataSize = userBuffer.DataSize, }; if (_session.AppendBuffer(buffer)) @@ -346,6 +348,8 @@ namespace Ryujinx.Audio.Output public void Dispose() { + GC.SuppressFinalize(this); + if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0) { Dispose(true); @@ -362,4 +366,4 @@ namespace Ryujinx.Audio.Output } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/AuxiliaryBufferAddresses.cs b/src/Ryujinx.Audio/Renderer/Common/AuxiliaryBufferAddresses.cs index 966474052..b7b97d5d8 100644 --- a/src/Ryujinx.Audio/Renderer/Common/AuxiliaryBufferAddresses.cs +++ b/src/Ryujinx.Audio/Renderer/Common/AuxiliaryBufferAddresses.cs @@ -10,4 +10,4 @@ namespace Ryujinx.Audio.Renderer.Common public ulong ReturnBufferInfo; public ulong ReturnBufferInfoBase; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/BehaviourParameter.cs b/src/Ryujinx.Audio/Renderer/Common/BehaviourParameter.cs index 270f84d5b..b0963c935 100644 --- a/src/Ryujinx.Audio/Renderer/Common/BehaviourParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Common/BehaviourParameter.cs @@ -16,7 +16,7 @@ namespace Ryujinx.Audio.Renderer.Common /// /// Reserved/padding. /// - private uint _padding; + private readonly uint _padding; /// /// The flags given controlling behaviour of the audio renderer @@ -38,7 +38,7 @@ namespace Ryujinx.Audio.Renderer.Common /// /// Reserved/padding. /// - private uint _padding; + private readonly uint _padding; /// /// Extra information given with the @@ -47,4 +47,4 @@ namespace Ryujinx.Audio.Renderer.Common public ulong ExtraErrorInfo; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/EdgeMatrix.cs b/src/Ryujinx.Audio/Renderer/Common/EdgeMatrix.cs index 24a9350fc..3beb62399 100644 --- a/src/Ryujinx.Audio/Renderer/Common/EdgeMatrix.cs +++ b/src/Ryujinx.Audio/Renderer/Common/EdgeMatrix.cs @@ -147,4 +147,4 @@ namespace Ryujinx.Audio.Renderer.Common return _nodeCount; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/EffectType.cs b/src/Ryujinx.Audio/Renderer/Common/EffectType.cs index 7128db4ce..7c8713b12 100644 --- a/src/Ryujinx.Audio/Renderer/Common/EffectType.cs +++ b/src/Ryujinx.Audio/Renderer/Common/EffectType.cs @@ -55,4 +55,4 @@ namespace Ryujinx.Audio.Renderer.Common /// Compressor, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/MemoryPoolUserState.cs b/src/Ryujinx.Audio/Renderer/Common/MemoryPoolUserState.cs index 590731c3b..6d835879c 100644 --- a/src/Ryujinx.Audio/Renderer/Common/MemoryPoolUserState.cs +++ b/src/Ryujinx.Audio/Renderer/Common/MemoryPoolUserState.cs @@ -38,6 +38,6 @@ namespace Ryujinx.Audio.Renderer.Common /// /// The memory pool is released. (client side only) /// - Released = 6 + Released = 6, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/NodeIdHelper.cs b/src/Ryujinx.Audio/Renderer/Common/NodeIdHelper.cs index a999e3ad1..76fba54b6 100644 --- a/src/Ryujinx.Audio/Renderer/Common/NodeIdHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Common/NodeIdHelper.cs @@ -25,4 +25,4 @@ namespace Ryujinx.Audio.Renderer.Common return (nodeId >> 16) & 0xFFF; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/NodeIdType.cs b/src/Ryujinx.Audio/Renderer/Common/NodeIdType.cs index 69b58f6bc..b226da14f 100644 --- a/src/Ryujinx.Audio/Renderer/Common/NodeIdType.cs +++ b/src/Ryujinx.Audio/Renderer/Common/NodeIdType.cs @@ -28,6 +28,6 @@ namespace Ryujinx.Audio.Renderer.Common /// /// Performance monitoring related node id (performance commands) /// - Performance = 15 + Performance = 15, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/NodeStates.cs b/src/Ryujinx.Audio/Renderer/Common/NodeStates.cs index 45748d606..75290a741 100644 --- a/src/Ryujinx.Audio/Renderer/Common/NodeStates.cs +++ b/src/Ryujinx.Audio/Renderer/Common/NodeStates.cs @@ -53,17 +53,17 @@ namespace Ryujinx.Audio.Renderer.Common } private int _nodeCount; - private EdgeMatrix _discovered; - private EdgeMatrix _finished; + private readonly EdgeMatrix _discovered; + private readonly EdgeMatrix _finished; private Memory _resultArray; - private Stack _stack; + private readonly Stack _stack; private int _tsortResultIndex; private enum NodeState : byte { Unknown, Discovered, - Finished + Finished, } public NodeStates() @@ -88,16 +88,16 @@ namespace Ryujinx.Audio.Renderer.Common int edgeMatrixWorkBufferSize = EdgeMatrix.GetWorkBufferSize(nodeCount); - _discovered.Initialize(nodeStatesWorkBuffer.Slice(0, edgeMatrixWorkBufferSize), nodeCount); + _discovered.Initialize(nodeStatesWorkBuffer[..edgeMatrixWorkBufferSize], nodeCount); _finished.Initialize(nodeStatesWorkBuffer.Slice(edgeMatrixWorkBufferSize, edgeMatrixWorkBufferSize), nodeCount); - nodeStatesWorkBuffer = nodeStatesWorkBuffer.Slice(edgeMatrixWorkBufferSize * 2); + nodeStatesWorkBuffer = nodeStatesWorkBuffer[(edgeMatrixWorkBufferSize * 2)..]; - _resultArray = SpanMemoryManager.Cast(nodeStatesWorkBuffer.Slice(0, sizeof(int) * nodeCount)); + _resultArray = SpanMemoryManager.Cast(nodeStatesWorkBuffer[..(sizeof(int) * nodeCount)]); - nodeStatesWorkBuffer = nodeStatesWorkBuffer.Slice(sizeof(int) * nodeCount); + nodeStatesWorkBuffer = nodeStatesWorkBuffer[(sizeof(int) * nodeCount)..]; - Memory stackWorkBuffer = SpanMemoryManager.Cast(nodeStatesWorkBuffer.Slice(0, Stack.CalcBufferSize(nodeCount * nodeCount))); + Memory stackWorkBuffer = SpanMemoryManager.Cast(nodeStatesWorkBuffer[..Stack.CalcBufferSize(nodeCount * nodeCount)]); _stack.Reset(stackWorkBuffer, nodeCount * nodeCount); } @@ -120,7 +120,8 @@ namespace Ryujinx.Audio.Renderer.Common return NodeState.Discovered; } - else if (_finished.Test(index)) + + if (_finished.Test(index)) { Debug.Assert(!_discovered.Test(index)); @@ -158,7 +159,7 @@ namespace Ryujinx.Audio.Renderer.Common public ReadOnlySpan GetTsortResult() { - return _resultArray.Span.Slice(0, _tsortResultIndex); + return _resultArray.Span[.._tsortResultIndex]; } public bool Sort(EdgeMatrix edgeMatrix) @@ -226,4 +227,4 @@ namespace Ryujinx.Audio.Renderer.Common return true; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/PerformanceDetailType.cs b/src/Ryujinx.Audio/Renderer/Common/PerformanceDetailType.cs index 805d55183..bde32a709 100644 --- a/src/Ryujinx.Audio/Renderer/Common/PerformanceDetailType.cs +++ b/src/Ryujinx.Audio/Renderer/Common/PerformanceDetailType.cs @@ -15,6 +15,6 @@ namespace Ryujinx.Audio.Renderer.Common PcmFloat, Limiter, CaptureBuffer, - Compressor + Compressor, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/PerformanceEntryType.cs b/src/Ryujinx.Audio/Renderer/Common/PerformanceEntryType.cs index bde72aaed..e32095e62 100644 --- a/src/Ryujinx.Audio/Renderer/Common/PerformanceEntryType.cs +++ b/src/Ryujinx.Audio/Renderer/Common/PerformanceEntryType.cs @@ -6,6 +6,6 @@ namespace Ryujinx.Audio.Renderer.Common Voice, SubMix, FinalMix, - Sink + Sink, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/PlayState.cs b/src/Ryujinx.Audio/Renderer/Common/PlayState.cs index 4a6929e03..a83d16afb 100644 --- a/src/Ryujinx.Audio/Renderer/Common/PlayState.cs +++ b/src/Ryujinx.Audio/Renderer/Common/PlayState.cs @@ -18,6 +18,6 @@ namespace Ryujinx.Audio.Renderer.Common /// /// The user request the voice to be paused. /// - Pause + Pause, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/ReverbEarlyMode.cs b/src/Ryujinx.Audio/Renderer/Common/ReverbEarlyMode.cs index aa7685621..c7443cc49 100644 --- a/src/Ryujinx.Audio/Renderer/Common/ReverbEarlyMode.cs +++ b/src/Ryujinx.Audio/Renderer/Common/ReverbEarlyMode.cs @@ -28,6 +28,6 @@ namespace Ryujinx.Audio.Renderer.Common /// /// No early reflection. /// - Disabled + Disabled, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/ReverbLateMode.cs b/src/Ryujinx.Audio/Renderer/Common/ReverbLateMode.cs index 8aa88165a..78f91cf08 100644 --- a/src/Ryujinx.Audio/Renderer/Common/ReverbLateMode.cs +++ b/src/Ryujinx.Audio/Renderer/Common/ReverbLateMode.cs @@ -33,6 +33,6 @@ namespace Ryujinx.Audio.Renderer.Common /// /// Max delay. (used for delay line limits) /// - Limit = NoDelay + Limit = NoDelay, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/SinkType.cs b/src/Ryujinx.Audio/Renderer/Common/SinkType.cs index 2e17201e7..5a08df4e1 100644 --- a/src/Ryujinx.Audio/Renderer/Common/SinkType.cs +++ b/src/Ryujinx.Audio/Renderer/Common/SinkType.cs @@ -18,6 +18,6 @@ namespace Ryujinx.Audio.Renderer.Common /// /// The sink is a circular buffer. /// - CircularBuffer + CircularBuffer, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/UpdateDataHeader.cs b/src/Ryujinx.Audio/Renderer/Common/UpdateDataHeader.cs index 70dbfa947..7efe3b02b 100644 --- a/src/Ryujinx.Audio/Renderer/Common/UpdateDataHeader.cs +++ b/src/Ryujinx.Audio/Renderer/Common/UpdateDataHeader.cs @@ -1,3 +1,4 @@ +using Ryujinx.Common.Memory; using System.Runtime.CompilerServices; namespace Ryujinx.Audio.Renderer.Common @@ -19,7 +20,9 @@ namespace Ryujinx.Audio.Renderer.Common public uint Unknown24; public uint RenderInfoSize; - private unsafe fixed int _reserved[4]; +#pragma warning disable IDE0051, CS0169 // Remove unused field + private Array4 _reserved; +#pragma warning restore IDE0051, CS0169 public uint TotalSize; @@ -30,4 +33,4 @@ namespace Ryujinx.Audio.Renderer.Common TotalSize = (uint)Unsafe.SizeOf(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/VoiceUpdateState.cs b/src/Ryujinx.Audio/Renderer/Common/VoiceUpdateState.cs index f52c2f4c4..608381af1 100644 --- a/src/Ryujinx.Audio/Renderer/Common/VoiceUpdateState.cs +++ b/src/Ryujinx.Audio/Renderer/Common/VoiceUpdateState.cs @@ -101,4 +101,4 @@ namespace Ryujinx.Audio.Renderer.Common } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/WaveBuffer.cs b/src/Ryujinx.Audio/Renderer/Common/WaveBuffer.cs index 0d00e8384..5109d3fa0 100644 --- a/src/Ryujinx.Audio/Renderer/Common/WaveBuffer.cs +++ b/src/Ryujinx.Audio/Renderer/Common/WaveBuffer.cs @@ -1,5 +1,4 @@ using System.Runtime.InteropServices; - using DspAddr = System.UInt64; namespace Ryujinx.Audio.Renderer.Common @@ -77,6 +76,6 @@ namespace Ryujinx.Audio.Renderer.Common /// /// Padding/Reserved. /// - private ushort _padding; + private readonly ushort _padding; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs b/src/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs index f35dbec7f..54673f2f6 100644 --- a/src/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs +++ b/src/Ryujinx.Audio/Renderer/Common/WorkBufferAllocator.cs @@ -23,7 +23,7 @@ namespace Ryujinx.Audio.Renderer.Common if (size != 0) { - ulong alignedOffset = BitUtils.AlignUp(Offset, (ulong)align); + ulong alignedOffset = BitUtils.AlignUp(Offset, (ulong)align); if (alignedOffset + size <= (ulong)BackingMemory.Length) { @@ -32,7 +32,7 @@ namespace Ryujinx.Audio.Renderer.Common Offset = alignedOffset + size; // Clear the memory to be sure that is does not contain any garbage. - result.Span.Fill(0); + result.Span.Clear(); return result; } @@ -55,7 +55,7 @@ namespace Ryujinx.Audio.Renderer.Common public static ulong GetTargetSize(ulong currentSize, ulong count, int align) where T : unmanaged { - return BitUtils.AlignUp(currentSize, (ulong)align) + (ulong)Unsafe.SizeOf() * count; + return BitUtils.AlignUp(currentSize, (ulong)align) + (ulong)Unsafe.SizeOf() * count; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Device/VirtualDevice.cs b/src/Ryujinx.Audio/Renderer/Device/VirtualDevice.cs index 90692b004..91956fda6 100644 --- a/src/Ryujinx.Audio/Renderer/Device/VirtualDevice.cs +++ b/src/Ryujinx.Audio/Renderer/Device/VirtualDevice.cs @@ -12,11 +12,11 @@ namespace Ryujinx.Audio.Renderer.Device /// public static readonly VirtualDevice[] Devices = new VirtualDevice[5] { - new VirtualDevice("AudioStereoJackOutput", 2, true), - new VirtualDevice("AudioBuiltInSpeakerOutput", 2, false), - new VirtualDevice("AudioTvOutput", 6, false), - new VirtualDevice("AudioUsbDeviceOutput", 2, true), - new VirtualDevice("AudioExternalOutput", 6, true), + new("AudioStereoJackOutput", 2, true), + new("AudioBuiltInSpeakerOutput", 2, false), + new("AudioTvOutput", 6, false), + new("AudioUsbDeviceOutput", 2, true), + new("AudioExternalOutput", 6, true), }; /// @@ -86,4 +86,4 @@ namespace Ryujinx.Audio.Renderer.Device return Name; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Device/VirtualDeviceSession.cs b/src/Ryujinx.Audio/Renderer/Device/VirtualDeviceSession.cs index db35d26d2..09fa71eda 100644 --- a/src/Ryujinx.Audio/Renderer/Device/VirtualDeviceSession.cs +++ b/src/Ryujinx.Audio/Renderer/Device/VirtualDeviceSession.cs @@ -24,4 +24,4 @@ namespace Ryujinx.Audio.Renderer.Device Device = virtualDevice; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Device/VirtualDeviceSessionRegistry.cs b/src/Ryujinx.Audio/Renderer/Device/VirtualDeviceSessionRegistry.cs index 696af90fa..4ad70619e 100644 --- a/src/Ryujinx.Audio/Renderer/Device/VirtualDeviceSessionRegistry.cs +++ b/src/Ryujinx.Audio/Renderer/Device/VirtualDeviceSessionRegistry.cs @@ -11,13 +11,15 @@ namespace Ryujinx.Audio.Renderer.Device /// /// The session registry, used to store the sessions of a given AppletResourceId. /// - private Dictionary _sessionsRegistry = new Dictionary(); + private readonly Dictionary _sessionsRegistry = new(); /// /// The default . /// /// This is used when the USB device is the default one on older revision. +#pragma warning disable CA1822 // Mark member as static public VirtualDevice DefaultDevice => VirtualDevice.Devices[0]; +#pragma warning restore CA1822 /// /// The current active . @@ -76,4 +78,4 @@ namespace Ryujinx.Audio.Renderer.Device return virtualDeviceSession; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs b/src/Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs index 2680dcb1e..5cb4509ff 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs @@ -12,7 +12,9 @@ namespace Ryujinx.Audio.Renderer.Dsp private const int SamplesPerFrame = 14; private const int NibblesPerFrame = SamplesPerFrame + 2; private const int BytesPerFrame = 8; +#pragma warning disable IDE0051 // Remove unused private member private const int BitsPerFrame = BytesPerFrame * 8; +#pragma warning restore IDE0051 [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint GetAdpcmDataSize(int sampleCount) @@ -64,10 +66,14 @@ namespace Ryujinx.Audio.Renderer.Dsp private static short Saturate(int value) { if (value > short.MaxValue) + { value = short.MaxValue; + } if (value < short.MinValue) + { value = short.MinValue; + } return (short)value; } @@ -109,7 +115,7 @@ namespace Ryujinx.Audio.Renderer.Dsp ReadOnlySpan targetInput; - targetInput = input.Slice(nibbles / 2); + targetInput = input[(nibbles / 2)..]; while (remaining > 0) { @@ -213,4 +219,4 @@ namespace Ryujinx.Audio.Renderer.Dsp return decodedCount; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/AudioProcessor.cs b/src/Ryujinx.Audio/Renderer/Dsp/AudioProcessor.cs index 899c2ef97..9c885b2cf 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/AudioProcessor.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/AudioProcessor.cs @@ -18,7 +18,7 @@ namespace Ryujinx.Audio.Renderer.Dsp Start, Stop, RenderStart, - RenderEnd + RenderEnd, } private class RendererSession @@ -36,7 +36,7 @@ namespace Ryujinx.Audio.Renderer.Dsp private long _lastTime; private long _playbackEnds; - private ManualResetEvent _event; + private readonly ManualResetEvent _event; private ManualResetEvent _pauseEvent; @@ -45,6 +45,7 @@ namespace Ryujinx.Audio.Renderer.Dsp _event = new ManualResetEvent(false); } +#pragma warning disable IDE0051 // Remove unused private member private static uint GetHardwareChannelCount(IHardwareDeviceDriver deviceDriver) { // Get the real device driver (In case the compat layer is on top of it). @@ -54,12 +55,11 @@ namespace Ryujinx.Audio.Renderer.Dsp { return 6; } - else - { - // NOTE: We default to stereo as this will get downmixed to mono by the compat layer if it's not compatible. - return 2; - } + + // NOTE: We default to stereo as this will get downmixed to mono by the compat layer if it's not compatible. + return 2; } +#pragma warning restore IDE0051 public void Start(IHardwareDeviceDriver deviceDriver, float volume) { @@ -110,7 +110,7 @@ namespace Ryujinx.Audio.Renderer.Dsp { CommandList = commands, RenderingLimit = renderingLimit, - AppletResourceId = appletResourceId + AppletResourceId = appletResourceId, }; } @@ -171,7 +171,7 @@ namespace Ryujinx.Audio.Renderer.Dsp { _workerThread = new Thread(Work) { - Name = "AudioProcessor.Worker" + Name = "AudioProcessor.Worker", }; _workerThread.Start(); @@ -260,6 +260,7 @@ namespace Ryujinx.Audio.Renderer.Dsp public void Dispose() { + GC.SuppressFinalize(this); Dispose(true); } @@ -271,4 +272,4 @@ namespace Ryujinx.Audio.Renderer.Dsp } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/BiquadFilterHelper.cs b/src/Ryujinx.Audio/Renderer/Dsp/BiquadFilterHelper.cs index 98460ff1a..1a51a1fbd 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/BiquadFilterHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/BiquadFilterHelper.cs @@ -80,4 +80,4 @@ namespace Ryujinx.Audio.Renderer.Dsp } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/AdpcmDataSourceCommandVersion1.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/AdpcmDataSourceCommandVersion1.cs index 1fe6069f7..51a12b4e7 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/AdpcmDataSourceCommandVersion1.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/AdpcmDataSourceCommandVersion1.cs @@ -1,7 +1,9 @@ using Ryujinx.Audio.Common; using Ryujinx.Audio.Renderer.Common; +using Ryujinx.Audio.Renderer.Server.Voice; using System; using static Ryujinx.Audio.Renderer.Parameter.VoiceInParameter; +using WaveBuffer = Ryujinx.Audio.Renderer.Common.WaveBuffer; namespace Ryujinx.Audio.Renderer.Dsp.Command { @@ -29,7 +31,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command public DecodingBehaviour DecodingBehaviour { get; } - public AdpcmDataSourceCommandVersion1(ref Server.Voice.VoiceState serverState, Memory state, ushort outputBufferIndex, int nodeId) + public AdpcmDataSourceCommandVersion1(ref VoiceState serverState, Memory state, ushort outputBufferIndex, int nodeId) { Enabled = true; NodeId = nodeId; @@ -57,7 +59,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command { Span outputBuffer = context.GetBuffer(OutputBufferIndex); - DataSourceHelper.WaveBufferInformation info = new DataSourceHelper.WaveBufferInformation + DataSourceHelper.WaveBufferInformation info = new() { SourceSampleRate = SampleRate, SampleFormat = SampleFormat.Adpcm, @@ -72,4 +74,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command DataSourceHelper.ProcessWaveBuffers(context.MemoryManager, outputBuffer, ref info, WaveBuffers, ref State.Span[0], context.SampleRate, (int)context.SampleCount); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/AuxiliaryBufferCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/AuxiliaryBufferCommand.cs index 5c3c0324b..7ed32800f 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/AuxiliaryBufferCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/AuxiliaryBufferCommand.cs @@ -155,7 +155,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command if (readResult != context.SampleCount) { - outputBuffer.Slice((int)readResult, (int)context.SampleCount - (int)readResult).Fill(0); + outputBuffer[(int)readResult..(int)context.SampleCount].Clear(); } } else @@ -170,4 +170,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/BiquadFilterCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/BiquadFilterCommand.cs index b994c1cb9..f56dd70e3 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/BiquadFilterCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/BiquadFilterCommand.cs @@ -48,4 +48,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command BiquadFilterHelper.ProcessBiquadFilter(ref _parameter, ref state, outputBuffer, inputBuffer, context.SampleCount); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/CaptureBufferCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/CaptureBufferCommand.cs index da1cb2546..01bff1e7d 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/CaptureBufferCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/CaptureBufferCommand.cs @@ -133,4 +133,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/ClearMixBufferCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/ClearMixBufferCommand.cs index 9e653e804..f0f85b0b2 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/ClearMixBufferCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/ClearMixBufferCommand.cs @@ -21,4 +21,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command context.ClearBuffers(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandList.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandList.cs index 2cbed9c2b..19a9576f7 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandList.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandList.cs @@ -71,7 +71,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command return (IntPtr)((float*)_buffersMemoryHandle.Pointer + index * _sampleCount); } - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(index), index, null); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -149,7 +149,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command public void Dispose() { + GC.SuppressFinalize(this); _buffersMemoryHandle.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandType.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandType.cs index 9ce181b17..098a04a04 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandType.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/CommandType.cs @@ -32,6 +32,6 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command LimiterVersion2, GroupedBiquadFilter, CaptureBuffer, - Compressor + Compressor, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/CompressorCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/CompressorCommand.cs index 34231e614..01291852e 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/CompressorCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/CompressorCommand.cs @@ -1,6 +1,7 @@ using Ryujinx.Audio.Renderer.Dsp.Effect; using Ryujinx.Audio.Renderer.Dsp.State; using Ryujinx.Audio.Renderer.Parameter.Effect; +using Ryujinx.Audio.Renderer.Server.Effect; using System; using System.Diagnostics; @@ -51,11 +52,11 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command if (IsEffectEnabled) { - if (_parameter.Status == Server.Effect.UsageState.Invalid) + if (_parameter.Status == UsageState.Invalid) { state = new CompressorState(ref _parameter); } - else if (_parameter.Status == Server.Effect.UsageState.New) + else if (_parameter.Status == UsageState.New) { state.UpdateParameter(ref _parameter); } diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/CopyMixBufferCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/CopyMixBufferCommand.cs index 7237fddf6..3f6aa8390 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/CopyMixBufferCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/CopyMixBufferCommand.cs @@ -27,4 +27,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command context.CopyBuffer(OutputBufferIndex, InputBufferIndex); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/DataSourceVersion2Command.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/DataSourceVersion2Command.cs index c1503b6a0..e82d403bf 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/DataSourceVersion2Command.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/DataSourceVersion2Command.cs @@ -1,7 +1,9 @@ using Ryujinx.Audio.Common; using Ryujinx.Audio.Renderer.Common; +using Ryujinx.Audio.Renderer.Server.Voice; using System; using static Ryujinx.Audio.Renderer.Parameter.VoiceInParameter; +using WaveBuffer = Ryujinx.Audio.Renderer.Common.WaveBuffer; namespace Ryujinx.Audio.Renderer.Dsp.Command { @@ -37,7 +39,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command public SampleRateConversionQuality SrcQuality { get; } - public DataSourceVersion2Command(ref Server.Voice.VoiceState serverState, Memory state, ushort outputBufferIndex, ushort channelIndex, int nodeId) + public DataSourceVersion2Command(ref VoiceState serverState, Memory state, ushort outputBufferIndex, ushort channelIndex, int nodeId) { Enabled = true; NodeId = nodeId; @@ -72,24 +74,20 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command private static CommandType GetCommandTypeBySampleFormat(SampleFormat sampleFormat) { - switch (sampleFormat) + return sampleFormat switch { - case SampleFormat.Adpcm: - return CommandType.AdpcmDataSourceVersion2; - case SampleFormat.PcmInt16: - return CommandType.PcmInt16DataSourceVersion2; - case SampleFormat.PcmFloat: - return CommandType.PcmFloatDataSourceVersion2; - default: - throw new NotImplementedException($"{sampleFormat}"); - } + SampleFormat.Adpcm => CommandType.AdpcmDataSourceVersion2, + SampleFormat.PcmInt16 => CommandType.PcmInt16DataSourceVersion2, + SampleFormat.PcmFloat => CommandType.PcmFloatDataSourceVersion2, + _ => throw new NotImplementedException($"{sampleFormat}"), + }; } public void Process(CommandList context) { Span outputBuffer = context.GetBuffer(OutputBufferIndex); - DataSourceHelper.WaveBufferInformation info = new DataSourceHelper.WaveBufferInformation + DataSourceHelper.WaveBufferInformation info = new() { SourceSampleRate = SampleRate, SampleFormat = SampleFormat, @@ -99,10 +97,10 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command ExtraParameterSize = ExtraParameterSize, ChannelIndex = (int)ChannelIndex, ChannelCount = (int)ChannelCount, - SrcQuality = SrcQuality + SrcQuality = SrcQuality, }; DataSourceHelper.ProcessWaveBuffers(context.MemoryManager, outputBuffer, ref info, WaveBuffers, ref State.Span[0], context.SampleRate, (int)context.SampleCount); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/DelayCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/DelayCommand.cs index e7e179389..003806cf7 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/DelayCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/DelayCommand.cs @@ -87,18 +87,18 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command float dryGain = FixedPointHelper.ToFloat(Parameter.DryGain, FixedPointPrecision); float outGain = FixedPointHelper.ToFloat(Parameter.OutGain, FixedPointPrecision); - Matrix2x2 delayFeedback = new Matrix2x2(delayFeedbackBaseGain, delayFeedbackCrossGain, + Matrix2x2 delayFeedback = new(delayFeedbackBaseGain, delayFeedbackCrossGain, delayFeedbackCrossGain, delayFeedbackBaseGain); for (int i = 0; i < sampleCount; i++) { - Vector2 channelInput = new Vector2 + Vector2 channelInput = new() { X = *((float*)inputBuffers[0] + i) * 64, Y = *((float*)inputBuffers[1] + i) * 64, }; - Vector2 delayLineValues = new Vector2() + Vector2 delayLineValues = new() { X = state.DelayLines[0].Read(), Y = state.DelayLines[1].Read(), @@ -124,7 +124,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command float dryGain = FixedPointHelper.ToFloat(Parameter.DryGain, FixedPointPrecision); float outGain = FixedPointHelper.ToFloat(Parameter.OutGain, FixedPointPrecision); - Matrix4x4 delayFeedback = new Matrix4x4(delayFeedbackBaseGain, delayFeedbackCrossGain, delayFeedbackCrossGain, 0.0f, + Matrix4x4 delayFeedback = new(delayFeedbackBaseGain, delayFeedbackCrossGain, delayFeedbackCrossGain, 0.0f, delayFeedbackCrossGain, delayFeedbackBaseGain, 0.0f, delayFeedbackCrossGain, delayFeedbackCrossGain, 0.0f, delayFeedbackBaseGain, delayFeedbackCrossGain, 0.0f, delayFeedbackCrossGain, delayFeedbackCrossGain, delayFeedbackBaseGain); @@ -132,20 +132,20 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command for (int i = 0; i < sampleCount; i++) { - Vector4 channelInput = new Vector4 + Vector4 channelInput = new() { X = *((float*)inputBuffers[0] + i) * 64, Y = *((float*)inputBuffers[1] + i) * 64, Z = *((float*)inputBuffers[2] + i) * 64, - W = *((float*)inputBuffers[3] + i) * 64 + W = *((float*)inputBuffers[3] + i) * 64, }; - Vector4 delayLineValues = new Vector4() + Vector4 delayLineValues = new() { X = state.DelayLines[0].Read(), Y = state.DelayLines[1].Read(), Z = state.DelayLines[2].Read(), - W = state.DelayLines[3].Read() + W = state.DelayLines[3].Read(), }; Vector4 temp = MatrixHelper.Transform(ref delayLineValues, ref delayFeedback) + channelInput * inGain; @@ -171,7 +171,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command float dryGain = FixedPointHelper.ToFloat(Parameter.DryGain, FixedPointPrecision); float outGain = FixedPointHelper.ToFloat(Parameter.OutGain, FixedPointPrecision); - Matrix6x6 delayFeedback = new Matrix6x6(delayFeedbackBaseGain, 0.0f, delayFeedbackCrossGain, 0.0f, delayFeedbackCrossGain, 0.0f, + Matrix6x6 delayFeedback = new(delayFeedbackBaseGain, 0.0f, delayFeedbackCrossGain, 0.0f, delayFeedbackCrossGain, 0.0f, 0.0f, delayFeedbackBaseGain, delayFeedbackCrossGain, 0.0f, 0.0f, delayFeedbackCrossGain, delayFeedbackCrossGain, delayFeedbackCrossGain, delayFeedbackBaseGain, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, feedbackGain, 0.0f, 0.0f, @@ -180,24 +180,24 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command for (int i = 0; i < sampleCount; i++) { - Vector6 channelInput = new Vector6 + Vector6 channelInput = new() { X = *((float*)inputBuffers[0] + i) * 64, Y = *((float*)inputBuffers[1] + i) * 64, Z = *((float*)inputBuffers[2] + i) * 64, W = *((float*)inputBuffers[3] + i) * 64, V = *((float*)inputBuffers[4] + i) * 64, - U = *((float*)inputBuffers[5] + i) * 64 + U = *((float*)inputBuffers[5] + i) * 64, }; - Vector6 delayLineValues = new Vector6 + Vector6 delayLineValues = new() { X = state.DelayLines[0].Read(), Y = state.DelayLines[1].Read(), Z = state.DelayLines[2].Read(), W = state.DelayLines[3].Read(), V = state.DelayLines[4].Read(), - U = state.DelayLines[5].Read() + U = state.DelayLines[5].Read(), }; Vector6 temp = MatrixHelper.Transform(ref delayLineValues, ref delayFeedback) + channelInput * inGain; diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/DepopForMixBuffersCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/DepopForMixBuffersCommand.cs index 1dba56e6c..ff38f38ca 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/DepopForMixBuffersCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/DepopForMixBuffersCommand.cs @@ -55,17 +55,15 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command return -depopValue; } - else + + for (int i = 0; i < sampleCount; i++) { - for (int i = 0; i < sampleCount; i++) - { - depopValue = FloatingPointHelper.MultiplyRoundDown(Decay, depopValue); + depopValue = FloatingPointHelper.MultiplyRoundDown(Decay, depopValue); - buffer[i] += depopValue; - } - - return depopValue; + buffer[i] += depopValue; } + + return depopValue; } public void Process(CommandList context) @@ -89,4 +87,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/DepopPrepareCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/DepopPrepareCommand.cs index d02f7c121..c64bbdc57 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/DepopPrepareCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/DepopPrepareCommand.cs @@ -54,4 +54,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/DownMixSurroundToStereoCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/DownMixSurroundToStereoCommand.cs index 79cefcc53..8997b0dbd 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/DownMixSurroundToStereoCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/DownMixSurroundToStereoCommand.cs @@ -65,4 +65,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command context.ClearBuffer(OutputBufferIndices[5]); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/GroupedBiquadFilterCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/GroupedBiquadFilterCommand.cs index b190cc10d..7af851bdc 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/GroupedBiquadFilterCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/GroupedBiquadFilterCommand.cs @@ -14,11 +14,11 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command public uint EstimatedProcessingTime { get; set; } - private BiquadFilterParameter[] _parameters; - private Memory _biquadFilterStates; - private int _inputBufferIndex; - private int _outputBufferIndex; - private bool[] _isInitialized; + private readonly BiquadFilterParameter[] _parameters; + private readonly Memory _biquadFilterStates; + private readonly int _inputBufferIndex; + private readonly int _outputBufferIndex; + private readonly bool[] _isInitialized; public GroupedBiquadFilterCommand(int baseIndex, ReadOnlySpan filters, Memory biquadFilterStateMemory, int inputBufferOffset, int outputBufferOffset, ReadOnlySpan isInitialized, int nodeId) { @@ -59,4 +59,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/ICommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/ICommand.cs index d281e6e9f..34a62c58d 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/ICommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/ICommand.cs @@ -17,4 +17,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command return false; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion1.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion1.cs index a464ad704..3ba0b5884 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion1.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion1.cs @@ -1,5 +1,6 @@ using Ryujinx.Audio.Renderer.Dsp.State; using Ryujinx.Audio.Renderer.Parameter.Effect; +using Ryujinx.Audio.Renderer.Server.Effect; using System; using System.Diagnostics; @@ -50,13 +51,13 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command if (IsEffectEnabled) { - if (Parameter.Status == Server.Effect.UsageState.Invalid) + if (Parameter.Status == UsageState.Invalid) { state = new LimiterState(ref _parameter, WorkBuffer); } - else if (Parameter.Status == Server.Effect.UsageState.New) + else if (Parameter.Status == UsageState.New) { - state.UpdateParameter(ref _parameter); + LimiterState.UpdateParameter(ref _parameter); } } @@ -141,4 +142,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs index 950de97b8..682098670 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs @@ -1,6 +1,7 @@ using Ryujinx.Audio.Renderer.Dsp.State; using Ryujinx.Audio.Renderer.Parameter; using Ryujinx.Audio.Renderer.Parameter.Effect; +using Ryujinx.Audio.Renderer.Server.Effect; using System; using System.Diagnostics; using System.Runtime.InteropServices; @@ -54,13 +55,13 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command if (IsEffectEnabled) { - if (Parameter.Status == Server.Effect.UsageState.Invalid) + if (Parameter.Status == UsageState.Invalid) { state = new LimiterState(ref _parameter, WorkBuffer); } - else if (Parameter.Status == Server.Effect.UsageState.New) + else if (Parameter.Status == UsageState.New) { - state.UpdateParameter(ref _parameter); + LimiterState.UpdateParameter(ref _parameter); } } @@ -160,4 +161,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/MixCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/MixCommand.cs index 2616bda57..c701f80eb 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/MixCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/MixCommand.cs @@ -134,4 +134,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command ProcessMix(outputBuffer, inputBuffer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/MixRampCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/MixRampCommand.cs index 76a1aba25..f77a233e1 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/MixRampCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/MixRampCommand.cs @@ -65,4 +65,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command State.Span[0].LastSamples[LastSampleIndex] = ProcessMixRamp(outputBuffer, inputBuffer, (int)context.SampleCount); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/MixRampGroupedCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/MixRampGroupedCommand.cs index e348e3588..3c7dd63b2 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/MixRampGroupedCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/MixRampGroupedCommand.cs @@ -48,7 +48,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private float ProcessMixRampGrouped(Span outputBuffer, ReadOnlySpan inputBuffer, float volume0, float volume1, int sampleCount) + private static float ProcessMixRampGrouped(Span outputBuffer, ReadOnlySpan inputBuffer, float volume0, float volume1, int sampleCount) { float ramp = (volume1 - volume0) / sampleCount; float volume = volume0; @@ -88,4 +88,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/PcmFloatDataSourceCommandVersion1.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/PcmFloatDataSourceCommandVersion1.cs index 7cec7d2ab..585edc058 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/PcmFloatDataSourceCommandVersion1.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/PcmFloatDataSourceCommandVersion1.cs @@ -1,7 +1,9 @@ using Ryujinx.Audio.Common; using Ryujinx.Audio.Renderer.Common; +using Ryujinx.Audio.Renderer.Server.Voice; using System; using static Ryujinx.Audio.Renderer.Parameter.VoiceInParameter; +using WaveBuffer = Ryujinx.Audio.Renderer.Common.WaveBuffer; namespace Ryujinx.Audio.Renderer.Dsp.Command { @@ -28,7 +30,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command public Memory State { get; } public DecodingBehaviour DecodingBehaviour { get; } - public PcmFloatDataSourceCommandVersion1(ref Server.Voice.VoiceState serverState, Memory state, ushort outputBufferIndex, ushort channelIndex, int nodeId) + public PcmFloatDataSourceCommandVersion1(ref VoiceState serverState, Memory state, ushort outputBufferIndex, ushort channelIndex, int nodeId) { Enabled = true; NodeId = nodeId; @@ -56,7 +58,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command { Span outputBuffer = context.GetBuffer(OutputBufferIndex); - DataSourceHelper.WaveBufferInformation info = new DataSourceHelper.WaveBufferInformation + DataSourceHelper.WaveBufferInformation info = new() { SourceSampleRate = SampleRate, SampleFormat = SampleFormat.PcmFloat, @@ -71,4 +73,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command DataSourceHelper.ProcessWaveBuffers(context.MemoryManager, outputBuffer, ref info, WaveBuffers, ref State.Span[0], context.SampleRate, (int)context.SampleCount); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/PcmInt16DataSourceCommandVersion1.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/PcmInt16DataSourceCommandVersion1.cs index dfe9814fe..6f01219f3 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/PcmInt16DataSourceCommandVersion1.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/PcmInt16DataSourceCommandVersion1.cs @@ -1,7 +1,9 @@ using Ryujinx.Audio.Common; using Ryujinx.Audio.Renderer.Common; +using Ryujinx.Audio.Renderer.Server.Voice; using System; using static Ryujinx.Audio.Renderer.Parameter.VoiceInParameter; +using WaveBuffer = Ryujinx.Audio.Renderer.Common.WaveBuffer; namespace Ryujinx.Audio.Renderer.Dsp.Command { @@ -28,7 +30,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command public Memory State { get; } public DecodingBehaviour DecodingBehaviour { get; } - public PcmInt16DataSourceCommandVersion1(ref Server.Voice.VoiceState serverState, Memory state, ushort outputBufferIndex, ushort channelIndex, int nodeId) + public PcmInt16DataSourceCommandVersion1(ref VoiceState serverState, Memory state, ushort outputBufferIndex, ushort channelIndex, int nodeId) { Enabled = true; NodeId = nodeId; @@ -56,7 +58,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command { Span outputBuffer = context.GetBuffer(OutputBufferIndex); - DataSourceHelper.WaveBufferInformation info = new DataSourceHelper.WaveBufferInformation + DataSourceHelper.WaveBufferInformation info = new() { SourceSampleRate = SampleRate, SampleFormat = SampleFormat.PcmInt16, @@ -71,4 +73,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command DataSourceHelper.ProcessWaveBuffers(context.MemoryManager, outputBuffer, ref info, WaveBuffers, ref State.Span[0], context.SampleRate, (int)context.SampleCount); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/PerformanceCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/PerformanceCommand.cs index d3e3f8056..d3d2ee306 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/PerformanceCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/PerformanceCommand.cs @@ -8,7 +8,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command { Invalid, Start, - End + End, } public bool Enabled { get; set; } @@ -44,4 +44,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/Reverb3dCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/Reverb3dCommand.cs index d1177e60f..8cdd4843b 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/Reverb3dCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/Reverb3dCommand.cs @@ -9,21 +9,21 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command { public class Reverb3dCommand : ICommand { - private static readonly int[] OutputEarlyIndicesTableMono = new int[20] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - private static readonly int[] TargetEarlyDelayLineIndicesTableMono = new int[20] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; - private static readonly int[] TargetOutputFeedbackIndicesTableMono = new int[1] { 0 }; + private static readonly int[] _outputEarlyIndicesTableMono = new int[20] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + private static readonly int[] _targetEarlyDelayLineIndicesTableMono = new int[20] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; + private static readonly int[] _targetOutputFeedbackIndicesTableMono = new int[1] { 0 }; - private static readonly int[] OutputEarlyIndicesTableStereo = new int[20] { 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1 }; - private static readonly int[] TargetEarlyDelayLineIndicesTableStereo = new int[20] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; - private static readonly int[] TargetOutputFeedbackIndicesTableStereo = new int[2] { 0, 1 }; + private static readonly int[] _outputEarlyIndicesTableStereo = new int[20] { 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1 }; + private static readonly int[] _targetEarlyDelayLineIndicesTableStereo = new int[20] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; + private static readonly int[] _targetOutputFeedbackIndicesTableStereo = new int[2] { 0, 1 }; - private static readonly int[] OutputEarlyIndicesTableQuadraphonic = new int[20] { 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 3, 3, 3 }; - private static readonly int[] TargetEarlyDelayLineIndicesTableQuadraphonic = new int[20] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; - private static readonly int[] TargetOutputFeedbackIndicesTableQuadraphonic = new int[4] { 0, 1, 2, 3 }; + private static readonly int[] _outputEarlyIndicesTableQuadraphonic = new int[20] { 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 3, 3, 3 }; + private static readonly int[] _targetEarlyDelayLineIndicesTableQuadraphonic = new int[20] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; + private static readonly int[] _targetOutputFeedbackIndicesTableQuadraphonic = new int[4] { 0, 1, 2, 3 }; - private static readonly int[] OutputEarlyIndicesTableSurround = new int[40] { 4, 5, 0, 5, 0, 5, 1, 5, 1, 5, 1, 5, 1, 5, 2, 5, 2, 5, 2, 5, 1, 5, 1, 5, 1, 5, 0, 5, 0, 5, 0, 5, 0, 5, 3, 5, 3, 5, 3, 5 }; - private static readonly int[] TargetEarlyDelayLineIndicesTableSurround = new int[40] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19 }; - private static readonly int[] TargetOutputFeedbackIndicesTableSurround = new int[6] { 0, 1, 2, 3, -1, 3 }; + private static readonly int[] _outputEarlyIndicesTableSurround = new int[40] { 4, 5, 0, 5, 0, 5, 1, 5, 1, 5, 1, 5, 1, 5, 2, 5, 2, 5, 2, 5, 1, 5, 1, 5, 1, 5, 0, 5, 0, 5, 0, 5, 0, 5, 3, 5, 3, 5, 3, 5 }; + private static readonly int[] _targetEarlyDelayLineIndicesTableSurround = new int[40] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19 }; + private static readonly int[] _targetOutputFeedbackIndicesTableSurround = new int[6] { 0, 1, 2, 3, -1, 3 }; public bool Enabled { get; set; } @@ -73,25 +73,25 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ProcessReverb3dMono(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { - ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, OutputEarlyIndicesTableMono, TargetEarlyDelayLineIndicesTableMono, TargetOutputFeedbackIndicesTableMono); + ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, _outputEarlyIndicesTableMono, _targetEarlyDelayLineIndicesTableMono, _targetOutputFeedbackIndicesTableMono); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ProcessReverb3dStereo(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { - ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, OutputEarlyIndicesTableStereo, TargetEarlyDelayLineIndicesTableStereo, TargetOutputFeedbackIndicesTableStereo); + ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, _outputEarlyIndicesTableStereo, _targetEarlyDelayLineIndicesTableStereo, _targetOutputFeedbackIndicesTableStereo); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ProcessReverb3dQuadraphonic(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { - ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, OutputEarlyIndicesTableQuadraphonic, TargetEarlyDelayLineIndicesTableQuadraphonic, TargetOutputFeedbackIndicesTableQuadraphonic); + ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, _outputEarlyIndicesTableQuadraphonic, _targetEarlyDelayLineIndicesTableQuadraphonic, _targetOutputFeedbackIndicesTableQuadraphonic); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ProcessReverb3dSurround(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount) { - ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, OutputEarlyIndicesTableSurround, TargetEarlyDelayLineIndicesTableSurround, TargetOutputFeedbackIndicesTableSurround); + ProcessReverb3dGeneric(ref state, outputBuffers, inputBuffers, sampleCount, _outputEarlyIndicesTableSurround, _targetEarlyDelayLineIndicesTableSurround, _targetOutputFeedbackIndicesTableSurround); } private unsafe void ProcessReverb3dGeneric(ref Reverb3dState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount, ReadOnlySpan outputEarlyIndicesTable, ReadOnlySpan targetEarlyDelayLineIndicesTable, ReadOnlySpan targetOutputFeedbackIndicesTable) @@ -109,7 +109,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command for (int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { - outputValues.Fill(0); + outputValues.Clear(); float tapOut = state.PreDelayLine.TapUnsafe(state.ReflectionDelayTime, DelayLineSampleIndexOffset); diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/ReverbCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/ReverbCommand.cs index cd08b838a..f494b3028 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/ReverbCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/ReverbCommand.cs @@ -1,5 +1,6 @@ using Ryujinx.Audio.Renderer.Dsp.State; using Ryujinx.Audio.Renderer.Parameter.Effect; +using Ryujinx.Audio.Renderer.Server.Effect; using System; using System.Diagnostics; using System.Runtime.CompilerServices; @@ -8,25 +9,25 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command { public class ReverbCommand : ICommand { - private static readonly int[] OutputEarlyIndicesTableMono = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - private static readonly int[] TargetEarlyDelayLineIndicesTableMono = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - private static readonly int[] OutputIndicesTableMono = new int[4] { 0, 0, 0, 0 }; - private static readonly int[] TargetOutputFeedbackIndicesTableMono = new int[4] { 0, 1, 2, 3 }; + private static readonly int[] _outputEarlyIndicesTableMono = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + private static readonly int[] _targetEarlyDelayLineIndicesTableMono = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + private static readonly int[] _outputIndicesTableMono = new int[4] { 0, 0, 0, 0 }; + private static readonly int[] _targetOutputFeedbackIndicesTableMono = new int[4] { 0, 1, 2, 3 }; - private static readonly int[] OutputEarlyIndicesTableStereo = new int[10] { 0, 0, 1, 1, 0, 1, 0, 0, 1, 1 }; - private static readonly int[] TargetEarlyDelayLineIndicesTableStereo = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - private static readonly int[] OutputIndicesTableStereo = new int[4] { 0, 0, 1, 1 }; - private static readonly int[] TargetOutputFeedbackIndicesTableStereo = new int[4] { 2, 0, 3, 1 }; + private static readonly int[] _outputEarlyIndicesTableStereo = new int[10] { 0, 0, 1, 1, 0, 1, 0, 0, 1, 1 }; + private static readonly int[] _targetEarlyDelayLineIndicesTableStereo = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + private static readonly int[] _outputIndicesTableStereo = new int[4] { 0, 0, 1, 1 }; + private static readonly int[] _targetOutputFeedbackIndicesTableStereo = new int[4] { 2, 0, 3, 1 }; - private static readonly int[] OutputEarlyIndicesTableQuadraphonic = new int[10] { 0, 0, 1, 1, 0, 1, 2, 2, 3, 3 }; - private static readonly int[] TargetEarlyDelayLineIndicesTableQuadraphonic = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - private static readonly int[] OutputIndicesTableQuadraphonic = new int[4] { 0, 1, 2, 3 }; - private static readonly int[] TargetOutputFeedbackIndicesTableQuadraphonic = new int[4] { 0, 1, 2, 3 }; + private static readonly int[] _outputEarlyIndicesTableQuadraphonic = new int[10] { 0, 0, 1, 1, 0, 1, 2, 2, 3, 3 }; + private static readonly int[] _targetEarlyDelayLineIndicesTableQuadraphonic = new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + private static readonly int[] _outputIndicesTableQuadraphonic = new int[4] { 0, 1, 2, 3 }; + private static readonly int[] _targetOutputFeedbackIndicesTableQuadraphonic = new int[4] { 0, 1, 2, 3 }; - private static readonly int[] OutputEarlyIndicesTableSurround = new int[20] { 0, 5, 0, 5, 1, 5, 1, 5, 4, 5, 4, 5, 2, 5, 2, 5, 3, 5, 3, 5 }; - private static readonly int[] TargetEarlyDelayLineIndicesTableSurround = new int[20] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9 }; - private static readonly int[] OutputIndicesTableSurround = new int[Constants.ChannelCountMax] { 0, 1, 2, 3, 4, 5 }; - private static readonly int[] TargetOutputFeedbackIndicesTableSurround = new int[Constants.ChannelCountMax] { 0, 1, 2, 3, -1, 3 }; + private static readonly int[] _outputEarlyIndicesTableSurround = new int[20] { 0, 5, 0, 5, 1, 5, 1, 5, 4, 5, 4, 5, 2, 5, 2, 5, 3, 5, 3, 5 }; + private static readonly int[] _targetEarlyDelayLineIndicesTableSurround = new int[20] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9 }; + private static readonly int[] _outputIndicesTableSurround = new int[Constants.ChannelCountMax] { 0, 1, 2, 3, 4, 5 }; + private static readonly int[] _targetOutputFeedbackIndicesTableSurround = new int[Constants.ChannelCountMax] { 0, 1, 2, 3, -1, 3 }; public bool Enabled { get; set; } @@ -82,10 +83,10 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command outputBuffers, inputBuffers, sampleCount, - OutputEarlyIndicesTableMono, - TargetEarlyDelayLineIndicesTableMono, - TargetOutputFeedbackIndicesTableMono, - OutputIndicesTableMono); + _outputEarlyIndicesTableMono, + _targetEarlyDelayLineIndicesTableMono, + _targetOutputFeedbackIndicesTableMono, + _outputIndicesTableMono); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -95,10 +96,10 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command outputBuffers, inputBuffers, sampleCount, - OutputEarlyIndicesTableStereo, - TargetEarlyDelayLineIndicesTableStereo, - TargetOutputFeedbackIndicesTableStereo, - OutputIndicesTableStereo); + _outputEarlyIndicesTableStereo, + _targetEarlyDelayLineIndicesTableStereo, + _targetOutputFeedbackIndicesTableStereo, + _outputIndicesTableStereo); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -108,10 +109,10 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command outputBuffers, inputBuffers, sampleCount, - OutputEarlyIndicesTableQuadraphonic, - TargetEarlyDelayLineIndicesTableQuadraphonic, - TargetOutputFeedbackIndicesTableQuadraphonic, - OutputIndicesTableQuadraphonic); + _outputEarlyIndicesTableQuadraphonic, + _targetEarlyDelayLineIndicesTableQuadraphonic, + _targetOutputFeedbackIndicesTableQuadraphonic, + _outputIndicesTableQuadraphonic); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -121,10 +122,10 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command outputBuffers, inputBuffers, sampleCount, - OutputEarlyIndicesTableSurround, - TargetEarlyDelayLineIndicesTableSurround, - TargetOutputFeedbackIndicesTableSurround, - OutputIndicesTableSurround); + _outputEarlyIndicesTableSurround, + _targetEarlyDelayLineIndicesTableSurround, + _targetOutputFeedbackIndicesTableSurround, + _outputIndicesTableSurround); } private unsafe void ProcessReverbGeneric(ref ReverbState state, ReadOnlySpan outputBuffers, ReadOnlySpan inputBuffers, uint sampleCount, ReadOnlySpan outputEarlyIndicesTable, ReadOnlySpan targetEarlyDelayLineIndicesTable, ReadOnlySpan targetOutputFeedbackIndicesTable, ReadOnlySpan outputIndicesTable) @@ -143,7 +144,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command for (int sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { - outputValues.Fill(0); + outputValues.Clear(); for (int i = 0; i < targetEarlyDelayLineIndicesTable.Length; i++) { @@ -263,11 +264,11 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command if (IsEffectEnabled) { - if (Parameter.Status == Server.Effect.UsageState.Invalid) + if (Parameter.Status == UsageState.Invalid) { state = new ReverbState(ref _parameter, WorkBuffer, IsLongSizePreDelaySupported); } - else if (Parameter.Status == Server.Effect.UsageState.New) + else if (Parameter.Status == UsageState.New) { state.UpdateParameter(ref _parameter); } @@ -276,4 +277,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command ProcessReverb(context, ref state); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/UpsampleCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/UpsampleCommand.cs index 0870d59ce..8882500cd 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/UpsampleCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/UpsampleCommand.cs @@ -67,4 +67,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/VolumeCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/VolumeCommand.cs index 0628f6d81..5deeb07f1 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/VolumeCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/VolumeCommand.cs @@ -134,4 +134,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command ProcessVolume(outputBuffer, inputBuffer); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/VolumeRampCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/VolumeRampCommand.cs index 5c0c88451..bffbcbc63 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/VolumeRampCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/VolumeRampCommand.cs @@ -53,4 +53,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command ProcessVolumeRamp(outputBuffer, inputBuffer, (int)context.SampleCount); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/DataSourceHelper.cs b/src/Ryujinx.Audio/Renderer/Dsp/DataSourceHelper.cs index 12e0f13ff..98657bd13 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/DataSourceHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/DataSourceHelper.cs @@ -76,7 +76,7 @@ namespace Ryujinx.Audio.Renderer.Dsp if (!info.DecodingBehaviour.HasFlag(DecodingBehaviour.SkipPitchAndSampleRateConversion)) { - voiceState.Pitch.AsSpan().Slice(0, pitchMaxLength).CopyTo(tempBuffer); + voiceState.Pitch.AsSpan()[..pitchMaxLength].CopyTo(tempBuffer); tempBufferIndex += pitchMaxLength; } @@ -107,7 +107,7 @@ namespace Ryujinx.Audio.Renderer.Dsp voiceState.LoopContext = memoryManager.Read(waveBuffer.Context); } - Span tempSpan = tempBuffer.Slice(tempBufferIndex + y); + Span tempSpan = tempBuffer[(tempBufferIndex + y)..]; int decodedSampleCount = -1; @@ -168,7 +168,7 @@ namespace Ryujinx.Audio.Renderer.Dsp decodedSampleCount = PcmHelper.Decode(tempSpan, waveBufferPcmFloat, targetSampleStartOffset, targetSampleEndOffset, info.ChannelIndex, info.ChannelCount); break; default: - Logger.Error?.Print(LogClass.AudioRenderer, $"Unsupported sample format " + info.SampleFormat); + Logger.Error?.Print(LogClass.AudioRenderer, "Unsupported sample format " + info.SampleFormat); break; } @@ -220,7 +220,7 @@ namespace Ryujinx.Audio.Renderer.Dsp } } - Span outputSpanInt = MemoryMarshal.Cast(outputBuffer.Slice(i)); + Span outputSpanInt = MemoryMarshal.Cast(outputBuffer[i..]); if (info.DecodingBehaviour.HasFlag(DecodingBehaviour.SkipPitchAndSampleRateConversion)) { @@ -231,9 +231,9 @@ namespace Ryujinx.Audio.Renderer.Dsp } else { - Span tempSpan = tempBuffer.Slice(tempBufferIndex + y); + Span tempSpan = tempBuffer[(tempBufferIndex + y)..]; - tempSpan.Slice(0, sampleCountToDecode - y).Fill(0); + tempSpan[..(sampleCountToDecode - y)].Clear(); ToFloat(outputBuffer, outputSpanInt, sampleCountToProcess); diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Effect/DecayDelay.cs b/src/Ryujinx.Audio/Renderer/Dsp/Effect/DecayDelay.cs index 37e066bf0..7253fdc92 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Effect/DecayDelay.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Effect/DecayDelay.cs @@ -49,4 +49,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Effect return _delayLine.Tap(sampleIndex); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Effect/DelayLine.cs b/src/Ryujinx.Audio/Renderer/Dsp/Effect/DelayLine.cs index 56890ebe8..8a3590a20 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Effect/DelayLine.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Effect/DelayLine.cs @@ -4,8 +4,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.Effect { public class DelayLine : IDelayLine { - private float[] _workBuffer; - private uint _sampleRate; + private readonly float[] _workBuffer; + private readonly uint _sampleRate; private uint _currentSampleIndex; private uint _lastSampleIndex; @@ -75,4 +75,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Effect return TapUnsafe(sampleIndex, -1); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Effect/DelayLineReverb3d.cs b/src/Ryujinx.Audio/Renderer/Dsp/Effect/DelayLineReverb3d.cs index a2ac9d265..ed8e7cfe0 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Effect/DelayLineReverb3d.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Effect/DelayLineReverb3d.cs @@ -4,8 +4,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.Effect { public class DelayLine3d : IDelayLine { - private float[] _workBuffer; - private uint _sampleRate; + private readonly float[] _workBuffer; + private readonly uint _sampleRate; private uint _currentSampleIndex; private uint _lastSampleIndex; @@ -73,4 +73,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Effect return TapUnsafe(sampleIndex, -1); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Effect/ExponentialMovingAverage.cs b/src/Ryujinx.Audio/Renderer/Dsp/Effect/ExponentialMovingAverage.cs index 78e46bf96..253400a5a 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Effect/ExponentialMovingAverage.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Effect/ExponentialMovingAverage.cs @@ -1,6 +1,4 @@ -using System.Runtime.CompilerServices; - -namespace Ryujinx.Audio.Renderer.Dsp.Effect +namespace Ryujinx.Audio.Renderer.Dsp.Effect { public struct ExponentialMovingAverage { @@ -11,7 +9,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Effect _mean = mean; } - public float Read() + public readonly float Read() { return _mean; } diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Effect/IDelayLine.cs b/src/Ryujinx.Audio/Renderer/Dsp/Effect/IDelayLine.cs index fd902525e..b408e294d 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Effect/IDelayLine.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Effect/IDelayLine.cs @@ -34,4 +34,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.Effect return (uint)MathF.Round(sampleRate * delayTime); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/FixedPointHelper.cs b/src/Ryujinx.Audio/Renderer/Dsp/FixedPointHelper.cs index 280e47c0c..d519de333 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/FixedPointHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/FixedPointHelper.cs @@ -36,4 +36,4 @@ namespace Ryujinx.Audio.Renderer.Dsp return ToInt(value + half, qBits); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/FloatingPointHelper.cs b/src/Ryujinx.Audio/Renderer/Dsp/FloatingPointHelper.cs index 6645e20a3..b231dbb6a 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/FloatingPointHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/FloatingPointHelper.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection.Metadata; using System.Runtime.CompilerServices; namespace Ryujinx.Audio.Renderer.Dsp @@ -39,7 +38,8 @@ namespace Ryujinx.Audio.Renderer.Dsp { return 1.0f; } - else if (x <= -5.3f) + + if (x <= -5.3f) { return 0.0f; } @@ -112,4 +112,4 @@ namespace Ryujinx.Audio.Renderer.Dsp return MathF.Sin(DegreesToRadians(value)); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/PcmHelper.cs b/src/Ryujinx.Audio/Renderer/Dsp/PcmHelper.cs index 0233a8d71..d209c515b 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/PcmHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/PcmHelper.cs @@ -1,5 +1,4 @@ using System; -using System.Numerics; using System.Runtime.CompilerServices; namespace Ryujinx.Audio.Renderer.Dsp @@ -62,7 +61,7 @@ namespace Ryujinx.Audio.Renderer.Dsp { for (int i = 0; i < input.Length; i++) { - output[i] = ((int)input[i]) << 16; + output[i] = input[i] << 16; } } @@ -127,4 +126,4 @@ namespace Ryujinx.Audio.Renderer.Dsp return (short)value; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/ResamplerHelper.cs b/src/Ryujinx.Audio/Renderer/Dsp/ResamplerHelper.cs index 7873c4d27..e44e9f41e 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/ResamplerHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/ResamplerHelper.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; @@ -11,8 +10,7 @@ namespace Ryujinx.Audio.Renderer.Dsp public static class ResamplerHelper { #region "Default Quality Lookup Tables" - private static short[] _normalCurveLut0 = new short[] - { + private static readonly short[] _normalCurveLut0 = { 6600, 19426, 6722, 3, 6479, 19424, 6845, 9, 6359, 19419, 6968, 15, 6239, 19412, 7093, 22, 6121, 19403, 7219, 28, 6004, 19391, 7345, 34, 5888, 19377, 7472, 41, 5773, 19361, 7600, 48, 5659, 19342, 7728, 55, 5546, 19321, 7857, 62, 5434, 19298, 7987, 69, 5323, 19273, 8118, 77, @@ -44,11 +42,10 @@ namespace Ryujinx.Audio.Renderer.Dsp 109, 8646, 19148, 4890, 101, 8513, 19183, 4997, 92, 8381, 19215, 5104, 84, 8249, 19245, 5213, 77, 8118, 19273, 5323, 69, 7987, 19298, 5434, 62, 7857, 19321, 5546, 55, 7728, 19342, 5659, 48, 7600, 19361, 5773, 41, 7472, 19377, 5888, 34, 7345, 19391, 6004, 28, 7219, 19403, 6121, - 22, 7093, 19412, 6239, 15, 6968, 19419, 6359, 9, 6845, 19424, 6479, 3, 6722, 19426, 6600 + 22, 7093, 19412, 6239, 15, 6968, 19419, 6359, 9, 6845, 19424, 6479, 3, 6722, 19426, 6600, }; - private static short[] _normalCurveLut1 = new short[] - { + private static readonly short[] _normalCurveLut1 = { -68, 32639, 69, -5, -200, 32630, 212, -15, -328, 32613, 359, -26, -450, 32586, 512, -36, -568, 32551, 669, -47, -680, 32507, 832, -58, -788, 32454, 1000, -69, -891, 32393, 1174, -80, -990, 32323, 1352, -92, -1084, 32244, 1536, -103, -1173, 32157, 1724, -115, -1258, 32061, 1919, -128, @@ -80,11 +77,10 @@ namespace Ryujinx.Audio.Renderer.Dsp -180, 2747, 31593, -1554, -167, 2532, 31723, -1486, -153, 2322, 31844, -1414, -140, 2118, 31956, -1338, -128, 1919, 32061, -1258, -115, 1724, 32157, -1173, -103, 1536, 32244, -1084, -92, 1352, 32323, -990, -80, 1174, 32393, -891, -69, 1000, 32454, -788, -58, 832, 32507, -680, -47, 669, 32551, -568, - -36, 512, 32586, -450, -26, 359, 32613, -328, -15, 212, 32630, -200, -5, 69, 32639, -68 + -36, 512, 32586, -450, -26, 359, 32613, -328, -15, 212, 32630, -200, -5, 69, 32639, -68, }; - private static short[] _normalCurveLut2 = new short[] - { + private static readonly short[] _normalCurveLut2 = { 3195, 26287, 3329, -32, 3064, 26281, 3467, -34, 2936, 26270, 3608, -38, 2811, 26253, 3751, -42, 2688, 26230, 3897, -46, 2568, 26202, 4046, -50, 2451, 26169, 4199, -54, 2338, 26130, 4354, -58, 2227, 26085, 4512, -63, 2120, 26035, 4673, -67, 2015, 25980, 4837, -72, 1912, 25919, 5004, -76, @@ -116,13 +112,12 @@ namespace Ryujinx.Audio.Renderer.Dsp -98, 5701, 25621, 1531, -92, 5522, 25704, 1622, -87, 5347, 25780, 1716, -81, 5174, 25852, 1813, -76, 5004, 25919, 1912, -72, 4837, 25980, 2015, -67, 4673, 26035, 2120, -63, 4512, 26085, 2227, -58, 4354, 26130, 2338, -54, 4199, 26169, 2451, -50, 4046, 26202, 2568, -46, 3897, 26230, 2688, - -42, 3751, 26253, 2811, -38, 3608, 26270, 2936, -34, 3467, 26281, 3064, -32, 3329, 26287, 3195 + -42, 3751, 26253, 2811, -38, 3608, 26270, 2936, -34, 3467, 26281, 3064, -32, 3329, 26287, 3195, }; #endregion #region "High Quality Lookup Tables" - private static short[] _highCurveLut0 = new short[] - { + private static readonly short[] _highCurveLut0 = { -582, -23, 8740, 16386, 8833, 8, -590, 0, -573, -54, 8647, 16385, 8925, 40, -598, -1, -565, -84, 8555, 16383, 9018, 72, -606, -1, -557, -113, 8462, 16379, 9110, 105, -614, -2, -549, -142, 8370, 16375, 9203, 139, -622, -2, -541, -170, 8277, 16369, 9295, 173, -630, -3, @@ -189,8 +184,7 @@ namespace Ryujinx.Audio.Renderer.Dsp -1, -598, 40, 8925, 16385, 8647, -54, -573, 0, -590, 8, 8833, 16386, 8740, -23, -582, }; - private static short[] _highCurveLut1 = new short[] - { + private static readonly short[] _highCurveLut1 = { -12, 47, -134, 32767, 81, -16, 2, 0, -26, 108, -345, 32760, 301, -79, 17, -1, -40, 168, -552, 32745, 526, -144, 32, -2, -53, 226, -753, 32723, 755, -210, 47, -3, -66, 284, -950, 32694, 989, -277, 63, -5, -78, 340, -1143, 32658, 1226, -346, 79, -6, @@ -257,8 +251,7 @@ namespace Ryujinx.Audio.Renderer.Dsp -1, 17, -79, 301, 32760, -345, 108, -26, 0, 2, -16, 81, 32767, -134, 47, -12, }; - private static short[] _highCurveLut2 = new short[] - { + private static readonly short[] _highCurveLut2 = { 418, -2538, 6118, 24615, 6298, -2563, 417, 0, 420, -2512, 5939, 24611, 6479, -2588, 415, 1, 421, -2485, 5761, 24605, 6662, -2612, 412, 2, 422, -2458, 5585, 24595, 6846, -2635, 409, 3, 423, -2430, 5410, 24582, 7030, -2658, 406, 4, 423, -2402, 5236, 24565, 7216, -2680, 403, 5, @@ -326,13 +319,13 @@ namespace Ryujinx.Audio.Renderer.Dsp }; #endregion - private static float[] _normalCurveLut0F; - private static float[] _normalCurveLut1F; - private static float[] _normalCurveLut2F; + private static readonly float[] _normalCurveLut0F; + private static readonly float[] _normalCurveLut1F; + private static readonly float[] _normalCurveLut2F; - private static float[] _highCurveLut0F; - private static float[] _highCurveLut1F; - private static float[] _highCurveLut2F; + private static readonly float[] _highCurveLut0F; + private static readonly float[] _highCurveLut1F; + private static readonly float[] _highCurveLut2F; static ResamplerHelper() { @@ -373,7 +366,8 @@ namespace Ryujinx.Audio.Renderer.Dsp { return _normalCurveLut1F; } - else if (ratio > 1.333313f) + + if (ratio > 1.333313f) { return _normalCurveLut0F; } @@ -514,7 +508,8 @@ namespace Ryujinx.Audio.Renderer.Dsp { return _highCurveLut1F; } - else if (ratio > 1.333313f) + + if (ratio > 1.333313f) { return _highCurveLut0F; } @@ -601,4 +596,4 @@ namespace Ryujinx.Audio.Renderer.Dsp } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/State/AdpcmLoopContext.cs b/src/Ryujinx.Audio/Renderer/Dsp/State/AdpcmLoopContext.cs index 821a135ef..f9ef201f2 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/State/AdpcmLoopContext.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/State/AdpcmLoopContext.cs @@ -9,4 +9,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.State public short History0; public short History1; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/State/AuxiliaryBufferHeader.cs b/src/Ryujinx.Audio/Renderer/Dsp/State/AuxiliaryBufferHeader.cs index 4e8d11e4c..97bbc80cc 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/State/AuxiliaryBufferHeader.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/State/AuxiliaryBufferHeader.cs @@ -71,4 +71,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.State public AuxiliaryBufferInfo CpuBufferInfo; public AuxiliaryBufferInfo DspBufferInfo; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/State/BiquadFilterState.cs b/src/Ryujinx.Audio/Renderer/Dsp/State/BiquadFilterState.cs index 4220e6d51..f9a32b3f9 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/State/BiquadFilterState.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/State/BiquadFilterState.cs @@ -10,4 +10,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.State public float State2; public float State3; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/State/DelayState.cs b/src/Ryujinx.Audio/Renderer/Dsp/State/DelayState.cs index 2a1e7f834..c56fa078a 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/State/DelayState.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/State/DelayState.cs @@ -64,4 +64,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.State } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/State/LimiterState.cs b/src/Ryujinx.Audio/Renderer/Dsp/State/LimiterState.cs index 0560757c9..80d1cb62e 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/State/LimiterState.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/State/LimiterState.cs @@ -20,12 +20,12 @@ namespace Ryujinx.Audio.Renderer.Dsp.State DetectorAverage.AsSpan().Fill(new ExponentialMovingAverage(0.0f)); CompressionGainAverage.AsSpan().Fill(new ExponentialMovingAverage(1.0f)); - DelayedSampleBufferPosition.AsSpan().Fill(0); - DelayedSampleBuffer.AsSpan().Fill(0.0f); + DelayedSampleBufferPosition.AsSpan().Clear(); + DelayedSampleBuffer.AsSpan().Clear(); UpdateParameter(ref parameter); } - public void UpdateParameter(ref LimiterParameter parameter) { } + public static void UpdateParameter(ref LimiterParameter parameter) { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/State/Reverb3dState.cs b/src/Ryujinx.Audio/Renderer/Dsp/State/Reverb3dState.cs index c06466031..5056b750e 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/State/Reverb3dState.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/State/Reverb3dState.cs @@ -6,11 +6,11 @@ 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 }; + 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; } @@ -46,9 +46,9 @@ namespace Ryujinx.Audio.Renderer.Dsp.State 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])); + 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); @@ -63,7 +63,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.State EarlyDelayTime = new uint[20]; DryGain = parameter.DryGain; - PreviousFeedbackOutputDecayed.AsSpan().Fill(0); + PreviousFeedbackOutputDecayed.AsSpan().Clear(); PreviousPreDelayValue = 0; EarlyReflectionsGain = FloatingPointHelper.Pow10(Math.Min(parameter.RoomGain + parameter.ReflectionsGain, 5000.0f) / 2000.0f); @@ -91,7 +91,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.State for (int i = 0; i < FdnDelayLines.Length; i++) { - FdnDelayLines[i].SetDelay(FdnDelayMinTimes[i] + (parameter.Density / 100 * (FdnDelayMaxTimes[i] - FdnDelayMinTimes[i]))); + FdnDelayLines[i].SetDelay(_fdnDelayMinTimes[i] + (parameter.Density / 100 * (_fdnDelayMaxTimes[i] - _fdnDelayMinTimes[i]))); uint tempSampleCount = FdnDelayLines[i].CurrentSampleCount + DecayDelays1[i].CurrentSampleCount + DecayDelays2[i].CurrentSampleCount; @@ -111,9 +111,9 @@ namespace Ryujinx.Audio.Renderer.Dsp.State 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); + 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; } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/State/ReverbState.cs b/src/Ryujinx.Audio/Renderer/Dsp/State/ReverbState.cs index 1ffabe05c..2f574f475 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/State/ReverbState.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/State/ReverbState.cs @@ -7,7 +7,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.State { public class ReverbState { - private static readonly float[] FdnDelayTimes = new float[20] + private static readonly float[] _fdnDelayTimes = new float[20] { // Room 53.953247f, 79.192566f, 116.238770f, 130.615295f, @@ -21,7 +21,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.State 53.953247f, 79.192566f, 116.238770f, 170.615295f, }; - private static readonly float[] DecayDelayTimes = new float[20] + private static readonly float[] _decayDelayTimes = new float[20] { // Room 7f, 9f, 13f, 17f, @@ -35,7 +35,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.State 7f, 9f, 13f, 17f, }; - private static readonly float[] EarlyDelayTimes = new float[50] + 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, @@ -46,10 +46,10 @@ namespace Ryujinx.Audio.Renderer.Dsp.State // 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 + 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] + 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, @@ -60,10 +60,10 @@ namespace Ryujinx.Audio.Renderer.Dsp.State // 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 + 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] + private static readonly float[] _preDelayTimes = new float[5] { // Room 12.5f, @@ -74,7 +74,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.State // Cathedral 50.0f, // Disabled - 0.0f + 0.0f, }; public DelayLine[] FdnDelayLines { get; } @@ -93,14 +93,14 @@ namespace Ryujinx.Audio.Renderer.Dsp.State private const int FixedPointPrecision = 14; - private ReadOnlySpan GetFdnDelayTimesByLateMode(ReverbLateMode lateMode) + private static ReadOnlySpan GetFdnDelayTimesByLateMode(ReverbLateMode lateMode) { - return FdnDelayTimes.AsSpan((int)lateMode * 4, 4); + return _fdnDelayTimes.AsSpan((int)lateMode * 4, 4); } - private ReadOnlySpan GetDecayDelayTimesByLateMode(ReverbLateMode lateMode) + private static ReadOnlySpan GetDecayDelayTimesByLateMode(ReverbLateMode lateMode) { - return DecayDelayTimes.AsSpan((int)lateMode * 4, 4); + return _decayDelayTimes.AsSpan((int)lateMode * 4, 4); } public ReverbState(ref ReverbParameter parameter, ulong workBuffer, bool isLongSizePreDelaySupported) @@ -148,8 +148,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.State 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; + EarlyDelayTime[i] = Math.Min(IDelayLine.GetSampleCount(sampleRate, _earlyDelayTimes[i] + preDelayTimeInMilliseconds), PreDelayLine.SampleCountMax) + 1; + EarlyGain[i] = _earlyGainBase[i] * earlyGain; } if (parameter.ChannelCount == 2) @@ -158,7 +158,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.State EarlyGain[5] = EarlyGain[5] * 0.5f; } - PreDelayLineDelayTime = Math.Min(IDelayLine.GetSampleCount(sampleRate, PreDelayTimes[(int)parameter.EarlyMode] + preDelayTimeInMilliseconds), PreDelayLine.SampleCountMax); + PreDelayLineDelayTime = Math.Min(IDelayLine.GetSampleCount(sampleRate, _preDelayTimes[(int)parameter.EarlyMode] + preDelayTimeInMilliseconds), PreDelayLine.SampleCountMax); ReadOnlySpan fdnDelayTimes = GetFdnDelayTimesByLateMode(parameter.LateMode); ReadOnlySpan decayDelayTimes = GetDecayDelayTimesByLateMode(parameter.LateMode); @@ -201,4 +201,4 @@ namespace Ryujinx.Audio.Renderer.Dsp.State } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Dsp/UpsamplerHelper.cs b/src/Ryujinx.Audio/Renderer/Dsp/UpsamplerHelper.cs index 54a63ace0..5732cdb21 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/UpsamplerHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/UpsamplerHelper.cs @@ -13,11 +13,11 @@ namespace Ryujinx.Audio.Renderer.Dsp private const int FilterBankLength = 20; // Bank0 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; private const int Bank0CenterIndex = 9; - private static readonly Array20 Bank1 = PrecomputeFilterBank(1.0f / 6.0f); - private static readonly Array20 Bank2 = PrecomputeFilterBank(2.0f / 6.0f); - private static readonly Array20 Bank3 = PrecomputeFilterBank(3.0f / 6.0f); - private static readonly Array20 Bank4 = PrecomputeFilterBank(4.0f / 6.0f); - private static readonly Array20 Bank5 = PrecomputeFilterBank(5.0f / 6.0f); + private static readonly Array20 _bank1 = PrecomputeFilterBank(1.0f / 6.0f); + private static readonly Array20 _bank2 = PrecomputeFilterBank(2.0f / 6.0f); + private static readonly Array20 _bank3 = PrecomputeFilterBank(3.0f / 6.0f); + private static readonly Array20 _bank4 = PrecomputeFilterBank(4.0f / 6.0f); + private static readonly Array20 _bank5 = PrecomputeFilterBank(5.0f / 6.0f); private static Array20 PrecomputeFilterBank(float offset) { @@ -39,7 +39,7 @@ namespace Ryujinx.Audio.Renderer.Dsp return A0 + A1 * MathF.Cos(2 * MathF.PI * x) + A2 * MathF.Cos(4 * MathF.PI * x); } - Array20 result = new Array20(); + Array20 result = new(); for (int i = 0; i < FilterBankLength; i++) { @@ -58,10 +58,10 @@ namespace Ryujinx.Audio.Renderer.Dsp { state.Scale = inputSampleCount switch { - 40 => 6.0f, - 80 => 3.0f, + 40 => 6.0f, + 80 => 3.0f, 160 => 1.5f, - _ => throw new ArgumentOutOfRangeException() + _ => throw new ArgumentOutOfRangeException(nameof(inputSampleCount), inputSampleCount, null), }; state.Initialized = true; } @@ -105,7 +105,7 @@ namespace Ryujinx.Audio.Renderer.Dsp [MethodImpl(MethodImplOptions.AggressiveInlining)] void NextInput(ref UpsamplerBufferState state, float input) { - state.History.AsSpan().Slice(1).CopyTo(state.History.AsSpan()); + state.History.AsSpan()[1..].CopyTo(state.History.AsSpan()); state.History[HistoryLength - 1] = input; } @@ -123,19 +123,19 @@ namespace Ryujinx.Audio.Renderer.Dsp outputBuffer[i] = state.History[Bank0CenterIndex]; break; case 1: - outputBuffer[i] = DoFilterBank(ref state, Bank1); + outputBuffer[i] = DoFilterBank(ref state, _bank1); break; case 2: - outputBuffer[i] = DoFilterBank(ref state, Bank2); + outputBuffer[i] = DoFilterBank(ref state, _bank2); break; case 3: - outputBuffer[i] = DoFilterBank(ref state, Bank3); + outputBuffer[i] = DoFilterBank(ref state, _bank3); break; case 4: - outputBuffer[i] = DoFilterBank(ref state, Bank4); + outputBuffer[i] = DoFilterBank(ref state, _bank4); break; case 5: - outputBuffer[i] = DoFilterBank(ref state, Bank5); + outputBuffer[i] = DoFilterBank(ref state, _bank5); break; } @@ -152,10 +152,10 @@ namespace Ryujinx.Audio.Renderer.Dsp outputBuffer[i] = state.History[Bank0CenterIndex]; break; case 1: - outputBuffer[i] = DoFilterBank(ref state, Bank2); + outputBuffer[i] = DoFilterBank(ref state, _bank2); break; case 2: - outputBuffer[i] = DoFilterBank(ref state, Bank4); + outputBuffer[i] = DoFilterBank(ref state, _bank4); break; } @@ -173,11 +173,11 @@ namespace Ryujinx.Audio.Renderer.Dsp outputBuffer[i] = state.History[Bank0CenterIndex]; break; case 1: - outputBuffer[i] = DoFilterBank(ref state, Bank4); + outputBuffer[i] = DoFilterBank(ref state, _bank4); break; case 2: NextInput(ref state, inputBuffer[inputBufferIndex++]); - outputBuffer[i] = DoFilterBank(ref state, Bank2); + outputBuffer[i] = DoFilterBank(ref state, _bank2); break; } @@ -185,7 +185,7 @@ namespace Ryujinx.Audio.Renderer.Dsp } break; default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(state), state.Scale, null); } } } diff --git a/src/Ryujinx.Audio/Renderer/Parameter/AudioRendererConfiguration.cs b/src/Ryujinx.Audio/Renderer/Parameter/AudioRendererConfiguration.cs index 359cd4c02..491a05c86 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/AudioRendererConfiguration.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/AudioRendererConfiguration.cs @@ -60,7 +60,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/unused /// - private byte _reserved; + private readonly byte _reserved; /// /// The target rendering device. @@ -96,4 +96,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// public int Revision; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/BehaviourErrorInfoOutStatus.cs b/src/Ryujinx.Audio/Renderer/Parameter/BehaviourErrorInfoOutStatus.cs index aba7dcd61..5a0565dc6 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/BehaviourErrorInfoOutStatus.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/BehaviourErrorInfoOutStatus.cs @@ -27,4 +27,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// private unsafe fixed uint _reserved[3]; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/BiquadFilterParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/BiquadFilterParameter.cs index ef86015fe..f1492b0b1 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/BiquadFilterParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/BiquadFilterParameter.cs @@ -18,7 +18,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/padding. /// - private byte _reserved; + private readonly byte _reserved; /// /// Biquad filter numerator (b0, b1, b2). @@ -31,4 +31,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// a0 = 1 public Array2 Denominator; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Effect/AuxiliaryBufferParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/Effect/AuxiliaryBufferParameter.cs index 36f286775..65f265a32 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Effect/AuxiliaryBufferParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Effect/AuxiliaryBufferParameter.cs @@ -81,4 +81,4 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// This is unused. public uint MixBufferSampleCount; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Effect/BiquadFilterEffectParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/Effect/BiquadFilterEffectParameter.cs index 73e0e9bbc..b12a941a5 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Effect/BiquadFilterEffectParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Effect/BiquadFilterEffectParameter.cs @@ -41,4 +41,4 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// public UsageState Status; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Effect/BufferMixerParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/Effect/BufferMixerParameter.cs index b03559eba..49b70e501 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Effect/BufferMixerParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Effect/BufferMixerParameter.cs @@ -29,4 +29,4 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// public uint MixesCount; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Effect/CompressorParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/Effect/CompressorParameter.cs index 0be376088..1a936b0df 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Effect/CompressorParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Effect/CompressorParameter.cs @@ -98,7 +98,7 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// Check if the is valid. /// /// Returns true if the is valid. - public bool IsChannelCountValid() + public readonly bool IsChannelCountValid() { return EffectInParameterVersion1.IsChannelCountValid(ChannelCount); } @@ -107,7 +107,7 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// Check if the is valid. /// /// Returns true if the is valid. - public bool IsChannelCountMaxValid() + public readonly bool IsChannelCountMaxValid() { return EffectInParameterVersion1.IsChannelCountValid(ChannelCountMax); } diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Effect/DelayParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/Effect/DelayParameter.cs index 72332c170..99c97d9d9 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Effect/DelayParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Effect/DelayParameter.cs @@ -84,7 +84,7 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// Check if the is valid. /// /// Returns true if the is valid. - public bool IsChannelCountValid() + public readonly bool IsChannelCountValid() { return EffectInParameterVersion1.IsChannelCountValid(ChannelCount); } @@ -93,9 +93,9 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// Check if the is valid. /// /// Returns true if the is valid. - public bool IsChannelCountMaxValid() + public readonly bool IsChannelCountMaxValid() { return EffectInParameterVersion1.IsChannelCountValid(ChannelCountMax); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Effect/LimiterParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/Effect/LimiterParameter.cs index 0bce94a27..23ccb8c88 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Effect/LimiterParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Effect/LimiterParameter.cs @@ -115,13 +115,13 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// /// Reserved/padding. /// - private byte _reserved; + private readonly byte _reserved; /// /// Check if the is valid. /// /// Returns true if the is valid. - public bool IsChannelCountValid() + public readonly bool IsChannelCountValid() { return EffectInParameterVersion1.IsChannelCountValid(ChannelCount); } @@ -130,9 +130,9 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// Check if the is valid. /// /// Returns true if the is valid. - public bool IsChannelCountMaxValid() + public readonly bool IsChannelCountMaxValid() { return EffectInParameterVersion1.IsChannelCountValid(ChannelCountMax); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Effect/LimiterStatistics.cs b/src/Ryujinx.Audio/Renderer/Parameter/Effect/LimiterStatistics.cs index f353f18d1..97e2f39fc 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Effect/LimiterStatistics.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Effect/LimiterStatistics.cs @@ -24,8 +24,8 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// public void Reset() { - InputMax.AsSpan().Fill(0.0f); + InputMax.AsSpan().Clear(); CompressionGainMin.AsSpan().Fill(1.0f); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Effect/Reverb3dParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/Effect/Reverb3dParameter.cs index c78ce5951..d2cd78707 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Effect/Reverb3dParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Effect/Reverb3dParameter.cs @@ -33,7 +33,7 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// /// Reserved/unused. /// - private uint _reserved; + private readonly uint _reserved; /// /// The target sample rate. @@ -110,7 +110,7 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// Check if the is valid. /// /// Returns true if the is valid. - public bool IsChannelCountValid() + public readonly bool IsChannelCountValid() { return EffectInParameterVersion1.IsChannelCountValid(ChannelCount); } @@ -119,9 +119,9 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// Check if the is valid. /// /// Returns true if the is valid. - public bool IsChannelCountMaxValid() + public readonly bool IsChannelCountMaxValid() { return EffectInParameterVersion1.IsChannelCountValid(ChannelCountMax); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Effect/ReverbParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/Effect/ReverbParameter.cs index baf049fbd..51ab156d2 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Effect/ReverbParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Effect/ReverbParameter.cs @@ -102,7 +102,7 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// Check if the is valid. /// /// Returns true if the is valid. - public bool IsChannelCountValid() + public readonly bool IsChannelCountValid() { return EffectInParameterVersion1.IsChannelCountValid(ChannelCount); } @@ -111,9 +111,9 @@ namespace Ryujinx.Audio.Renderer.Parameter.Effect /// Check if the is valid. /// /// Returns true if the is valid. - public bool IsChannelCountMaxValid() + public readonly bool IsChannelCountMaxValid() { return EffectInParameterVersion1.IsChannelCountValid(ChannelCountMax); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/EffectInParameterVersion1.cs b/src/Ryujinx.Audio/Renderer/Parameter/EffectInParameterVersion1.cs index e5419f70a..46686e3b4 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/EffectInParameterVersion1.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/EffectInParameterVersion1.cs @@ -31,7 +31,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/padding. /// - private byte _reserved1; + private readonly byte _reserved1; /// /// The target mix id of the effect. @@ -58,7 +58,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/padding. /// - private uint _reserved2; + private readonly uint _reserved2; /// /// Specific data storage. @@ -70,19 +70,19 @@ namespace Ryujinx.Audio.Renderer.Parameter public Span SpecificData => SpanHelpers.AsSpan(ref _specificDataStart); - EffectType IEffectInParameter.Type => Type; + readonly EffectType IEffectInParameter.Type => Type; - bool IEffectInParameter.IsNew => IsNew; + readonly bool IEffectInParameter.IsNew => IsNew; - bool IEffectInParameter.IsEnabled => IsEnabled; + readonly bool IEffectInParameter.IsEnabled => IsEnabled; - int IEffectInParameter.MixId => MixId; + readonly int IEffectInParameter.MixId => MixId; - ulong IEffectInParameter.BufferBase => BufferBase; + readonly ulong IEffectInParameter.BufferBase => BufferBase; - ulong IEffectInParameter.BufferSize => BufferSize; + readonly ulong IEffectInParameter.BufferSize => BufferSize; - uint IEffectInParameter.ProcessingOrder => ProcessingOrder; + readonly uint IEffectInParameter.ProcessingOrder => ProcessingOrder; /// /// Check if the given channel count is valid. @@ -94,4 +94,4 @@ namespace Ryujinx.Audio.Renderer.Parameter return channelCount == 1 || channelCount == 2 || channelCount == 4 || channelCount == 6; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/EffectInParameterVersion2.cs b/src/Ryujinx.Audio/Renderer/Parameter/EffectInParameterVersion2.cs index 250012d16..3854c7148 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/EffectInParameterVersion2.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/EffectInParameterVersion2.cs @@ -31,7 +31,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/padding. /// - private byte _reserved1; + private readonly byte _reserved1; /// /// The target mix id of the effect. @@ -58,7 +58,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/padding. /// - private uint _reserved2; + private readonly uint _reserved2; /// /// Specific data storage. @@ -70,19 +70,19 @@ namespace Ryujinx.Audio.Renderer.Parameter public Span SpecificData => SpanHelpers.AsSpan(ref _specificDataStart); - EffectType IEffectInParameter.Type => Type; + readonly EffectType IEffectInParameter.Type => Type; - bool IEffectInParameter.IsNew => IsNew; + readonly bool IEffectInParameter.IsNew => IsNew; - bool IEffectInParameter.IsEnabled => IsEnabled; + readonly bool IEffectInParameter.IsEnabled => IsEnabled; - int IEffectInParameter.MixId => MixId; + readonly int IEffectInParameter.MixId => MixId; - ulong IEffectInParameter.BufferBase => BufferBase; + readonly ulong IEffectInParameter.BufferBase => BufferBase; - ulong IEffectInParameter.BufferSize => BufferSize; + readonly ulong IEffectInParameter.BufferSize => BufferSize; - uint IEffectInParameter.ProcessingOrder => ProcessingOrder; + readonly uint IEffectInParameter.ProcessingOrder => ProcessingOrder; /// /// Check if the given channel count is valid. @@ -94,4 +94,4 @@ namespace Ryujinx.Audio.Renderer.Parameter return channelCount == 1 || channelCount == 2 || channelCount == 4 || channelCount == 6; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/EffectOutStatusVersion1.cs b/src/Ryujinx.Audio/Renderer/Parameter/EffectOutStatusVersion1.cs index 5e6a33ace..3c3e95538 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/EffectOutStatusVersion1.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/EffectOutStatusVersion1.cs @@ -18,6 +18,6 @@ namespace Ryujinx.Audio.Renderer.Parameter /// private unsafe fixed byte _reserved[15]; - EffectState IEffectOutStatus.State { get => State; set => State = value; } + EffectState IEffectOutStatus.State { readonly get => State; set => State = value; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/EffectOutStatusVersion2.cs b/src/Ryujinx.Audio/Renderer/Parameter/EffectOutStatusVersion2.cs index f2c9768b3..ee058d3ae 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/EffectOutStatusVersion2.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/EffectOutStatusVersion2.cs @@ -23,6 +23,6 @@ namespace Ryujinx.Audio.Renderer.Parameter /// public EffectResultState ResultState; - EffectState IEffectOutStatus.State { get => State; set => State = value; } + EffectState IEffectOutStatus.State { readonly get => State; set => State = value; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/EffectResultState.cs b/src/Ryujinx.Audio/Renderer/Parameter/EffectResultState.cs index bd96c22bf..b3a4bae12 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/EffectResultState.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/EffectResultState.cs @@ -23,4 +23,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// public Span SpecificData => SpanHelpers.AsSpan(ref _specificDataStart); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/EffectState.cs b/src/Ryujinx.Audio/Renderer/Parameter/EffectState.cs index 911ba6d84..c4d06f122 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/EffectState.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/EffectState.cs @@ -13,6 +13,6 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// The effect is disabled. /// - Disabled = 4 + Disabled = 4, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/IEffectInParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/IEffectInParameter.cs index bdd1ca45e..703c3e6db 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/IEffectInParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/IEffectInParameter.cs @@ -50,4 +50,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// Span SpecificData { get; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/IEffectOutStatus.cs b/src/Ryujinx.Audio/Renderer/Parameter/IEffectOutStatus.cs index a5addbcb7..74d132209 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/IEffectOutStatus.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/IEffectOutStatus.cs @@ -10,4 +10,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// EffectState State { get; set; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/MemoryPoolInParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/MemoryPoolInParameter.cs index 242e3843c..602508589 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/MemoryPoolInParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/MemoryPoolInParameter.cs @@ -30,4 +30,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// private unsafe fixed uint _reserved[3]; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/MemoryPoolOutStatus.cs b/src/Ryujinx.Audio/Renderer/Parameter/MemoryPoolOutStatus.cs index 29a6e261f..a78937d01 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/MemoryPoolOutStatus.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/MemoryPoolOutStatus.cs @@ -19,4 +19,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// private unsafe fixed uint _reserved[3]; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/MixInParameterDirtyOnlyUpdate.cs b/src/Ryujinx.Audio/Renderer/Parameter/MixInParameterDirtyOnlyUpdate.cs index c0954cda0..733b5ad76 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/MixInParameterDirtyOnlyUpdate.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/MixInParameterDirtyOnlyUpdate.cs @@ -24,4 +24,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// private unsafe fixed byte _reserved[24]; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/MixParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/MixParameter.cs index 5b9a969a0..2eec04a21 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/MixParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/MixParameter.cs @@ -41,7 +41,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/padding. /// - private ushort _reserved1; + private readonly ushort _reserved1; /// /// The id of the mix. @@ -61,7 +61,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/padding. /// - private ulong _reserved2; + private readonly ulong _reserved2; /// /// Mix buffer volumes storage. @@ -81,7 +81,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/padding. /// - private uint _reserved3; + private readonly uint _reserved3; [StructLayout(LayoutKind.Sequential, Size = 4 * Constants.MixBufferCountMax * Constants.MixBufferCountMax, Pack = 1)] private struct MixVolumeArray { } @@ -92,4 +92,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// Used when no splitter id is specified. public Span MixBufferVolume => SpanHelpers.AsSpan(ref _mixBufferVolumeArray); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Performance/PerformanceInParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/Performance/PerformanceInParameter.cs index 0f9a3aa3e..806f7fa89 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Performance/PerformanceInParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Performance/PerformanceInParameter.cs @@ -18,4 +18,4 @@ namespace Ryujinx.Audio.Renderer.Parameter.Performance /// private unsafe fixed uint _reserved[3]; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Performance/PerformanceOutStatus.cs b/src/Ryujinx.Audio/Renderer/Parameter/Performance/PerformanceOutStatus.cs index 64bbe080a..839d6eb6b 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Performance/PerformanceOutStatus.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Performance/PerformanceOutStatus.cs @@ -18,4 +18,4 @@ namespace Ryujinx.Audio.Renderer.Parameter.Performance /// private unsafe fixed uint _reserved[3]; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/RendererInfoOutStatus.cs b/src/Ryujinx.Audio/Renderer/Parameter/RendererInfoOutStatus.cs index a42ea833f..c97ce2965 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/RendererInfoOutStatus.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/RendererInfoOutStatus.cs @@ -16,6 +16,6 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/Unused. /// - private ulong _reserved; + private readonly ulong _reserved; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Sink/CircularBufferParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/Sink/CircularBufferParameter.cs index 7c02d65ff..0d4b276ef 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Sink/CircularBufferParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Sink/CircularBufferParameter.cs @@ -2,7 +2,6 @@ using Ryujinx.Audio.Common; using Ryujinx.Audio.Renderer.Common; using Ryujinx.Common.Memory; using System.Runtime.InteropServices; - using CpuAddress = System.UInt64; namespace Ryujinx.Audio.Renderer.Parameter.Sink @@ -41,7 +40,7 @@ namespace Ryujinx.Audio.Renderer.Parameter.Sink /// /// The target . /// - /// Only is supported. + /// Only is supported. public SampleFormat SampleFormat; /// @@ -57,6 +56,6 @@ namespace Ryujinx.Audio.Renderer.Parameter.Sink /// /// Reserved/padding. /// - private ushort _reserved2; + private readonly ushort _reserved2; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/Sink/DeviceParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/Sink/DeviceParameter.cs index abeadaccf..652d02a63 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/Sink/DeviceParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/Sink/DeviceParameter.cs @@ -19,7 +19,7 @@ namespace Ryujinx.Audio.Renderer.Parameter.Sink /// /// Reserved/padding. /// - private byte _padding; + private readonly byte _padding; /// /// The total count of channels to output to the device. @@ -34,7 +34,7 @@ namespace Ryujinx.Audio.Renderer.Parameter.Sink /// /// Reserved/padding. /// - private byte _reserved; + private readonly byte _reserved; /// /// Set to true if the user controls Surround to Stereo downmixing coefficients. @@ -55,4 +55,4 @@ namespace Ryujinx.Audio.Renderer.Parameter.Sink /// public Span DeviceName => SpanHelpers.AsSpan(ref _deviceName); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/SinkInParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/SinkInParameter.cs index 1ee4eb532..3c1ac09c0 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/SinkInParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/SinkInParameter.cs @@ -25,7 +25,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/padding. /// - private ushort _reserved1; + private readonly ushort _reserved1; /// /// The node id of the sink. @@ -50,4 +50,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// public Span SpecificData => SpanHelpers.AsSpan(ref _specificDataStart); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/SinkOutStatus.cs b/src/Ryujinx.Audio/Renderer/Parameter/SinkOutStatus.cs index 426b861ca..dd0f867b5 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/SinkOutStatus.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/SinkOutStatus.cs @@ -16,11 +16,11 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/padding. /// - private uint _padding; + private readonly uint _padding; /// /// Reserved/padding. /// private unsafe fixed ulong _reserved[3]; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/SplitterDestinationInParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/SplitterDestinationInParameter.cs index 96c43092b..b74b67be0 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/SplitterDestinationInParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/SplitterDestinationInParameter.cs @@ -59,9 +59,9 @@ namespace Ryujinx.Audio.Renderer.Parameter /// Check if the magic is valid. /// /// Returns true if the magic is valid. - public bool IsMagicValid() + public readonly bool IsMagicValid() { return Magic == ValidMagic; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/SplitterInParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/SplitterInParameter.cs index 0220497de..2567b15a8 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/SplitterInParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/SplitterInParameter.cs @@ -38,9 +38,9 @@ namespace Ryujinx.Audio.Renderer.Parameter /// Check if the magic is valid. /// /// Returns true if the magic is valid. - public bool IsMagicValid() + public readonly bool IsMagicValid() { return Magic == ValidMagic; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/SplitterInParameterHeader.cs b/src/Ryujinx.Audio/Renderer/Parameter/SplitterInParameterHeader.cs index dbae17a9a..10fa866e7 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/SplitterInParameterHeader.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/SplitterInParameterHeader.cs @@ -37,9 +37,9 @@ namespace Ryujinx.Audio.Renderer.Parameter /// Check if the magic is valid. /// /// Returns true if the magic is valid. - public bool IsMagicValid() + public readonly bool IsMagicValid() { return Magic == ValidMagic; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/VoiceChannelResourceInParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/VoiceChannelResourceInParameter.cs index 6a863237d..6cff1a251 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/VoiceChannelResourceInParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/VoiceChannelResourceInParameter.cs @@ -25,4 +25,4 @@ namespace Ryujinx.Audio.Renderer.Parameter [MarshalAs(UnmanagedType.I1)] public bool IsUsed; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/VoiceInParameter.cs b/src/Ryujinx.Audio/Renderer/Parameter/VoiceInParameter.cs index c4b4ba312..86f92442b 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/VoiceInParameter.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/VoiceInParameter.cs @@ -94,7 +94,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/unused. /// - private uint _reserved1; + private readonly uint _reserved1; /// /// User state address required by the data source. @@ -143,7 +143,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/unused. /// - private ushort _reserved2; + private readonly ushort _reserved2; /// /// Change the behaviour of the voice. @@ -222,7 +222,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Reserved/unused. /// - private byte _reserved; + private readonly byte _reserved; /// /// If set to anything other than 0, specifies how many times to loop the wavebuffer. @@ -260,7 +260,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// The PCM sample type /// Returns true if the sample offset are in range of the size. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private bool IsSampleOffsetInRangeForPcm() where T : unmanaged + private readonly bool IsSampleOffsetInRangeForPcm() where T : unmanaged { uint dataTypeSize = (uint)Unsafe.SizeOf(); @@ -273,27 +273,15 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// The target /// Returns true if the sample offset are in range of the size. - public bool IsSampleOffsetValid(SampleFormat format) + public readonly bool IsSampleOffsetValid(SampleFormat format) { - bool result; - - switch (format) + return format switch { - case SampleFormat.PcmInt16: - result = IsSampleOffsetInRangeForPcm(); - break; - case SampleFormat.PcmFloat: - result = IsSampleOffsetInRangeForPcm(); - break; - case SampleFormat.Adpcm: - result = AdpcmHelper.GetAdpcmDataSize((int)StartSampleOffset) <= Size && - AdpcmHelper.GetAdpcmDataSize((int)EndSampleOffset) <= Size; - break; - default: - throw new NotImplementedException($"{format} not implemented!"); - } - - return result; + SampleFormat.PcmInt16 => IsSampleOffsetInRangeForPcm(), + SampleFormat.PcmFloat => IsSampleOffsetInRangeForPcm(), + SampleFormat.Adpcm => AdpcmHelper.GetAdpcmDataSize((int)StartSampleOffset) <= Size && AdpcmHelper.GetAdpcmDataSize((int)EndSampleOffset) <= Size, + _ => throw new NotImplementedException($"{format} not implemented!"), + }; } } @@ -316,7 +304,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Skip pitch and Sample Rate Conversion (SRC). /// - SkipPitchAndSampleRateConversion = 2 + SkipPitchAndSampleRateConversion = 2, } /// @@ -338,7 +326,7 @@ namespace Ryujinx.Audio.Renderer.Parameter /// /// Resample interpolating 1 samples per output sample. /// - Low + Low, } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Parameter/VoiceOutStatus.cs b/src/Ryujinx.Audio/Renderer/Parameter/VoiceOutStatus.cs index be9d35849..a7c749835 100644 --- a/src/Ryujinx.Audio/Renderer/Parameter/VoiceOutStatus.cs +++ b/src/Ryujinx.Audio/Renderer/Parameter/VoiceOutStatus.cs @@ -32,4 +32,4 @@ namespace Ryujinx.Audio.Renderer.Parameter /// private unsafe fixed byte _reserved[3]; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs b/src/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs index 8485fb4c5..7bb8ae5ba 100644 --- a/src/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs +++ b/src/Ryujinx.Audio/Renderer/Server/AudioRenderSystem.cs @@ -19,7 +19,6 @@ using System; using System.Buffers; using System.Diagnostics; using System.Threading; - using CpuAddress = System.UInt64; namespace Ryujinx.Audio.Renderer.Server @@ -30,19 +29,21 @@ namespace Ryujinx.Audio.Renderer.Server private AudioRendererRenderingDevice _renderingDevice; private AudioRendererExecutionMode _executionMode; - private IWritableEvent _systemEvent; + private readonly IWritableEvent _systemEvent; private MemoryPoolState _dspMemoryPoolState; - private VoiceContext _voiceContext; - private MixContext _mixContext; - private SinkContext _sinkContext; - private SplitterContext _splitterContext; - private EffectContext _effectContext; + private readonly VoiceContext _voiceContext; + private readonly MixContext _mixContext; + private readonly SinkContext _sinkContext; + private readonly SplitterContext _splitterContext; + private readonly EffectContext _effectContext; private PerformanceManager _performanceManager; private UpsamplerManager _upsamplerManager; private bool _isActive; private BehaviourContext _behaviourContext; +#pragma warning disable IDE0052 // Remove unread private member private ulong _totalElapsedTicksUpdating; private ulong _totalElapsedTicks; +#pragma warning restore IDE0052 private int _sessionId; private Memory _memoryPools; @@ -75,7 +76,7 @@ namespace Ryujinx.Audio.Renderer.Server private ulong _elapsedFrameCount; private ulong _renderingStartTick; - private AudioRendererManager _manager; + private readonly AudioRendererManager _manager; private int _disposeState; @@ -143,12 +144,12 @@ namespace Ryujinx.Audio.Renderer.Server WorkBufferAllocator workBufferAllocator; - workBufferMemory.Span.Fill(0); + workBufferMemory.Span.Clear(); _workBufferMemoryPin = workBufferMemory.Pin(); workBufferAllocator = new WorkBufferAllocator(workBufferMemory); - PoolMapper poolMapper = new PoolMapper(processHandle, false); + PoolMapper poolMapper = new(processHandle, false); poolMapper.InitializeSystemPool(ref _dspMemoryPoolState, workBuffer, workBufferSize); _mixBuffer = workBufferAllocator.Allocate(_sampleCount * (_voiceChannelCountMax + _mixBufferCount), 0x10); @@ -244,9 +245,9 @@ namespace Ryujinx.Audio.Renderer.Server foreach (ref MixState mix in mixes.Span) { - mix = new MixState(effectProcessingOrderArray.Slice(0, (int)parameter.EffectCount), ref _behaviourContext); + mix = new MixState(effectProcessingOrderArray[..(int)parameter.EffectCount], ref _behaviourContext); - effectProcessingOrderArray = effectProcessingOrderArray.Slice((int)parameter.EffectCount); + effectProcessingOrderArray = effectProcessingOrderArray[(int)parameter.EffectCount..]; } } @@ -341,26 +342,15 @@ namespace Ryujinx.Audio.Renderer.Server _elapsedFrameCount = 0; _voiceDropParameter = 1.0f; - switch (_behaviourContext.GetCommandProcessingTimeEstimatorVersion()) + _commandProcessingTimeEstimator = _behaviourContext.GetCommandProcessingTimeEstimatorVersion() switch { - case 1: - _commandProcessingTimeEstimator = new CommandProcessingTimeEstimatorVersion1(_sampleCount, _mixBufferCount); - break; - case 2: - _commandProcessingTimeEstimator = new CommandProcessingTimeEstimatorVersion2(_sampleCount, _mixBufferCount); - break; - case 3: - _commandProcessingTimeEstimator = new CommandProcessingTimeEstimatorVersion3(_sampleCount, _mixBufferCount); - break; - case 4: - _commandProcessingTimeEstimator = new CommandProcessingTimeEstimatorVersion4(_sampleCount, _mixBufferCount); - break; - case 5: - _commandProcessingTimeEstimator = new CommandProcessingTimeEstimatorVersion5(_sampleCount, _mixBufferCount); - break; - default: - throw new NotImplementedException($"Unsupported processing time estimator version {_behaviourContext.GetCommandProcessingTimeEstimatorVersion()}."); - } + 1 => new CommandProcessingTimeEstimatorVersion1(_sampleCount, _mixBufferCount), + 2 => new CommandProcessingTimeEstimatorVersion2(_sampleCount, _mixBufferCount), + 3 => new CommandProcessingTimeEstimatorVersion3(_sampleCount, _mixBufferCount), + 4 => new CommandProcessingTimeEstimatorVersion4(_sampleCount, _mixBufferCount), + 5 => new CommandProcessingTimeEstimatorVersion5(_sampleCount, _mixBufferCount), + _ => throw new NotImplementedException($"Unsupported processing time estimator version {_behaviourContext.GetCommandProcessingTimeEstimatorVersion()}."), + }; return ResultCode.Success; } @@ -402,9 +392,9 @@ namespace Ryujinx.Audio.Renderer.Server { ulong updateStartTicks = GetSystemTicks(); - output.Span.Fill(0); + output.Span.Clear(); - StateUpdater stateUpdater = new StateUpdater(input, output, _processHandle, _behaviourContext); + StateUpdater stateUpdater = new(input, output, _processHandle, _behaviourContext); ResultCode result; @@ -609,9 +599,9 @@ namespace Ryujinx.Audio.Renderer.Server _renderingStartTick = 0; } - CommandBuffer commandBuffer = new CommandBuffer(commandList, _commandProcessingTimeEstimator); + CommandBuffer commandBuffer = new(commandList, _commandProcessingTimeEstimator); - CommandGenerator commandGenerator = new CommandGenerator(commandBuffer, GetContext(), _voiceContext, _mixContext, _effectContext, _sinkContext, _splitterContext, _performanceManager); + CommandGenerator commandGenerator = new(commandBuffer, GetContext(), _voiceContext, _mixContext, _effectContext, _sinkContext, _splitterContext, _performanceManager); _voiceContext.Sort(); commandGenerator.GenerateVoices(); @@ -731,7 +721,7 @@ namespace Ryujinx.Audio.Renderer.Server DepopBuffer = _depopBuffer, MixBufferCount = GetMixBufferCount(), SessionId = _sessionId, - UpsamplerManager = _upsamplerManager + UpsamplerManager = _upsamplerManager, }; } @@ -742,7 +732,7 @@ namespace Ryujinx.Audio.Renderer.Server public static ulong GetWorkBufferSize(ref AudioRendererConfiguration parameter) { - BehaviourContext behaviourContext = new BehaviourContext(); + BehaviourContext behaviourContext = new(); behaviourContext.SetUserRevision(parameter.Revision); @@ -813,6 +803,8 @@ namespace Ryujinx.Audio.Renderer.Server public void Dispose() { + GC.SuppressFinalize(this); + if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0) { Dispose(true); @@ -828,7 +820,7 @@ namespace Ryujinx.Audio.Renderer.Server Stop(); } - PoolMapper mapper = new PoolMapper(_processHandle, false); + PoolMapper mapper = new(_processHandle, false); mapper.Unmap(ref _dspMemoryPoolState); PoolMapper.ClearUsageState(_memoryPools); @@ -876,4 +868,4 @@ namespace Ryujinx.Audio.Renderer.Server return ResultCode.UnsupportedOperation; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs b/src/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs index e41d5cc50..0dbbd26c8 100644 --- a/src/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs +++ b/src/Ryujinx.Audio/Renderer/Server/AudioRendererManager.cs @@ -29,7 +29,7 @@ namespace Ryujinx.Audio.Renderer.Server /// /// The session ids allocation table. /// - private int[] _sessionIds; + private readonly int[] _sessionIds; /// /// The events linked to each session. @@ -39,7 +39,7 @@ namespace Ryujinx.Audio.Renderer.Server /// /// The sessions instances. /// - private AudioRenderSystem[] _sessions; + private readonly AudioRenderSystem[] _sessions; /// /// The count of active sessions. @@ -186,7 +186,7 @@ namespace Ryujinx.Audio.Renderer.Server _workerThread = new Thread(SendCommands) { - Name = "AudioRendererManager.Worker" + Name = "AudioRendererManager.Worker", }; _workerThread.Start(); @@ -317,7 +317,7 @@ namespace Ryujinx.Audio.Renderer.Server { int sessionId = AcquireSessionId(); - AudioRenderSystem audioRenderer = new AudioRenderSystem(this, _sessionsSystemEvent[sessionId]); + AudioRenderSystem audioRenderer = new(this, _sessionsSystemEvent[sessionId]); // TODO: Eventually, we should try to use the guest supplied work buffer instead of allocating // our own. However, it was causing problems on some applications that would unmap the memory @@ -367,6 +367,8 @@ namespace Ryujinx.Audio.Renderer.Server public void Dispose() { + GC.SuppressFinalize(this); + if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0) { Dispose(true); @@ -402,4 +404,4 @@ namespace Ryujinx.Audio.Renderer.Server } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/BehaviourContext.cs b/src/Ryujinx.Audio/Renderer/Server/BehaviourContext.cs index 821947a98..3297b5d9f 100644 --- a/src/Ryujinx.Audio/Renderer/Server/BehaviourContext.cs +++ b/src/Ryujinx.Audio/Renderer/Server/BehaviourContext.cs @@ -125,7 +125,7 @@ namespace Ryujinx.Audio.Renderer.Server /// /// Error storage. /// - private ErrorInfo[] _errorInfos; + private readonly ErrorInfo[] _errorInfos; /// /// Current position in the array. @@ -254,7 +254,8 @@ namespace Ryujinx.Audio.Renderer.Server { return 0.80f; } - else if (CheckFeatureSupported(UserRevision, BaseRevisionMagic + Revision4)) + + if (CheckFeatureSupported(UserRevision, BaseRevisionMagic + Revision4)) { return 0.75f; } @@ -299,10 +300,8 @@ namespace Ryujinx.Audio.Renderer.Server { return 2; } - else - { - return 1; - } + + return 1; } /// @@ -436,7 +435,7 @@ namespace Ryujinx.Audio.Renderer.Server errorInfos[i] = new ErrorInfo { ErrorCode = 0, - ExtraErrorInfo = 0 + ExtraErrorInfo = 0, }; } } @@ -450,4 +449,4 @@ namespace Ryujinx.Audio.Renderer.Server _errorIndex = 0; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/CommandBuffer.cs b/src/Ryujinx.Audio/Renderer/Server/CommandBuffer.cs index 905cb2054..f4174a913 100644 --- a/src/Ryujinx.Audio/Renderer/Server/CommandBuffer.cs +++ b/src/Ryujinx.Audio/Renderer/Server/CommandBuffer.cs @@ -20,7 +20,7 @@ namespace Ryujinx.Audio.Renderer.Server /// /// The command processing time estimator in use. /// - private ICommandProcessingTimeEstimator _commandProcessingTimeEstimator; + private readonly ICommandProcessingTimeEstimator _commandProcessingTimeEstimator; /// /// The estimated total processing time. @@ -61,7 +61,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateClearMixBuffer(int nodeId) { - ClearMixBufferCommand command = new ClearMixBufferCommand(nodeId); + ClearMixBufferCommand command = new(nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -79,7 +79,7 @@ namespace Ryujinx.Audio.Renderer.Server /// Set to true if the voice was playing previously. public void GenerateDepopPrepare(Memory state, Memory depopBuffer, uint bufferCount, uint bufferOffset, int nodeId, bool wasPlaying) { - DepopPrepareCommand command = new DepopPrepareCommand(state, depopBuffer, bufferCount, bufferOffset, nodeId, wasPlaying); + DepopPrepareCommand command = new(state, depopBuffer, bufferCount, bufferOffset, nodeId, wasPlaying); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -94,7 +94,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GeneratePerformance(ref PerformanceEntryAddresses performanceEntryAddresses, PerformanceCommand.Type type, int nodeId) { - PerformanceCommand command = new PerformanceCommand(ref performanceEntryAddresses, type, nodeId); + PerformanceCommand command = new(ref performanceEntryAddresses, type, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -110,7 +110,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateVolumeRamp(float previousVolume, float volume, uint bufferIndex, int nodeId) { - VolumeRampCommand command = new VolumeRampCommand(previousVolume, volume, bufferIndex, nodeId); + VolumeRampCommand command = new(previousVolume, volume, bufferIndex, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -127,7 +127,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateDataSourceVersion2(ref VoiceState voiceState, Memory state, ushort outputBufferIndex, ushort channelIndex, int nodeId) { - DataSourceVersion2Command command = new DataSourceVersion2Command(ref voiceState, state, outputBufferIndex, channelIndex, nodeId); + DataSourceVersion2Command command = new(ref voiceState, state, outputBufferIndex, channelIndex, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -144,7 +144,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GeneratePcmInt16DataSourceVersion1(ref VoiceState voiceState, Memory state, ushort outputBufferIndex, ushort channelIndex, int nodeId) { - PcmInt16DataSourceCommandVersion1 command = new PcmInt16DataSourceCommandVersion1(ref voiceState, state, outputBufferIndex, channelIndex, nodeId); + PcmInt16DataSourceCommandVersion1 command = new(ref voiceState, state, outputBufferIndex, channelIndex, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -161,7 +161,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GeneratePcmFloatDataSourceVersion1(ref VoiceState voiceState, Memory state, ushort outputBufferIndex, ushort channelIndex, int nodeId) { - PcmFloatDataSourceCommandVersion1 command = new PcmFloatDataSourceCommandVersion1(ref voiceState, state, outputBufferIndex, channelIndex, nodeId); + PcmFloatDataSourceCommandVersion1 command = new(ref voiceState, state, outputBufferIndex, channelIndex, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -177,7 +177,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateAdpcmDataSourceVersion1(ref VoiceState voiceState, Memory state, ushort outputBufferIndex, int nodeId) { - AdpcmDataSourceCommandVersion1 command = new AdpcmDataSourceCommandVersion1(ref voiceState, state, outputBufferIndex, nodeId); + AdpcmDataSourceCommandVersion1 command = new(ref voiceState, state, outputBufferIndex, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -196,7 +196,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateBiquadFilter(int baseIndex, ref BiquadFilterParameter filter, Memory biquadFilterStateMemory, int inputBufferOffset, int outputBufferOffset, bool needInitialization, int nodeId) { - BiquadFilterCommand command = new BiquadFilterCommand(baseIndex, ref filter, biquadFilterStateMemory, inputBufferOffset, outputBufferOffset, needInitialization, nodeId); + BiquadFilterCommand command = new(baseIndex, ref filter, biquadFilterStateMemory, inputBufferOffset, outputBufferOffset, needInitialization, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -215,7 +215,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateGroupedBiquadFilter(int baseIndex, ReadOnlySpan filters, Memory biquadFilterStatesMemory, int inputBufferOffset, int outputBufferOffset, ReadOnlySpan isInitialized, int nodeId) { - GroupedBiquadFilterCommand command = new GroupedBiquadFilterCommand(baseIndex, filters, biquadFilterStatesMemory, inputBufferOffset, outputBufferOffset, isInitialized, nodeId); + GroupedBiquadFilterCommand command = new(baseIndex, filters, biquadFilterStatesMemory, inputBufferOffset, outputBufferOffset, isInitialized, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -234,7 +234,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateMixRampGrouped(uint mixBufferCount, uint inputBufferIndex, uint outputBufferIndex, Span previousVolume, Span volume, Memory state, int nodeId) { - MixRampGroupedCommand command = new MixRampGroupedCommand(mixBufferCount, inputBufferIndex, outputBufferIndex, previousVolume, volume, state, nodeId); + MixRampGroupedCommand command = new(mixBufferCount, inputBufferIndex, outputBufferIndex, previousVolume, volume, state, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -253,7 +253,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateMixRamp(float previousVolume, float volume, uint inputBufferIndex, uint outputBufferIndex, int lastSampleIndex, Memory state, int nodeId) { - MixRampCommand command = new MixRampCommand(previousVolume, volume, inputBufferIndex, outputBufferIndex, lastSampleIndex, state, nodeId); + MixRampCommand command = new(previousVolume, volume, inputBufferIndex, outputBufferIndex, lastSampleIndex, state, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -270,7 +270,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The target sample rate in use. public void GenerateDepopForMixBuffersCommand(Memory depopBuffer, uint bufferOffset, uint bufferCount, int nodeId, uint sampleRate) { - DepopForMixBuffersCommand command = new DepopForMixBuffersCommand(depopBuffer, bufferOffset, bufferCount, nodeId, sampleRate); + DepopForMixBuffersCommand command = new(depopBuffer, bufferOffset, bufferCount, nodeId, sampleRate); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -285,7 +285,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateCopyMixBuffer(uint inputBufferIndex, uint outputBufferIndex, int nodeId) { - CopyMixBufferCommand command = new CopyMixBufferCommand(inputBufferIndex, outputBufferIndex, nodeId); + CopyMixBufferCommand command = new(inputBufferIndex, outputBufferIndex, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -301,7 +301,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The mix volume. public void GenerateMix(uint inputBufferIndex, uint outputBufferIndex, int nodeId, float volume) { - MixCommand command = new MixCommand(inputBufferIndex, outputBufferIndex, nodeId, volume); + MixCommand command = new(inputBufferIndex, outputBufferIndex, nodeId, volume); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -323,7 +323,7 @@ namespace Ryujinx.Audio.Renderer.Server { if (parameter.IsChannelCountValid()) { - ReverbCommand command = new ReverbCommand(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, isLongSizePreDelaySupported, newEffectChannelMappingSupported); + ReverbCommand command = new(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, isLongSizePreDelaySupported, newEffectChannelMappingSupported); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -345,7 +345,7 @@ namespace Ryujinx.Audio.Renderer.Server { if (parameter.IsChannelCountValid()) { - Reverb3dCommand command = new Reverb3dCommand(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, newEffectChannelMappingSupported); + Reverb3dCommand command = new(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, newEffectChannelMappingSupported); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -368,7 +368,7 @@ namespace Ryujinx.Audio.Renderer.Server { if (parameter.IsChannelCountValid()) { - DelayCommand command = new DelayCommand(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, newEffectChannelMappingSupported); + DelayCommand command = new(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, newEffectChannelMappingSupported); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -389,7 +389,7 @@ namespace Ryujinx.Audio.Renderer.Server { if (parameter.IsChannelCountValid()) { - LimiterCommandVersion1 command = new LimiterCommandVersion1(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId); + LimiterCommandVersion1 command = new(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -411,7 +411,7 @@ namespace Ryujinx.Audio.Renderer.Server { if (parameter.IsChannelCountValid()) { - LimiterCommandVersion2 command = new LimiterCommandVersion2(bufferOffset, parameter, state, effectResultState, isEnabled, workBuffer, nodeId); + LimiterCommandVersion2 command = new(bufferOffset, parameter, state, effectResultState, isEnabled, workBuffer, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -437,7 +437,7 @@ namespace Ryujinx.Audio.Renderer.Server { if (state.SendBufferInfoBase != 0 && state.ReturnBufferInfoBase != 0) { - AuxiliaryBufferCommand command = new AuxiliaryBufferCommand(bufferOffset, inputBufferOffset, outputBufferOffset, ref state, isEnabled, countMax, outputBuffer, inputBuffer, updateCount, writeOffset, nodeId); + AuxiliaryBufferCommand command = new(bufferOffset, inputBufferOffset, outputBufferOffset, ref state, isEnabled, countMax, outputBuffer, inputBuffer, updateCount, writeOffset, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -461,7 +461,7 @@ namespace Ryujinx.Audio.Renderer.Server { if (sendBufferInfo != 0) { - CaptureBufferCommand command = new CaptureBufferCommand(bufferOffset, inputBufferOffset, sendBufferInfo, isEnabled, countMax, outputBuffer, updateCount, writeOffset, nodeId); + CaptureBufferCommand command = new(bufferOffset, inputBufferOffset, sendBufferInfo, isEnabled, countMax, outputBuffer, updateCount, writeOffset, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -473,7 +473,7 @@ namespace Ryujinx.Audio.Renderer.Server { if (parameter.IsChannelCountValid()) { - CompressorCommand command = new CompressorCommand(bufferOffset, parameter, state, isEnabled, nodeId); + CompressorCommand command = new(bufferOffset, parameter, state, isEnabled, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -489,7 +489,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateVolume(float volume, uint bufferOffset, int nodeId) { - VolumeCommand command = new VolumeCommand(volume, bufferOffset, nodeId); + VolumeCommand command = new(volume, bufferOffset, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -504,7 +504,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateCircularBuffer(uint bufferOffset, CircularBufferSink sink, int nodeId) { - CircularBufferSinkCommand command = new CircularBufferSinkCommand(bufferOffset, ref sink.Parameter, ref sink.CircularBufferAddressInfo, sink.CurrentWriteOffset, nodeId); + CircularBufferSinkCommand command = new(bufferOffset, ref sink.Parameter, ref sink.CircularBufferAddressInfo, sink.CurrentWriteOffset, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -521,7 +521,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateDownMixSurroundToStereo(uint bufferOffset, Span inputBufferOffset, Span outputBufferOffset, float[] downMixParameter, int nodeId) { - DownMixSurroundToStereoCommand command = new DownMixSurroundToStereoCommand(bufferOffset, inputBufferOffset, outputBufferOffset, downMixParameter, nodeId); + DownMixSurroundToStereoCommand command = new(bufferOffset, inputBufferOffset, outputBufferOffset, downMixParameter, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -541,7 +541,7 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateUpsample(uint bufferOffset, UpsamplerState upsampler, uint inputCount, Span inputBufferOffset, uint bufferCountPerSample, uint sampleCount, uint sampleRate, int nodeId) { - UpsampleCommand command = new UpsampleCommand(bufferOffset, upsampler, inputCount, inputBufferOffset, bufferCountPerSample, sampleCount, sampleRate, nodeId); + UpsampleCommand command = new(bufferOffset, upsampler, inputCount, inputBufferOffset, bufferCountPerSample, sampleCount, sampleRate, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); @@ -558,11 +558,11 @@ namespace Ryujinx.Audio.Renderer.Server /// The node id associated to this command. public void GenerateDeviceSink(uint bufferOffset, DeviceSink sink, int sessionId, Memory buffer, int nodeId) { - DeviceSinkCommand command = new DeviceSinkCommand(bufferOffset, sink, sessionId, buffer, nodeId); + DeviceSinkCommand command = new(bufferOffset, sink, sessionId, buffer, nodeId); command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command); AddCommand(command); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/CommandGenerator.cs b/src/Ryujinx.Audio/Renderer/Server/CommandGenerator.cs index afc1e39b7..ae8f699f3 100644 --- a/src/Ryujinx.Audio/Renderer/Server/CommandGenerator.cs +++ b/src/Ryujinx.Audio/Renderer/Server/CommandGenerator.cs @@ -17,14 +17,14 @@ namespace Ryujinx.Audio.Renderer.Server { public class CommandGenerator { - private CommandBuffer _commandBuffer; - private RendererSystemContext _rendererContext; - private VoiceContext _voiceContext; - private MixContext _mixContext; - private EffectContext _effectContext; - private SinkContext _sinkContext; - private SplitterContext _splitterContext; - private PerformanceManager _performanceManager; + private readonly CommandBuffer _commandBuffer; + private readonly RendererSystemContext _rendererContext; + private readonly VoiceContext _voiceContext; + private readonly MixContext _mixContext; + private readonly EffectContext _effectContext; + private readonly SinkContext _sinkContext; + private readonly SplitterContext _splitterContext; + private readonly PerformanceManager _performanceManager; public CommandGenerator(CommandBuffer commandBuffer, RendererSystemContext rendererContext, VoiceContext voiceContext, MixContext mixContext, EffectContext effectContext, SinkContext sinkContext, SplitterContext splitterContext, PerformanceManager performanceManager) { @@ -138,7 +138,7 @@ namespace Ryujinx.Audio.Renderer.Server if (supportsOptimizedPath && voiceState.BiquadFilters[0].Enable && voiceState.BiquadFilters[1].Enable) { - Memory biquadStateRawMemory = SpanMemoryManager.Cast(state).Slice(VoiceUpdateState.BiquadStateOffset, VoiceUpdateState.BiquadStateSize * Constants.VoiceBiquadFilterCount); + Memory biquadStateRawMemory = SpanMemoryManager.Cast(state)[..(VoiceUpdateState.BiquadStateSize * Constants.VoiceBiquadFilterCount)]; Memory stateMemory = SpanMemoryManager.Cast(biquadStateRawMemory); _commandBuffer.GenerateGroupedBiquadFilter(baseIndex, voiceState.BiquadFilters.AsSpan(), stateMemory, bufferOffset, bufferOffset, voiceState.BiquadFilterNeedInitialization, nodeId); @@ -151,7 +151,7 @@ namespace Ryujinx.Audio.Renderer.Server if (filter.Enable) { - Memory biquadStateRawMemory = SpanMemoryManager.Cast(state).Slice(VoiceUpdateState.BiquadStateOffset, VoiceUpdateState.BiquadStateSize * Constants.VoiceBiquadFilterCount); + Memory biquadStateRawMemory = SpanMemoryManager.Cast(state)[..(VoiceUpdateState.BiquadStateSize * Constants.VoiceBiquadFilterCount)]; Memory stateMemory = SpanMemoryManager.Cast(biquadStateRawMemory); @@ -224,7 +224,7 @@ namespace Ryujinx.Audio.Renderer.Server bool performanceInitialized = false; - PerformanceEntryAddresses performanceEntry = new PerformanceEntryAddresses(); + PerformanceEntryAddresses performanceEntry = new(); if (_performanceManager != null && _performanceManager.IsTargetNodeId(nodeId) && _performanceManager.GetNextEntry(out performanceEntry, dataSourceDetailType, PerformanceEntryType.Voice, nodeId)) { @@ -371,7 +371,7 @@ namespace Ryujinx.Audio.Renderer.Server { int nodeId = sortedState.NodeId; - PerformanceEntryAddresses performanceEntry = new PerformanceEntryAddresses(); + PerformanceEntryAddresses performanceEntry = new(); bool performanceInitialized = false; @@ -502,9 +502,11 @@ namespace Ryujinx.Audio.Renderer.Server bool needInitialization = effect.Parameter.Status == UsageState.Invalid || (effect.Parameter.Status == UsageState.New && !_rendererContext.BehaviourContext.IsBiquadFilterEffectStateClearBugFixed()); - BiquadFilterParameter parameter = new BiquadFilterParameter(); + BiquadFilterParameter parameter = new() + { + Enable = true, + }; - parameter.Enable = true; effect.Parameter.Denominator.AsSpan().CopyTo(parameter.Denominator.AsSpan()); effect.Parameter.Numerator.AsSpan().CopyTo(parameter.Numerator.AsSpan()); @@ -623,7 +625,7 @@ namespace Ryujinx.Audio.Renderer.Server bool isFinalMix = mix.MixId == Constants.FinalMixId; - PerformanceEntryAddresses performanceEntry = new PerformanceEntryAddresses(); + PerformanceEntryAddresses performanceEntry = new(); bool performanceInitialized = false; @@ -789,7 +791,7 @@ namespace Ryujinx.Audio.Renderer.Server GenerateEffects(ref subMix); - PerformanceEntryAddresses performanceEntry = new PerformanceEntryAddresses(); + PerformanceEntryAddresses performanceEntry = new(); int nodeId = subMix.NodeId; @@ -820,7 +822,7 @@ namespace Ryujinx.Audio.Renderer.Server { int nodeId = sortedState.NodeId; - PerformanceEntryAddresses performanceEntry = new PerformanceEntryAddresses(); + PerformanceEntryAddresses performanceEntry = new(); bool performanceInitialized = false; @@ -853,7 +855,7 @@ namespace Ryujinx.Audio.Renderer.Server GenerateEffects(ref finalMix); - PerformanceEntryAddresses performanceEntry = new PerformanceEntryAddresses(); + PerformanceEntryAddresses performanceEntry = new(); int nodeId = finalMix.NodeId; @@ -901,7 +903,7 @@ namespace Ryujinx.Audio.Renderer.Server { int nodeId = _mixContext.GetFinalState().NodeId; - PerformanceEntryAddresses performanceEntry = new PerformanceEntryAddresses(); + PerformanceEntryAddresses performanceEntry = new(); bool performanceInitialized = false; @@ -977,7 +979,7 @@ namespace Ryujinx.Audio.Renderer.Server { bool performanceInitialized = false; - PerformanceEntryAddresses performanceEntry = new PerformanceEntryAddresses(); + PerformanceEntryAddresses performanceEntry = new(); if (_performanceManager != null && _performanceManager.GetNextEntry(out performanceEntry, PerformanceEntryType.Sink, sink.NodeId)) { @@ -1025,4 +1027,4 @@ namespace Ryujinx.Audio.Renderer.Server } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion1.cs b/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion1.cs index 63dc9ca96..d95e9aa71 100644 --- a/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion1.cs +++ b/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion1.cs @@ -8,8 +8,8 @@ namespace Ryujinx.Audio.Renderer.Server /// public class CommandProcessingTimeEstimatorVersion1 : ICommandProcessingTimeEstimator { - private uint _sampleCount; - private uint _bufferCount; + private readonly uint _sampleCount; + private readonly uint _bufferCount; public CommandProcessingTimeEstimatorVersion1(uint sampleCount, uint bufferCount) { @@ -185,4 +185,4 @@ namespace Ryujinx.Audio.Renderer.Server return 0; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion2.cs b/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion2.cs index d4f28a07d..929aaf383 100644 --- a/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion2.cs +++ b/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion2.cs @@ -9,8 +9,8 @@ namespace Ryujinx.Audio.Renderer.Server /// public class CommandProcessingTimeEstimatorVersion2 : ICommandProcessingTimeEstimator { - private uint _sampleCount; - private uint _bufferCount; + private readonly uint _sampleCount; + private readonly uint _bufferCount; public CommandProcessingTimeEstimatorVersion2(uint sampleCount, uint bufferCount) { @@ -189,71 +189,47 @@ namespace Ryujinx.Audio.Renderer.Server { if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)41636.0f; - case 2: - return (uint)97861.0f; - case 4: - return (uint)192520.0f; - case 6: - return (uint)301760.0f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)41636.0f, + 2 => (uint)97861.0f, + 4 => (uint)192520.0f, + 6 => (uint)301760.0f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)578.53f; - case 2: - return (uint)663.06f; - case 4: - return (uint)703.98f; - case 6: - return (uint)760.03f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)578.53f, + 2 => (uint)663.06f, + 4 => (uint)703.98f, + 6 => (uint)760.03f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)8770.3f; - case 2: - return (uint)25741.0f; - case 4: - return (uint)47551.0f; - case 6: - return (uint)81629.0f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)8770.3f, + 2 => (uint)25741.0f, + 4 => (uint)47551.0f, + 6 => (uint)81629.0f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)521.28f; - case 2: - return (uint)585.4f; - case 4: - return (uint)629.88f; - case 6: - return (uint)713.57f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)521.28f, + 2 => (uint)585.4f, + 4 => (uint)629.88f, + 6 => (uint)713.57f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } public uint Estimate(ReverbCommand command) @@ -264,71 +240,47 @@ namespace Ryujinx.Audio.Renderer.Server { if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)97192.0f; - case 2: - return (uint)103280.0f; - case 4: - return (uint)109580.0f; - case 6: - return (uint)115070.0f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)97192.0f, + 2 => (uint)103280.0f, + 4 => (uint)109580.0f, + 6 => (uint)115070.0f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)492.01f; - case 2: - return (uint)554.46f; - case 4: - return (uint)595.86f; - case 6: - return (uint)656.62f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)492.01f, + 2 => (uint)554.46f, + 4 => (uint)595.86f, + 6 => (uint)656.62f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)136460.0f; - case 2: - return (uint)145750.0f; - case 4: - return (uint)154800.0f; - case 6: - return (uint)161970.0f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)136460.0f, + 2 => (uint)145750.0f, + 4 => (uint)154800.0f, + 6 => (uint)161970.0f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)495.79f; - case 2: - return (uint)527.16f; - case 4: - return (uint)598.75f; - case 6: - return (uint)666.03f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)495.79f, + 2 => (uint)527.16f, + 4 => (uint)598.75f, + 6 => (uint)666.03f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } public uint Estimate(Reverb3dCommand command) @@ -339,70 +291,46 @@ namespace Ryujinx.Audio.Renderer.Server { if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)138840.0f; - case 2: - return (uint)135430.0f; - case 4: - return (uint)199180.0f; - case 6: - return (uint)247350.0f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)138840.0f, + 2 => (uint)135430.0f, + 4 => (uint)199180.0f, + 6 => (uint)247350.0f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)718.7f; - case 2: - return (uint)751.3f; - case 4: - return (uint)797.46f; - case 6: - return (uint)867.43f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)718.7f, + 2 => (uint)751.3f, + 4 => (uint)797.46f, + 6 => (uint)867.43f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)199950.0f; - case 2: - return (uint)195200.0f; - case 4: - return (uint)290580.0f; - case 6: - return (uint)363490.0f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)199950.0f, + 2 => (uint)195200.0f, + 4 => (uint)290580.0f, + 6 => (uint)363490.0f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)534.24f; - case 2: - return (uint)570.87f; - case 4: - return (uint)660.93f; - case 6: - return (uint)694.6f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)534.24f, + 2 => (uint)570.87f, + 4 => (uint)660.93f, + 6 => (uint)694.6f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } public uint Estimate(AuxiliaryBufferCommand command) diff --git a/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion3.cs b/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion3.cs index b79ca1369..8ae4bc059 100644 --- a/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion3.cs +++ b/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion3.cs @@ -12,20 +12,20 @@ namespace Ryujinx.Audio.Renderer.Server /// public class CommandProcessingTimeEstimatorVersion3 : ICommandProcessingTimeEstimator { - protected uint _sampleCount; - protected uint _bufferCount; + protected uint SampleCount; + protected uint BufferCount; public CommandProcessingTimeEstimatorVersion3(uint sampleCount, uint bufferCount) { - _sampleCount = sampleCount; - _bufferCount = bufferCount; + SampleCount = sampleCount; + BufferCount = bufferCount; } public uint Estimate(PerformanceCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)498.17f; } @@ -35,24 +35,24 @@ namespace Ryujinx.Audio.Renderer.Server public uint Estimate(ClearMixBufferCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); float costPerBuffer = 440.68f; float baseCost = 0; - if (_sampleCount == 160) + if (SampleCount == 160) { costPerBuffer = 266.65f; } - return (uint)(baseCost + costPerBuffer * _bufferCount); + return (uint)(baseCost + costPerBuffer * BufferCount); } public uint Estimate(BiquadFilterCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)4173.2f; } @@ -64,9 +64,9 @@ namespace Ryujinx.Audio.Renderer.Server { float costPerSample = 6.4434f; - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { costPerSample = 6.708f; } @@ -81,14 +81,14 @@ namespace Ryujinx.Audio.Renderer.Server } } - return (uint)(_sampleCount * costPerSample * volumeCount); + return (uint)(SampleCount * costPerSample * volumeCount); } public uint Estimate(MixRampCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)1968.7f; } @@ -103,9 +103,9 @@ namespace Ryujinx.Audio.Renderer.Server public uint Estimate(VolumeRampCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)1425.3f; } @@ -115,41 +115,41 @@ namespace Ryujinx.Audio.Renderer.Server public uint Estimate(PcmInt16DataSourceCommandVersion1 command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); float costPerSample = 710.143f; float baseCost = 7853.286f; - if (_sampleCount == 160) + if (SampleCount == 160) { costPerSample = 427.52f; baseCost = 6329.442f; } - return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / _sampleCount) * (command.Pitch * 0.000030518f)))); + return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / SampleCount) * (command.Pitch * 0.000030518f)))); } public uint Estimate(AdpcmDataSourceCommandVersion1 command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); float costPerSample = 3564.1f; float baseCost = 9736.702f; - if (_sampleCount == 160) + if (SampleCount == 160) { costPerSample = 2125.6f; baseCost = 7913.808f; } - return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / _sampleCount) * (command.Pitch * 0.000030518f)))); + return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / SampleCount) * (command.Pitch * 0.000030518f)))); } public uint Estimate(DepopForMixBuffersCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)739.64f; } @@ -159,9 +159,9 @@ namespace Ryujinx.Audio.Renderer.Server public uint Estimate(CopyMixBufferCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)842.59f; } @@ -171,9 +171,9 @@ namespace Ryujinx.Audio.Renderer.Server public uint Estimate(MixCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)1402.8f; } @@ -183,231 +183,159 @@ namespace Ryujinx.Audio.Renderer.Server public virtual uint Estimate(DelayCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)8929.04f; - case 2: - return (uint)25500.75f; - case 4: - return (uint)47759.62f; - case 6: - return (uint)82203.07f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)8929.04f, + 2 => (uint)25500.75f, + 4 => (uint)47759.62f, + 6 => (uint)82203.07f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)1295.20f; - case 2: - return (uint)1213.60f; - case 4: - return (uint)942.03f; - case 6: - return (uint)1001.55f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)1295.20f, + 2 => (uint)1213.60f, + 4 => (uint)942.03f, + 6 => (uint)1001.55f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)11941.05f; - case 2: - return (uint)37197.37f; - case 4: - return (uint)69749.84f; - case 6: - return (uint)120042.40f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)11941.05f, + 2 => (uint)37197.37f, + 4 => (uint)69749.84f, + 6 => (uint)120042.40f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)997.67f; - case 2: - return (uint)977.63f; - case 4: - return (uint)792.30f; - case 6: - return (uint)875.43f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)997.67f, + 2 => (uint)977.63f, + 4 => (uint)792.30f, + 6 => (uint)875.43f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } public virtual uint Estimate(ReverbCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)81475.05f; - case 2: - return (uint)84975.0f; - case 4: - return (uint)91625.15f; - case 6: - return (uint)95332.27f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)81475.05f, + 2 => (uint)84975.0f, + 4 => (uint)91625.15f, + 6 => (uint)95332.27f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)536.30f; - case 2: - return (uint)588.70f; - case 4: - return (uint)643.70f; - case 6: - return (uint)706.0f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)536.30f, + 2 => (uint)588.70f, + 4 => (uint)643.70f, + 6 => (uint)706.0f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)120174.47f; - case 2: - return (uint)25262.22f; - case 4: - return (uint)135751.23f; - case 6: - return (uint)141129.23f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)120174.47f, + 2 => (uint)25262.22f, + 4 => (uint)135751.23f, + 6 => (uint)141129.23f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)617.64f; - case 2: - return (uint)659.54f; - case 4: - return (uint)711.43f; - case 6: - return (uint)778.07f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)617.64f, + 2 => (uint)659.54f, + 4 => (uint)711.43f, + 6 => (uint)778.07f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } public virtual uint Estimate(Reverb3dCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)116754.0f; - case 2: - return (uint)125912.05f; - case 4: - return (uint)146336.03f; - case 6: - return (uint)165812.66f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)116754.0f, + 2 => (uint)125912.05f, + 4 => (uint)146336.03f, + 6 => (uint)165812.66f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)734.0f; - case 2: - return (uint)766.62f; - case 4: - return (uint)797.46f; - case 6: - return (uint)867.43f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)734.0f, + 2 => (uint)766.62f, + 4 => (uint)797.46f, + 6 => (uint)867.43f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)170292.34f; - case 2: - return (uint)183875.63f; - case 4: - return (uint)214696.19f; - case 6: - return (uint)243846.77f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)170292.34f, + 2 => (uint)183875.63f, + 4 => (uint)214696.19f, + 6 => (uint)243846.77f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)508.47f; - case 2: - return (uint)582.45f; - case 4: - return (uint)626.42f; - case 6: - return (uint)682.47f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)508.47f, + 2 => (uint)582.45f, + 4 => (uint)626.42f, + 6 => (uint)682.47f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } public uint Estimate(AuxiliaryBufferCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { if (command.Enabled) { @@ -427,9 +355,9 @@ namespace Ryujinx.Audio.Renderer.Server public uint Estimate(VolumeCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)1311.1f; } @@ -439,12 +367,12 @@ namespace Ryujinx.Audio.Renderer.Server public uint Estimate(CircularBufferSinkCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); float costPerBuffer = 770.26f; float baseCost = 0f; - if (_sampleCount == 160) + if (SampleCount == 160) { costPerBuffer = 531.07f; } @@ -454,9 +382,9 @@ namespace Ryujinx.Audio.Renderer.Server public uint Estimate(DownMixSurroundToStereoCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)9949.7f; } @@ -466,9 +394,9 @@ namespace Ryujinx.Audio.Renderer.Server public uint Estimate(UpsampleCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)312990.0f; } @@ -478,12 +406,12 @@ namespace Ryujinx.Audio.Renderer.Server public uint Estimate(DeviceSinkCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); Debug.Assert(command.InputCount == 2 || command.InputCount == 6); if (command.InputCount == 2) { - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)8980.0f; } @@ -491,7 +419,7 @@ namespace Ryujinx.Audio.Renderer.Server return (uint)9221.9f; } - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)9177.9f; } @@ -501,27 +429,27 @@ namespace Ryujinx.Audio.Renderer.Server public uint Estimate(PcmFloatDataSourceCommandVersion1 command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); float costPerSample = 3490.9f; float baseCost = 10090.9f; - if (_sampleCount == 160) + if (SampleCount == 160) { costPerSample = 2310.4f; baseCost = 7845.25f; } - return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / _sampleCount) * (command.Pitch * 0.000030518f)))); + return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / SampleCount) * (command.Pitch * 0.000030518f)))); } public uint Estimate(DataSourceVersion2Command command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - (float baseCost, float costPerSample) = GetCostByFormat(_sampleCount, command.SampleFormat, command.SrcQuality); + (float baseCost, float costPerSample) = GetCostByFormat(SampleCount, command.SampleFormat, command.SrcQuality); - return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / _sampleCount) * (command.Pitch * 0.000030518f) - 1.0f))); + return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / SampleCount) * (command.Pitch * 0.000030518f) - 1.0f))); } private static (float, float) GetCostByFormat(uint sampleCount, SampleFormat format, SampleRateConversionQuality quality) @@ -618,124 +546,90 @@ namespace Ryujinx.Audio.Renderer.Server private uint EstimateLimiterCommandCommon(LimiterParameter parameter, bool enabled) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { if (enabled) { - switch (parameter.ChannelCount) + return parameter.ChannelCount switch { - case 1: - return (uint)21392.0f; - case 2: - return (uint)26829.0f; - case 4: - return (uint)32405.0f; - case 6: - return (uint)52219.0f; - default: - throw new NotImplementedException($"{parameter.ChannelCount}"); - } + 1 => (uint)21392.0f, + 2 => (uint)26829.0f, + 4 => (uint)32405.0f, + 6 => (uint)52219.0f, + _ => throw new NotImplementedException($"{parameter.ChannelCount}"), + }; } - else + + return parameter.ChannelCount switch { - switch (parameter.ChannelCount) - { - case 1: - return (uint)897.0f; - case 2: - return (uint)931.55f; - case 4: - return (uint)975.39f; - case 6: - return (uint)1016.8f; - default: - throw new NotImplementedException($"{parameter.ChannelCount}"); - } - } + 1 => (uint)897.0f, + 2 => (uint)931.55f, + 4 => (uint)975.39f, + 6 => (uint)1016.8f, + _ => throw new NotImplementedException($"{parameter.ChannelCount}"), + }; } if (enabled) { - switch (parameter.ChannelCount) + return parameter.ChannelCount switch { - case 1: - return (uint)30556.0f; - case 2: - return (uint)39011.0f; - case 4: - return (uint)48270.0f; - case 6: - return (uint)76712.0f; - default: - throw new NotImplementedException($"{parameter.ChannelCount}"); - } + 1 => (uint)30556.0f, + 2 => (uint)39011.0f, + 4 => (uint)48270.0f, + 6 => (uint)76712.0f, + _ => throw new NotImplementedException($"{parameter.ChannelCount}"), + }; } - else + + return parameter.ChannelCount switch { - switch (parameter.ChannelCount) - { - case 1: - return (uint)874.43f; - case 2: - return (uint)921.55f; - case 4: - return (uint)945.26f; - case 6: - return (uint)992.26f; - default: - throw new NotImplementedException($"{parameter.ChannelCount}"); - } - } + 1 => (uint)874.43f, + 2 => (uint)921.55f, + 4 => (uint)945.26f, + 6 => (uint)992.26f, + _ => throw new NotImplementedException($"{parameter.ChannelCount}"), + }; } public uint Estimate(LimiterCommandVersion1 command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); return EstimateLimiterCommandCommon(command.Parameter, command.IsEffectEnabled); } public uint Estimate(LimiterCommandVersion2 command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); if (!command.Parameter.StatisticsEnabled || !command.IsEffectEnabled) { return EstimateLimiterCommandCommon(command.Parameter, command.IsEffectEnabled); } - if (_sampleCount == 160) + if (SampleCount == 160) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)23309.0f; - case 2: - return (uint)29954.0f; - case 4: - return (uint)35807.0f; - case 6: - return (uint)58340.0f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)23309.0f, + 2 => (uint)29954.0f, + 4 => (uint)35807.0f, + 6 => (uint)58340.0f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return (uint)33526.0f; - case 2: - return (uint)43549.0f; - case 4: - return (uint)52190.0f; - case 6: - return (uint)85527.0f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => (uint)33526.0f, + 2 => (uint)43549.0f, + 4 => (uint)52190.0f, + 6 => (uint)85527.0f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } public virtual uint Estimate(GroupedBiquadFilterCommand command) @@ -753,4 +647,4 @@ namespace Ryujinx.Audio.Renderer.Server return 0; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion4.cs b/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion4.cs index c60d8ebcb..25bc67cd9 100644 --- a/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion4.cs +++ b/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion4.cs @@ -12,9 +12,9 @@ namespace Ryujinx.Audio.Renderer.Server public override uint Estimate(GroupedBiquadFilterCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { return (uint)7424.5f; } @@ -24,9 +24,9 @@ namespace Ryujinx.Audio.Renderer.Server public override uint Estimate(CaptureBufferCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { if (command.Enabled) { @@ -44,4 +44,4 @@ namespace Ryujinx.Audio.Renderer.Server return (uint)435.2f; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion5.cs b/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion5.cs index 2ed7e6a5b..7135c1c4f 100644 --- a/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion5.cs +++ b/src/Ryujinx.Audio/Renderer/Server/CommandProcessingTimeEstimatorVersion5.cs @@ -13,298 +13,202 @@ namespace Ryujinx.Audio.Renderer.Server public override uint Estimate(DelayCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return 8929; - case 2: - return 25501; - case 4: - return 47760; - case 6: - return 82203; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => 8929, + 2 => 25501, + 4 => 47760, + 6 => 82203, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)1295.20f; - case 2: - return (uint)1213.60f; - case 4: - return (uint)942.03f; - case 6: - return (uint)1001.6f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)1295.20f, + 2 => (uint)1213.60f, + 4 => (uint)942.03f, + 6 => (uint)1001.6f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return 11941; - case 2: - return 37197; - case 4: - return 69750; - case 6: - return 12004; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => 11941, + 2 => 37197, + 4 => 69750, + 6 => 12004, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)997.67f; - case 2: - return (uint)977.63f; - case 4: - return (uint)792.31f; - case 6: - return (uint)875.43f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)997.67f, + 2 => (uint)977.63f, + 4 => (uint)792.31f, + 6 => (uint)875.43f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } public override uint Estimate(ReverbCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return 81475; - case 2: - return 84975; - case 4: - return 91625; - case 6: - return 95332; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => 81475, + 2 => 84975, + 4 => 91625, + 6 => 95332, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)536.30f; - case 2: - return (uint)588.80f; - case 4: - return (uint)643.70f; - case 6: - return (uint)706.0f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)536.30f, + 2 => (uint)588.80f, + 4 => (uint)643.70f, + 6 => (uint)706.0f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return 120170; - case 2: - return 125260; - case 4: - return 135750; - case 6: - return 141130; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => 120170, + 2 => 125260, + 4 => 135750, + 6 => 141130, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)617.64f; - case 2: - return (uint)659.54f; - case 4: - return (uint)711.44f; - case 6: - return (uint)778.07f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)617.64f, + 2 => (uint)659.54f, + 4 => (uint)711.44f, + 6 => (uint)778.07f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } public override uint Estimate(Reverb3dCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return 116750; - case 2: - return 125910; - case 4: - return 146340; - case 6: - return 165810; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => 116750, + 2 => 125910, + 4 => 146340, + 6 => 165810, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return 735; - case 2: - return (uint)766.62f; - case 4: - return (uint)834.07f; - case 6: - return (uint)875.44f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => 735, + 2 => (uint)766.62f, + 4 => (uint)834.07f, + 6 => (uint)875.44f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return 170290; - case 2: - return 183880; - case 4: - return 214700; - case 6: - return 243850; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => 170290, + 2 => 183880, + 4 => 214700, + 6 => 243850, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)508.47f; - case 2: - return (uint)582.45f; - case 4: - return (uint)626.42f; - case 6: - return (uint)682.47f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)508.47f, + 2 => (uint)582.45f, + 4 => (uint)626.42f, + 6 => (uint)682.47f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } public override uint Estimate(CompressorCommand command) { - Debug.Assert(_sampleCount == 160 || _sampleCount == 240); + Debug.Assert(SampleCount == 160 || SampleCount == 240); - if (_sampleCount == 160) + if (SampleCount == 160) { if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return 34431; - case 2: - return 44253; - case 4: - return 63827; - case 6: - return 83361; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => 34431, + 2 => 44253, + 4 => 63827, + 6 => 83361, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)630.12f; - case 2: - return (uint)638.27f; - case 4: - return (uint)705.86f; - case 6: - return (uint)782.02f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)630.12f, + 2 => (uint)638.27f, + 4 => (uint)705.86f, + 6 => (uint)782.02f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } if (command.Enabled) { - switch (command.Parameter.ChannelCount) + return command.Parameter.ChannelCount switch { - case 1: - return 51095; - case 2: - return 65693; - case 4: - return 95383; - case 6: - return 124510; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } + 1 => 51095, + 2 => 65693, + 4 => 95383, + 6 => 124510, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } - else + + return command.Parameter.ChannelCount switch { - switch (command.Parameter.ChannelCount) - { - case 1: - return (uint)840.14f; - case 2: - return (uint)826.1f; - case 4: - return (uint)901.88f; - case 6: - return (uint)965.29f; - default: - throw new NotImplementedException($"{command.Parameter.ChannelCount}"); - } - } + 1 => (uint)840.14f, + 2 => (uint)826.1f, + 4 => (uint)901.88f, + 6 => (uint)965.29f, + _ => throw new NotImplementedException($"{command.Parameter.ChannelCount}"), + }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Effect/AuxiliaryBufferEffect.cs b/src/Ryujinx.Audio/Renderer/Server/Effect/AuxiliaryBufferEffect.cs index 164065271..57ca266f4 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Effect/AuxiliaryBufferEffect.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Effect/AuxiliaryBufferEffect.cs @@ -58,7 +58,7 @@ namespace Ryujinx.Audio.Renderer.Server.Effect { ulong bufferSize = (ulong)Unsafe.SizeOf() * Parameter.BufferStorageSize + (ulong)Unsafe.SizeOf(); - bool sendBufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[0], Parameter.SendBufferInfoAddress, bufferSize); + bool sendBufferUnmapped = !mapper.TryAttachBuffer(out _, ref WorkBuffers[0], Parameter.SendBufferInfoAddress, bufferSize); bool returnBufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[1], Parameter.ReturnBufferInfoAddress, bufferSize); BufferUnmapped = sendBufferUnmapped && returnBufferUnmapped; @@ -82,4 +82,4 @@ namespace Ryujinx.Audio.Renderer.Server.Effect UpdateUsageStateForCommandGeneration(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Effect/BaseEffect.cs b/src/Ryujinx.Audio/Renderer/Server/Effect/BaseEffect.cs index 825b3bf76..a9716db2a 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Effect/BaseEffect.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Effect/BaseEffect.cs @@ -244,29 +244,19 @@ namespace Ryujinx.Audio.Renderer.Server.Effect /// The associated to the of this effect. public PerformanceDetailType GetPerformanceDetailType() { - switch (Type) + return Type switch { - 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; - case EffectType.Limiter: - return PerformanceDetailType.Limiter; - case EffectType.CaptureBuffer: - return PerformanceDetailType.CaptureBuffer; - case EffectType.Compressor: - return PerformanceDetailType.Compressor; - default: - throw new NotImplementedException($"{Type}"); - } + EffectType.BiquadFilter => PerformanceDetailType.BiquadFilter, + EffectType.AuxiliaryBuffer => PerformanceDetailType.Aux, + EffectType.Delay => PerformanceDetailType.Delay, + EffectType.Reverb => PerformanceDetailType.Reverb, + EffectType.Reverb3d => PerformanceDetailType.Reverb3d, + EffectType.BufferMix => PerformanceDetailType.Mix, + EffectType.Limiter => PerformanceDetailType.Limiter, + EffectType.CaptureBuffer => PerformanceDetailType.CaptureBuffer, + EffectType.Compressor => PerformanceDetailType.Compressor, + _ => throw new NotImplementedException($"{Type}"), + }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Effect/BiquadFilterEffect.cs b/src/Ryujinx.Audio/Renderer/Server/Effect/BiquadFilterEffect.cs index de91046dc..b987f7c85 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Effect/BiquadFilterEffect.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Effect/BiquadFilterEffect.cs @@ -64,4 +64,4 @@ namespace Ryujinx.Audio.Renderer.Server.Effect Parameter.Status = UsageState.Enabled; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Effect/BufferMixEffect.cs b/src/Ryujinx.Audio/Renderer/Server/Effect/BufferMixEffect.cs index 82c0a055a..d6cb9cfa3 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Effect/BufferMixEffect.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Effect/BufferMixEffect.cs @@ -46,4 +46,4 @@ namespace Ryujinx.Audio.Renderer.Server.Effect UpdateUsageStateForCommandGeneration(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Effect/CaptureBufferEffect.cs b/src/Ryujinx.Audio/Renderer/Server/Effect/CaptureBufferEffect.cs index c445798d4..5be4b4ed5 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Effect/CaptureBufferEffect.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Effect/CaptureBufferEffect.cs @@ -79,4 +79,4 @@ namespace Ryujinx.Audio.Renderer.Server.Effect UpdateUsageStateForCommandGeneration(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Effect/DelayEffect.cs b/src/Ryujinx.Audio/Renderer/Server/Effect/DelayEffect.cs index 3f5d70bcf..43cabb7db 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Effect/DelayEffect.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Effect/DelayEffect.cs @@ -90,4 +90,4 @@ namespace Ryujinx.Audio.Renderer.Server.Effect Parameter.Status = UsageState.Enabled; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Effect/EffectContext.cs b/src/Ryujinx.Audio/Renderer/Server/Effect/EffectContext.cs index bfb6528b4..619f31100 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Effect/EffectContext.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Effect/EffectContext.cs @@ -120,4 +120,4 @@ namespace Ryujinx.Audio.Renderer.Server.Effect } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Effect/LimiterEffect.cs b/src/Ryujinx.Audio/Renderer/Server/Effect/LimiterEffect.cs index 6e17ef3d1..3e2f7326d 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Effect/LimiterEffect.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Effect/LimiterEffect.cs @@ -92,4 +92,4 @@ namespace Ryujinx.Audio.Renderer.Server.Effect destState = srcState; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Effect/Reverb3dEffect.cs b/src/Ryujinx.Audio/Renderer/Server/Effect/Reverb3dEffect.cs index 473fddb84..f9d7f4943 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Effect/Reverb3dEffect.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Effect/Reverb3dEffect.cs @@ -89,4 +89,4 @@ namespace Ryujinx.Audio.Renderer.Server.Effect Parameter.ParameterStatus = UsageState.Enabled; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Effect/ReverbEffect.cs b/src/Ryujinx.Audio/Renderer/Server/Effect/ReverbEffect.cs index e1543fd17..6fdf8fc23 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Effect/ReverbEffect.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Effect/ReverbEffect.cs @@ -92,4 +92,4 @@ namespace Ryujinx.Audio.Renderer.Server.Effect Parameter.Status = UsageState.Enabled; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Effect/UsageState.cs b/src/Ryujinx.Audio/Renderer/Server/Effect/UsageState.cs index 8648aa2ca..da7172244 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Effect/UsageState.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Effect/UsageState.cs @@ -23,6 +23,6 @@ namespace Ryujinx.Audio.Renderer.Server.Effect /// /// The effect is disabled. /// - Disabled + Disabled, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/ICommandProcessingTimeEstimator.cs b/src/Ryujinx.Audio/Renderer/Server/ICommandProcessingTimeEstimator.cs index 4872ddb3a..27b22363a 100644 --- a/src/Ryujinx.Audio/Renderer/Server/ICommandProcessingTimeEstimator.cs +++ b/src/Ryujinx.Audio/Renderer/Server/ICommandProcessingTimeEstimator.cs @@ -37,4 +37,4 @@ namespace Ryujinx.Audio.Renderer.Server uint Estimate(CaptureBufferCommand command); uint Estimate(CompressorCommand command); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/MemoryPool/AddressInfo.cs b/src/Ryujinx.Audio/Renderer/Server/MemoryPool/AddressInfo.cs index 5fd6b2b92..a7ec4cf51 100644 --- a/src/Ryujinx.Audio/Renderer/Server/MemoryPool/AddressInfo.cs +++ b/src/Ryujinx.Audio/Renderer/Server/MemoryPool/AddressInfo.cs @@ -27,9 +27,9 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool /// public DspAddress ForceMappedDspAddress; - private unsafe ref MemoryPoolState MemoryPoolState => ref *_memoryPools; + private readonly unsafe ref MemoryPoolState MemoryPoolState => ref *_memoryPools; - public unsafe bool HasMemoryPoolState => (IntPtr)_memoryPools != IntPtr.Zero; + public readonly unsafe bool HasMemoryPoolState => (IntPtr)_memoryPools != IntPtr.Zero; /// /// Create an new empty . @@ -55,7 +55,7 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool CpuAddress = cpuAddress, _memoryPools = MemoryPoolState.Null, Size = size, - ForceMappedDspAddress = 0 + ForceMappedDspAddress = 0, }; } } @@ -105,7 +105,7 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool /// Check if the is mapped. /// /// Returns true if the is mapped. - public bool HasMappedMemoryPool() + public readonly bool HasMappedMemoryPool() { return HasMemoryPoolState && MemoryPoolState.IsMapped(); } @@ -115,7 +115,7 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool /// /// If true, mark the as used. /// Returns the DSP address associated to the . - public DspAddress GetReference(bool markUsed) + public readonly DspAddress GetReference(bool markUsed) { if (!HasMappedMemoryPool()) { @@ -130,4 +130,4 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool return MemoryPoolState.Translate(CpuAddress, Size); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/MemoryPool/MemoryPoolState.cs b/src/Ryujinx.Audio/Renderer/Server/MemoryPool/MemoryPoolState.cs index 69466bab5..91bd5dbf5 100644 --- a/src/Ryujinx.Audio/Renderer/Server/MemoryPool/MemoryPoolState.cs +++ b/src/Ryujinx.Audio/Renderer/Server/MemoryPool/MemoryPoolState.cs @@ -26,7 +26,7 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool /// /// located on the DSP side for system use. /// - Dsp + Dsp, } /// @@ -69,7 +69,7 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool CpuAddress = 0, DspAddress = 0, Size = 0, - Location = location + Location = location, }; } @@ -90,7 +90,7 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool /// The . /// The size. /// True if the is contained inside the . - public bool Contains(CpuAddress targetCpuAddress, ulong size) + public readonly bool Contains(CpuAddress targetCpuAddress, ulong size) { if (CpuAddress <= targetCpuAddress && size + targetCpuAddress <= Size + CpuAddress) { @@ -106,7 +106,7 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool /// The . /// The size. /// the target DSP address. - public DspAddress Translate(CpuAddress targetCpuAddress, ulong size) + public readonly DspAddress Translate(CpuAddress targetCpuAddress, ulong size) { if (Contains(targetCpuAddress, size) && IsMapped()) { @@ -122,9 +122,9 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool /// Is the mapped on the DSP? /// /// Returns true if the is mapped on the DSP. - public bool IsMapped() + public readonly bool IsMapped() { return DspAddress != 0; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/MemoryPool/PoolMapper.cs b/src/Ryujinx.Audio/Renderer/Server/MemoryPool/PoolMapper.cs index 4a29ead3e..391b80f8d 100644 --- a/src/Ryujinx.Audio/Renderer/Server/MemoryPool/PoolMapper.cs +++ b/src/Ryujinx.Audio/Renderer/Server/MemoryPool/PoolMapper.cs @@ -40,23 +40,23 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool /// /// unmapping failed. /// - UnmapError = 3 + UnmapError = 3, } /// /// The handle of the process owning the CPU memory manipulated. /// - private uint _processHandle; + private readonly uint _processHandle; /// /// The that will be manipulated. /// - private Memory _memoryPools; + private readonly Memory _memoryPools; /// /// If set to true, this will try to force map memory pool even if their state are considered invalid. /// - private bool _isForceMapEnabled; + private readonly bool _isForceMapEnabled; /// /// Create a new used for system mapping. @@ -125,7 +125,8 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool { return CurrentProcessPseudoHandle; } - else if (memoryPool.Location == MemoryPoolState.LocationType.Dsp) + + if (memoryPool.Location == MemoryPoolState.LocationType.Dsp) { return _processHandle; } @@ -234,13 +235,11 @@ namespace Ryujinx.Audio.Renderer.Server.MemoryPool return true; } - else - { - errorInfo.ErrorCode = ResultCode.InvalidAddressInfo; - errorInfo.ExtraErrorInfo = addressInfo.CpuAddress; - return _isForceMapEnabled; - } + errorInfo.ErrorCode = ResultCode.InvalidAddressInfo; + errorInfo.ExtraErrorInfo = addressInfo.CpuAddress; + + return _isForceMapEnabled; } /// diff --git a/src/Ryujinx.Audio/Renderer/Server/Mix/MixContext.cs b/src/Ryujinx.Audio/Renderer/Server/Mix/MixContext.cs index cda6f737c..8991ceaf9 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Mix/MixContext.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Mix/MixContext.cs @@ -206,7 +206,7 @@ namespace Ryujinx.Audio.Renderer.Server.Mix { UpdateDistancesFromFinalMix(); - int[] sortedMixesTemp = _sortedMixes.Slice(0, (int)GetCount()).ToArray(); + int[] sortedMixesTemp = _sortedMixes[..(int)GetCount()].ToArray(); Array.Sort(sortedMixesTemp, (a, b) => { @@ -248,12 +248,10 @@ namespace Ryujinx.Audio.Renderer.Server.Mix return isValid; } - else - { - UpdateMixBufferOffset(); - return true; - } + UpdateMixBufferOffset(); + + return true; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Mix/MixState.cs b/src/Ryujinx.Audio/Renderer/Server/Mix/MixState.cs index 146e67811..88ae44831 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Mix/MixState.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Mix/MixState.cs @@ -7,7 +7,6 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; - using static Ryujinx.Audio.Constants; namespace Ryujinx.Audio.Renderer.Server.Mix @@ -66,7 +65,7 @@ namespace Ryujinx.Audio.Renderer.Server.Mix /// /// The effect processing order storage. /// - private IntPtr _effectProcessingOrderArrayPointer; + private readonly IntPtr _effectProcessingOrderArrayPointer; /// /// The max element count that can be found in the effect processing order storage. @@ -120,7 +119,7 @@ namespace Ryujinx.Audio.Renderer.Server.Mix /// /// The array used to order effects associated to this mix. /// - public Span EffectProcessingOrderArray + public readonly Span EffectProcessingOrderArray { get { @@ -175,7 +174,7 @@ namespace Ryujinx.Audio.Renderer.Server.Mix /// /// Clear the to its default state. /// - public void ClearEffectProcessingOrder() + public readonly void ClearEffectProcessingOrder() { EffectProcessingOrderArray.Fill(-1); } @@ -184,7 +183,7 @@ namespace Ryujinx.Audio.Renderer.Server.Mix /// Return true if the mix has any destinations. /// /// True if the mix has any destinations. - public bool HasAnyDestination() + public readonly bool HasAnyDestination() { return DestinationMixId != UnusedMixId || DestinationSplitterId != UnusedSplitterId; } @@ -310,4 +309,4 @@ namespace Ryujinx.Audio.Renderer.Server.Mix return isDirty; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceDetailEntry.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceDetailEntry.cs index dbe59cb0d..ffabf4676 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceDetailEntry.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceDetailEntry.cs @@ -49,4 +49,4 @@ namespace Ryujinx.Audio.Renderer.Server.Performance /// The type to use. void SetDetailType(PerformanceDetailType detailType); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceEntry.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceEntry.cs index 9888a4cc1..a0178187b 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceEntry.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceEntry.cs @@ -43,4 +43,4 @@ namespace Ryujinx.Audio.Renderer.Server.Performance /// The type to use. void SetEntryType(PerformanceEntryType type); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceHeader.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceHeader.cs index 21876b4b4..deacd8ccc 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceHeader.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/IPerformanceHeader.cs @@ -77,4 +77,4 @@ namespace Ryujinx.Audio.Renderer.Server.Performance /// The total count of detailed entries in this frame. void SetEntryDetailCount(int entryDetailCount); } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceDetailVersion1.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceDetailVersion1.cs index 22704c0d1..a4024607c 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceDetailVersion1.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceDetailVersion1.cs @@ -34,22 +34,22 @@ namespace Ryujinx.Audio.Renderer.Server.Performance /// public PerformanceEntryType EntryType; - public int GetProcessingTime() + public readonly int GetProcessingTime() { return ProcessingTime; } - public int GetProcessingTimeOffset() + public readonly int GetProcessingTimeOffset() { return 8; } - public int GetStartTime() + public readonly int GetStartTime() { return StartTime; } - public int GetStartTimeOffset() + public readonly int GetStartTimeOffset() { return 4; } @@ -69,4 +69,4 @@ namespace Ryujinx.Audio.Renderer.Server.Performance NodeId = nodeId; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceDetailVersion2.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceDetailVersion2.cs index 05ecda9b6..f10e2937e 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceDetailVersion2.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceDetailVersion2.cs @@ -34,22 +34,22 @@ namespace Ryujinx.Audio.Renderer.Server.Performance /// public PerformanceEntryType EntryType; - public int GetProcessingTime() + public readonly int GetProcessingTime() { return ProcessingTime; } - public int GetProcessingTimeOffset() + public readonly int GetProcessingTimeOffset() { return 8; } - public int GetStartTime() + public readonly int GetStartTime() { return StartTime; } - public int GetStartTimeOffset() + public readonly int GetStartTimeOffset() { return 4; } @@ -69,4 +69,4 @@ namespace Ryujinx.Audio.Renderer.Server.Performance NodeId = nodeId; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryAddresses.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryAddresses.cs index 1b8d8668a..d24b96a27 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryAddresses.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryAddresses.cs @@ -53,4 +53,4 @@ namespace Ryujinx.Audio.Renderer.Server.Performance BaseMemory.Span[(int)ProcessingTimeOffset / 4] = (int)(endTimeNano / 1000) - BaseMemory.Span[(int)StartTimeOffset / 4]; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryVersion1.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryVersion1.cs index fa2d32164..2c407670f 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryVersion1.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryVersion1.cs @@ -29,22 +29,22 @@ namespace Ryujinx.Audio.Renderer.Server.Performance /// public PerformanceEntryType EntryType; - public int GetProcessingTime() + public readonly int GetProcessingTime() { return ProcessingTime; } - public int GetProcessingTimeOffset() + public readonly int GetProcessingTimeOffset() { return 8; } - public int GetStartTime() + public readonly int GetStartTime() { return StartTime; } - public int GetStartTimeOffset() + public readonly int GetStartTimeOffset() { return 4; } @@ -59,4 +59,4 @@ namespace Ryujinx.Audio.Renderer.Server.Performance NodeId = nodeId; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryVersion2.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryVersion2.cs index 49d4b3ce0..eb96a3141 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryVersion2.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceEntryVersion2.cs @@ -29,22 +29,22 @@ namespace Ryujinx.Audio.Renderer.Server.Performance /// public PerformanceEntryType EntryType; - public int GetProcessingTime() + public readonly int GetProcessingTime() { return ProcessingTime; } - public int GetProcessingTimeOffset() + public readonly int GetProcessingTimeOffset() { return 8; } - public int GetStartTime() + public readonly int GetStartTime() { return StartTime; } - public int GetStartTimeOffset() + public readonly int GetStartTimeOffset() { return 4; } @@ -59,4 +59,4 @@ namespace Ryujinx.Audio.Renderer.Server.Performance NodeId = nodeId; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceFrameHeaderVersion1.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceFrameHeaderVersion1.cs index 5fe6bff06..5aeb703c5 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceFrameHeaderVersion1.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceFrameHeaderVersion1.cs @@ -38,22 +38,22 @@ namespace Ryujinx.Audio.Renderer.Server.Performance /// public uint VoiceDropCount; - public int GetEntryCount() + public readonly int GetEntryCount() { return EntryCount; } - public int GetEntryCountOffset() + public readonly int GetEntryCountOffset() { return 4; } - public int GetEntryDetailCount() + public readonly int GetEntryDetailCount() { return EntryDetailCount; } - public void SetDspRunningBehind(bool isRunningBehind) + public readonly void SetDspRunningBehind(bool isRunningBehind) { // NOTE: Not present in version 1 } @@ -68,7 +68,7 @@ namespace Ryujinx.Audio.Renderer.Server.Performance EntryDetailCount = entryDetailCount; } - public void SetIndex(uint index) + public readonly void SetIndex(uint index) { // NOTE: Not present in version 1 } @@ -83,7 +83,7 @@ namespace Ryujinx.Audio.Renderer.Server.Performance NextOffset = nextOffset; } - public void SetStartRenderingTicks(ulong startTicks) + public readonly void SetStartRenderingTicks(ulong startTicks) { // NOTE: not present in version 1 } @@ -98,4 +98,4 @@ namespace Ryujinx.Audio.Renderer.Server.Performance VoiceDropCount = voiceCount; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceFrameHeaderVersion2.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceFrameHeaderVersion2.cs index a18229686..d6e0ffc8b 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceFrameHeaderVersion2.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceFrameHeaderVersion2.cs @@ -54,17 +54,17 @@ namespace Ryujinx.Audio.Renderer.Server.Performance [MarshalAs(UnmanagedType.I1)] public bool IsDspRunningBehind; - public int GetEntryCount() + public readonly int GetEntryCount() { return EntryCount; } - public int GetEntryCountOffset() + public readonly int GetEntryCountOffset() { return 4; } - public int GetEntryDetailCount() + public readonly int GetEntryDetailCount() { return EntryDetailCount; } @@ -114,4 +114,4 @@ namespace Ryujinx.Audio.Renderer.Server.Performance VoiceDropCount = voiceCount; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManager.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManager.cs index f996441c0..0a035916c 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManager.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManager.cs @@ -22,11 +22,12 @@ namespace Ryujinx.Audio.Renderer.Server.Performance PerformanceEntryVersion2, PerformanceDetailVersion2>.GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref parameter); } - else if (version == 1) + + if (version == 1) { return (ulong)PerformanceManagerGeneric.GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref parameter); + PerformanceEntryVersion1, + PerformanceDetailVersion1>.GetRequiredBufferSizeForPerformanceMetricsPerFrame(ref parameter); } throw new NotImplementedException($"Unknown Performance metrics data format version {version}"); @@ -90,17 +91,12 @@ namespace Ryujinx.Audio.Renderer.Server.Performance { uint version = behaviourContext.GetPerformanceMetricsDataFormat(); - switch (version) + return version switch { - case 1: - return new PerformanceManagerGeneric(performanceBuffer, - ref parameter); - case 2: - return new PerformanceManagerGeneric(performanceBuffer, - ref parameter); - default: - throw new NotImplementedException($"Unknown Performance metrics data format version {version}"); - } + 1 => new PerformanceManagerGeneric(performanceBuffer, ref parameter), + 2 => new PerformanceManagerGeneric(performanceBuffer, ref parameter), + _ => throw new NotImplementedException($"Unknown Performance metrics data format version {version}"), + }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManagerGeneric.cs b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManagerGeneric.cs index 18e77391d..5a70a1bcf 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManagerGeneric.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Performance/PerformanceManagerGeneric.cs @@ -25,20 +25,20 @@ namespace Ryujinx.Audio.Renderer.Server.Performance /// private const int MaxFrameDetailCount = 100; - private Memory _buffer; - private Memory _historyBuffer; + private readonly Memory _buffer; + private readonly Memory _historyBuffer; - private Memory CurrentBuffer => _buffer.Slice(0, _frameSize); - private Memory CurrentBufferData => CurrentBuffer.Slice(Unsafe.SizeOf()); + private Memory CurrentBuffer => _buffer[.._frameSize]; + private Memory CurrentBufferData => CurrentBuffer[Unsafe.SizeOf()..]; private ref THeader CurrentHeader => ref MemoryMarshal.Cast(CurrentBuffer.Span)[0]; - private Span Entries => MemoryMarshal.Cast(CurrentBufferData.Span.Slice(0, GetEntriesSize())); + private Span Entries => MemoryMarshal.Cast(CurrentBufferData.Span[..GetEntriesSize()]); private Span EntriesDetail => MemoryMarshal.Cast(CurrentBufferData.Span.Slice(GetEntriesSize(), GetEntriesDetailSize())); - private int _frameSize; - private int _availableFrameCount; - private int _entryCountPerFrame; + private readonly int _frameSize; + private readonly int _availableFrameCount; + private readonly int _entryCountPerFrame; private int _detailTarget; private int _entryIndex; private int _entryDetailIndex; @@ -56,7 +56,7 @@ namespace Ryujinx.Audio.Renderer.Server.Performance _historyFrameIndex = 0; - _historyBuffer = _buffer.Slice(_frameSize); + _historyBuffer = _buffer[_frameSize..]; SetupNewHeader(); } @@ -130,7 +130,7 @@ namespace Ryujinx.Audio.Renderer.Server.Performance Span inputEntries = GetEntriesFromBuffer(_historyBuffer.Span, _indexHistoryRead); Span inputEntriesDetail = GetEntriesDetailFromBuffer(_historyBuffer.Span, _indexHistoryRead); - Span targetSpan = performanceOutput.Slice(nextOffset); + Span targetSpan = performanceOutput[nextOffset..]; // NOTE: We check for the space for two headers for the final blank header. int requiredSpace = Unsafe.SizeOf() + Unsafe.SizeOf() * inputHeader.GetEntryCount() @@ -146,7 +146,7 @@ namespace Ryujinx.Audio.Renderer.Server.Performance nextOffset += Unsafe.SizeOf(); - Span outputEntries = MemoryMarshal.Cast(performanceOutput.Slice(nextOffset)); + Span outputEntries = MemoryMarshal.Cast(performanceOutput[nextOffset..]); int totalProcessingTime = 0; @@ -168,7 +168,7 @@ namespace Ryujinx.Audio.Renderer.Server.Performance } } - Span outputEntriesDetail = MemoryMarshal.Cast(performanceOutput.Slice(nextOffset)); + Span outputEntriesDetail = MemoryMarshal.Cast(performanceOutput[nextOffset..]); int effectiveEntryDetailCount = 0; @@ -198,7 +198,7 @@ namespace Ryujinx.Audio.Renderer.Server.Performance if (nextOffset < performanceOutput.Length && (performanceOutput.Length - nextOffset) >= Unsafe.SizeOf()) { - ref THeader outputHeader = ref MemoryMarshal.Cast(performanceOutput.Slice(nextOffset))[0]; + ref THeader outputHeader = ref MemoryMarshal.Cast(performanceOutput[nextOffset..])[0]; outputHeader = default; } @@ -208,9 +208,11 @@ namespace Ryujinx.Audio.Renderer.Server.Performance public override bool GetNextEntry(out PerformanceEntryAddresses performanceEntry, PerformanceEntryType entryType, int nodeId) { - performanceEntry = new PerformanceEntryAddresses(); - performanceEntry.BaseMemory = SpanMemoryManager.Cast(CurrentBuffer); - performanceEntry.EntryCountOffset = (uint)CurrentHeader.GetEntryCountOffset(); + performanceEntry = new PerformanceEntryAddresses + { + BaseMemory = SpanMemoryManager.Cast(CurrentBuffer), + EntryCountOffset = (uint)CurrentHeader.GetEntryCountOffset(), + }; uint baseEntryOffset = (uint)(Unsafe.SizeOf() + Unsafe.SizeOf() * _entryIndex); @@ -237,9 +239,11 @@ namespace Ryujinx.Audio.Renderer.Server.Performance return false; } - performanceEntry = new PerformanceEntryAddresses(); - performanceEntry.BaseMemory = SpanMemoryManager.Cast(CurrentBuffer); - performanceEntry.EntryCountOffset = (uint)CurrentHeader.GetEntryCountOffset(); + performanceEntry = new PerformanceEntryAddresses + { + BaseMemory = SpanMemoryManager.Cast(CurrentBuffer), + EntryCountOffset = (uint)CurrentHeader.GetEntryCountOffset(), + }; uint baseEntryOffset = (uint)(Unsafe.SizeOf() + GetEntriesSize() + Unsafe.SizeOf() * _entryDetailIndex); @@ -301,4 +305,4 @@ namespace Ryujinx.Audio.Renderer.Server.Performance } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/RendererSystemContext.cs b/src/Ryujinx.Audio/Renderer/Server/RendererSystemContext.cs index 164567806..090850018 100644 --- a/src/Ryujinx.Audio/Renderer/Server/RendererSystemContext.cs +++ b/src/Ryujinx.Audio/Renderer/Server/RendererSystemContext.cs @@ -45,4 +45,4 @@ namespace Ryujinx.Audio.Renderer.Server /// public Memory DepopBuffer; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Sink/BaseSink.cs b/src/Ryujinx.Audio/Renderer/Server/Sink/BaseSink.cs index f7b639975..d36c5e260 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Sink/BaseSink.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Sink/BaseSink.cs @@ -99,4 +99,4 @@ namespace Ryujinx.Audio.Renderer.Server.Sink errorInfo = new ErrorInfo(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Sink/CircularBufferSink.cs b/src/Ryujinx.Audio/Renderer/Server/Sink/CircularBufferSink.cs index 722d8c4b4..097757988 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Sink/CircularBufferSink.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Sink/CircularBufferSink.cs @@ -106,4 +106,4 @@ namespace Ryujinx.Audio.Renderer.Server.Sink base.CleanUp(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Sink/DeviceSink.cs b/src/Ryujinx.Audio/Renderer/Server/Sink/DeviceSink.cs index de345d3ad..e03fe11d4 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Sink/DeviceSink.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Sink/DeviceSink.cs @@ -72,4 +72,4 @@ namespace Ryujinx.Audio.Renderer.Server.Sink outStatus = new SinkOutStatus(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Sink/SinkContext.cs b/src/Ryujinx.Audio/Renderer/Server/Sink/SinkContext.cs index b57d39908..951984d8c 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Sink/SinkContext.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Sink/SinkContext.cs @@ -53,4 +53,4 @@ namespace Ryujinx.Audio.Renderer.Server.Sink return ref _sinks[id]; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterContext.cs b/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterContext.cs index 91877cdda..e408692ab 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterContext.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterContext.cs @@ -101,10 +101,8 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter return size; } - else - { - return size; - } + + return size; } /// @@ -164,10 +162,10 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter { ref SplitterState splitter = ref GetState(parameter.Id); - splitter.Update(this, ref parameter, input.Slice(Unsafe.SizeOf())); + splitter.Update(this, ref parameter, input[Unsafe.SizeOf()..]); } - input = input.Slice(0x1C + (int)parameter.DestinationCount * 4); + input = input[(0x1C + parameter.DestinationCount * 4)..]; } } } @@ -194,7 +192,7 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter destination.Update(parameter); } - input = input.Slice(Unsafe.SizeOf()); + input = input[Unsafe.SizeOf()..]; } } } @@ -229,12 +227,10 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter return true; } - else - { - consumedSize = 0; - return false; - } + consumedSize = 0; + + return false; } /// @@ -300,4 +296,4 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterDestination.cs b/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterDestination.cs index c074e4a72..1faf7921f 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterDestination.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterDestination.cs @@ -65,7 +65,7 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter /// /// Get the of the next element or if not present. /// - public Span Next + public readonly Span Next { get { @@ -138,7 +138,7 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter /// Return true if the is used and has a destination. /// /// True if the is used and has a destination. - public bool IsConfigured() + public readonly bool IsConfigured() { return IsUsed && DestinationId != Constants.UnusedMixId; } @@ -160,8 +160,8 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter /// public void ClearVolumes() { - MixBufferVolume.Fill(0); - PreviousMixBufferVolume.Fill(0); + MixBufferVolume.Clear(); + PreviousMixBufferVolume.Clear(); } /// @@ -190,4 +190,4 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterState.cs b/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterState.cs index 15a0c6ba4..e08ee9ea7 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterState.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Splitter/SplitterState.cs @@ -43,7 +43,7 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter /// /// Span to the first element of the linked list of . /// - public Span Destinations + public readonly Span Destinations { get { @@ -63,7 +63,7 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter Id = id; } - public Span GetData(int index) + public readonly Span GetData(int index) { int i = 0; @@ -95,7 +95,7 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter /// Utility function to apply a given to all . /// /// The action to execute on each elements. - private void ForEachDestination(SpanAction action) + private readonly void ForEachDestination(SpanAction action) { Span temp = Destinations; @@ -183,7 +183,7 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter /// /// Update the internal state of this instance. /// - public void UpdateInternalState() + public readonly void UpdateInternalState() { ForEachDestination((destination, _) => destination[0].UpdateInternalState()); } @@ -218,4 +218,4 @@ namespace Ryujinx.Audio.Renderer.Server.Splitter } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/StateUpdater.cs b/src/Ryujinx.Audio/Renderer/Server/StateUpdater.cs index 5cf539c6d..22eebc7cc 100644 --- a/src/Ryujinx.Audio/Renderer/Server/StateUpdater.cs +++ b/src/Ryujinx.Audio/Renderer/Server/StateUpdater.cs @@ -22,15 +22,15 @@ namespace Ryujinx.Audio.Renderer.Server public class StateUpdater { private readonly ReadOnlyMemory _inputOrigin; - private ReadOnlyMemory _outputOrigin; + private readonly ReadOnlyMemory _outputOrigin; private ReadOnlyMemory _input; private Memory _output; - private uint _processHandle; + private readonly uint _processHandle; private BehaviourContext _behaviourContext; private UpdateDataHeader _inputHeader; - private Memory _outputHeader; + private readonly Memory _outputHeader; private ref UpdateDataHeader OutputHeader => ref _outputHeader.Span[0]; @@ -45,9 +45,9 @@ namespace Ryujinx.Audio.Renderer.Server _inputHeader = SpanIOHelper.Read(ref _input); - _outputHeader = SpanMemoryManager.Cast(_output.Slice(0, Unsafe.SizeOf())); + _outputHeader = SpanMemoryManager.Cast(_output[..Unsafe.SizeOf()]); OutputHeader.Initialize(_behaviourContext.UserRevision); - _output = _output.Slice(Unsafe.SizeOf()); + _output = _output[Unsafe.SizeOf()..]; } public ResultCode UpdateBehaviourContext() @@ -72,7 +72,7 @@ namespace Ryujinx.Audio.Renderer.Server public ResultCode UpdateMemoryPools(Span memoryPools) { - PoolMapper mapper = new PoolMapper(_processHandle, _behaviourContext.IsMemoryPoolForceMappingEnabled()); + PoolMapper mapper = new(_processHandle, _behaviourContext.IsMemoryPoolForceMappingEnabled()); if (memoryPools.Length * Unsafe.SizeOf() != _inputHeader.MemoryPoolsSize) { @@ -136,11 +136,11 @@ namespace Ryujinx.Audio.Renderer.Server int initialOutputSize = _output.Length; - ReadOnlySpan parameters = MemoryMarshal.Cast(_input.Slice(0, (int)_inputHeader.VoicesSize).Span); + ReadOnlySpan parameters = MemoryMarshal.Cast(_input[..(int)_inputHeader.VoicesSize].Span); - _input = _input.Slice((int)_inputHeader.VoicesSize); + _input = _input[(int)_inputHeader.VoicesSize..]; - PoolMapper mapper = new PoolMapper(_processHandle, memoryPools, _behaviourContext.IsMemoryPoolForceMappingEnabled()); + PoolMapper mapper = new(_processHandle, memoryPools, _behaviourContext.IsMemoryPoolForceMappingEnabled()); // First make everything not in use. for (int i = 0; i < context.GetCount(); i++) @@ -151,7 +151,7 @@ namespace Ryujinx.Audio.Renderer.Server } Memory[] voiceUpdateStatesArray = ArrayPool>.Shared.Rent(Constants.VoiceChannelCountMax); - + Span> voiceUpdateStates = voiceUpdateStatesArray.AsSpan(0, Constants.VoiceChannelCountMax); // Start processing @@ -218,42 +218,20 @@ namespace Ryujinx.Audio.Renderer.Server { effect.ForceUnmapBuffers(mapper); - switch (parameter.Type) + effect = parameter.Type switch { - case EffectType.Invalid: - effect = new BaseEffect(); - break; - case EffectType.BufferMix: - effect = new BufferMixEffect(); - break; - case EffectType.AuxiliaryBuffer: - effect = new AuxiliaryBufferEffect(); - break; - case EffectType.Delay: - effect = new DelayEffect(); - break; - case EffectType.Reverb: - effect = new ReverbEffect(); - break; - case EffectType.Reverb3d: - effect = new Reverb3dEffect(); - break; - case EffectType.BiquadFilter: - effect = new BiquadFilterEffect(); - break; - case EffectType.Limiter: - effect = new LimiterEffect(); - break; - case EffectType.CaptureBuffer: - effect = new CaptureBufferEffect(); - break; - case EffectType.Compressor: - effect = new CompressorEffect(); - break; - - default: - throw new NotImplementedException($"EffectType {parameter.Type} not implemented!"); - } + EffectType.Invalid => new BaseEffect(), + EffectType.BufferMix => new BufferMixEffect(), + EffectType.AuxiliaryBuffer => new AuxiliaryBufferEffect(), + EffectType.Delay => new DelayEffect(), + EffectType.Reverb => new ReverbEffect(), + EffectType.Reverb3d => new Reverb3dEffect(), + EffectType.BiquadFilter => new BiquadFilterEffect(), + EffectType.Limiter => new LimiterEffect(), + EffectType.CaptureBuffer => new CaptureBufferEffect(), + EffectType.Compressor => new CompressorEffect(), + _ => throw new NotImplementedException($"EffectType {parameter.Type} not implemented!"), + }; } public ResultCode UpdateEffects(EffectContext context, bool isAudioRendererActive, Memory memoryPools) @@ -262,10 +240,8 @@ namespace Ryujinx.Audio.Renderer.Server { return UpdateEffectsVersion2(context, isAudioRendererActive, memoryPools); } - else - { - return UpdateEffectsVersion1(context, isAudioRendererActive, memoryPools); - } + + return UpdateEffectsVersion1(context, isAudioRendererActive, memoryPools); } public ResultCode UpdateEffectsVersion2(EffectContext context, bool isAudioRendererActive, Memory memoryPools) @@ -277,11 +253,11 @@ namespace Ryujinx.Audio.Renderer.Server int initialOutputSize = _output.Length; - ReadOnlySpan parameters = MemoryMarshal.Cast(_input.Slice(0, (int)_inputHeader.EffectsSize).Span); + ReadOnlySpan parameters = MemoryMarshal.Cast(_input[..(int)_inputHeader.EffectsSize].Span); - _input = _input.Slice((int)_inputHeader.EffectsSize); + _input = _input[(int)_inputHeader.EffectsSize..]; - PoolMapper mapper = new PoolMapper(_processHandle, memoryPools, _behaviourContext.IsMemoryPoolForceMappingEnabled()); + PoolMapper mapper = new(_processHandle, memoryPools, _behaviourContext.IsMemoryPoolForceMappingEnabled()); for (int i = 0; i < context.GetCount(); i++) { @@ -333,11 +309,11 @@ namespace Ryujinx.Audio.Renderer.Server int initialOutputSize = _output.Length; - ReadOnlySpan parameters = MemoryMarshal.Cast(_input.Slice(0, (int)_inputHeader.EffectsSize).Span); + ReadOnlySpan parameters = MemoryMarshal.Cast(_input[..(int)_inputHeader.EffectsSize].Span); - _input = _input.Slice((int)_inputHeader.EffectsSize); + _input = _input[(int)_inputHeader.EffectsSize..]; - PoolMapper mapper = new PoolMapper(_processHandle, memoryPools, _behaviourContext.IsMemoryPoolForceMappingEnabled()); + PoolMapper mapper = new(_processHandle, memoryPools, _behaviourContext.IsMemoryPoolForceMappingEnabled()); for (int i = 0; i < context.GetCount(); i++) { @@ -376,17 +352,15 @@ namespace Ryujinx.Audio.Renderer.Server { if (context.Update(_input.Span, out int consumedSize)) { - _input = _input.Slice(consumedSize); + _input = _input[consumedSize..]; return ResultCode.Success; } - else - { - return ResultCode.InvalidUpdateInfo; - } + + return ResultCode.InvalidUpdateInfo; } - private bool CheckMixParametersValidity(MixContext mixContext, uint mixBufferCount, uint inputMixCount, ReadOnlySpan parameters) + private static bool CheckMixParametersValidity(MixContext mixContext, uint mixBufferCount, uint inputMixCount, ReadOnlySpan parameters) { uint maxMixStateCount = mixContext.GetCount(); uint totalRequiredMixBufferCount = 0; @@ -439,12 +413,12 @@ namespace Ryujinx.Audio.Renderer.Server if (_behaviourContext.IsMixInParameterDirtyOnlyUpdateSupported()) { - _input = _input.Slice(Unsafe.SizeOf()); + _input = _input[Unsafe.SizeOf()..]; } - ReadOnlySpan parameters = MemoryMarshal.Cast(_input.Span.Slice(0, (int)inputMixSize)); + ReadOnlySpan parameters = MemoryMarshal.Cast(_input.Span[..(int)inputMixSize]); - _input = _input.Slice((int)inputMixSize); + _input = _input[(int)inputMixSize..]; if (CheckMixParametersValidity(mixContext, mixBufferCount, mixCount, parameters)) { @@ -506,25 +480,18 @@ namespace Ryujinx.Audio.Renderer.Server { sink.CleanUp(); - switch (parameter.Type) + sink = parameter.Type switch { - case SinkType.Invalid: - sink = new BaseSink(); - break; - case SinkType.CircularBuffer: - sink = new CircularBufferSink(); - break; - case SinkType.Device: - sink = new DeviceSink(); - break; - default: - throw new NotImplementedException($"SinkType {parameter.Type} not implemented!"); - } + SinkType.Invalid => new BaseSink(), + SinkType.CircularBuffer => new CircularBufferSink(), + SinkType.Device => new DeviceSink(), + _ => throw new NotImplementedException($"SinkType {parameter.Type} not implemented!"), + }; } public ResultCode UpdateSinks(SinkContext context, Memory memoryPools) { - PoolMapper mapper = new PoolMapper(_processHandle, memoryPools, _behaviourContext.IsMemoryPoolForceMappingEnabled()); + PoolMapper mapper = new(_processHandle, memoryPools, _behaviourContext.IsMemoryPoolForceMappingEnabled()); if (context.GetCount() * Unsafe.SizeOf() != _inputHeader.SinksSize) { @@ -533,9 +500,9 @@ namespace Ryujinx.Audio.Renderer.Server int initialOutputSize = _output.Length; - ReadOnlySpan parameters = MemoryMarshal.Cast(_input.Slice(0, (int)_inputHeader.SinksSize).Span); + ReadOnlySpan parameters = MemoryMarshal.Cast(_input[..(int)_inputHeader.SinksSize].Span); - _input = _input.Slice((int)_inputHeader.SinksSize); + _input = _input[(int)_inputHeader.SinksSize..]; for (int i = 0; i < context.GetCount(); i++) { @@ -640,4 +607,4 @@ namespace Ryujinx.Audio.Renderer.Server return ResultCode.Success; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Types/AudioRendererExecutionMode.cs b/src/Ryujinx.Audio/Renderer/Server/Types/AudioRendererExecutionMode.cs index 5d82ce0b6..0db61c5e6 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Types/AudioRendererExecutionMode.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Types/AudioRendererExecutionMode.cs @@ -14,6 +14,6 @@ namespace Ryujinx.Audio.Renderer.Server.Types /// Audio renderer operation needs to be done manually via ExecuteAudioRenderer. /// /// This is not supported on the DSP and is as such stubbed. - Manual + Manual, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Types/AudioRendererRenderingDevice.cs b/src/Ryujinx.Audio/Renderer/Server/Types/AudioRendererRenderingDevice.cs index 5ad27b0b1..fd9e231cf 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Types/AudioRendererRenderingDevice.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Types/AudioRendererRenderingDevice.cs @@ -19,6 +19,6 @@ namespace Ryujinx.Audio.Renderer.Server.Types /// /// Only supports . /// - Cpu + Cpu, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Types/PlayState.cs b/src/Ryujinx.Audio/Renderer/Server/Types/PlayState.cs index 25cc34a8f..46aae05ab 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Types/PlayState.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Types/PlayState.cs @@ -34,6 +34,6 @@ namespace Ryujinx.Audio.Renderer.Server.Types /// /// The user can resume to the state. /// - Paused + Paused, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerBufferState.cs b/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerBufferState.cs index a45fa8e5b..a3c442a45 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerBufferState.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerBufferState.cs @@ -11,4 +11,4 @@ namespace Ryujinx.Audio.Renderer.Server.Upsampler public bool Initialized; public int Phase; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerManager.cs b/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerManager.cs index 0fee00001..dbc2c9b3f 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerManager.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerManager.cs @@ -11,22 +11,22 @@ namespace Ryujinx.Audio.Renderer.Server.Upsampler /// /// Work buffer for upsampler. /// - private Memory _upSamplerWorkBuffer; + private readonly Memory _upSamplerWorkBuffer; /// /// Global lock of the object. /// - private readonly object Lock = new(); + private readonly object _lock = new(); /// /// The upsamplers instances. /// - private UpsamplerState[] _upsamplers; + private readonly UpsamplerState[] _upsamplers; /// /// The count of upsamplers. /// - private uint _count; + private readonly uint _count; /// /// Create a new . @@ -49,7 +49,7 @@ namespace Ryujinx.Audio.Renderer.Server.Upsampler { int workBufferOffset = 0; - lock (Lock) + lock (_lock) { for (int i = 0; i < _count; i++) { @@ -73,7 +73,7 @@ namespace Ryujinx.Audio.Renderer.Server.Upsampler /// The index of the to free. public void Free(int index) { - lock (Lock) + lock (_lock) { Debug.Assert(_upsamplers[index] != null); @@ -81,4 +81,4 @@ namespace Ryujinx.Audio.Renderer.Server.Upsampler } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerState.cs b/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerState.cs index e508f35b4..39a58c91a 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerState.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Upsampler/UpsamplerState.cs @@ -20,12 +20,12 @@ namespace Ryujinx.Audio.Renderer.Server.Upsampler /// /// The index of the . (used to free it) /// - private int _index; + private readonly int _index; /// /// The . /// - private UpsamplerManager _manager; + private readonly UpsamplerManager _manager; /// /// The source sample count. @@ -65,4 +65,4 @@ namespace Ryujinx.Audio.Renderer.Server.Upsampler _manager.Free(_index); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceChannelResource.cs b/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceChannelResource.cs index 939d92944..e3d5f797d 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceChannelResource.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceChannelResource.cs @@ -37,4 +37,4 @@ namespace Ryujinx.Audio.Renderer.Server.Voice Mix.AsSpan().CopyTo(PreviousMix.AsSpan()); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceContext.cs b/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceContext.cs index 1c57b71be..7ce7143ed 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceContext.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceContext.cs @@ -126,7 +126,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice _sortedVoices.Span[i] = i; } - int[] sortedVoicesTemp = _sortedVoices.Slice(0, (int)GetCount()).ToArray(); + int[] sortedVoicesTemp = _sortedVoices[..(int)GetCount()].ToArray(); Array.Sort(sortedVoicesTemp, (a, b) => { @@ -146,4 +146,4 @@ namespace Ryujinx.Audio.Renderer.Server.Voice sortedVoicesTemp.AsSpan().CopyTo(_sortedVoices.Span); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceState.cs b/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceState.cs index 0bf53c544..225f7d31b 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceState.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Voice/VoiceState.cs @@ -1,5 +1,6 @@ using Ryujinx.Audio.Common; using Ryujinx.Audio.Renderer.Common; +using Ryujinx.Audio.Renderer.Dsp.State; using Ryujinx.Audio.Renderer.Parameter; using Ryujinx.Audio.Renderer.Server.MemoryPool; using Ryujinx.Common.Memory; @@ -9,6 +10,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using static Ryujinx.Audio.Renderer.Common.BehaviourParameter; using static Ryujinx.Audio.Renderer.Parameter.VoiceInParameter; +using PlayState = Ryujinx.Audio.Renderer.Server.Types.PlayState; namespace Ryujinx.Audio.Renderer.Server.Voice { @@ -65,12 +67,12 @@ namespace Ryujinx.Audio.Renderer.Server.Voice /// /// The current voice . /// - public Types.PlayState PlayState; + public PlayState PlayState; /// /// The previous voice . /// - public Types.PlayState PreviousPlayState; + public PlayState PreviousPlayState; /// /// The priority of the voice. @@ -192,7 +194,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice DataSourceStateUnmapped = false; BufferInfoUnmapped = false; FlushWaveBufferCount = 0; - PlayState = Types.PlayState.Stopped; + PlayState = PlayState.Stopped; Priority = Constants.VoiceLowestPriority; Id = 0; NodeId = 0; @@ -202,7 +204,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice Pitch = 0.0f; Volume = 0.0f; PreviousVolume = 0.0f; - BiquadFilters.AsSpan().Fill(new BiquadFilterParameter()); + BiquadFilters.AsSpan().Clear(); WaveBuffersCount = 0; WaveBuffersIndex = 0; MixId = Constants.UnusedMixId; @@ -233,7 +235,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice /// Check if the voice needs to be skipped. /// /// Returns true if the voice needs to be skipped. - public bool ShouldSkip() + public readonly bool ShouldSkip() { return !InUse || WaveBuffersCount == 0 || DataSourceStateUnmapped || BufferInfoUnmapped || VoiceDropFlag; } @@ -242,7 +244,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice /// Return true if the mix has any destinations. /// /// True if the mix has any destinations. - public bool HasAnyDestination() + public readonly bool HasAnyDestination() { return MixId != Constants.UnusedMixId || SplitterId != Constants.UnusedSplitterId; } @@ -252,7 +254,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice /// /// The user parameter. /// Return true, if the server voice information needs to be updated. - private bool ShouldUpdateParameters(ref VoiceInParameter parameter) + private readonly bool ShouldUpdateParameters(ref VoiceInParameter parameter) { if (DataSourceStateAddressInfo.CpuAddress == parameter.DataSourceStateAddress) { @@ -338,31 +340,31 @@ namespace Ryujinx.Audio.Renderer.Server.Voice /// Update the internal play state from user play state. /// /// The target user play state. - public void UpdatePlayState(PlayState userPlayState) + public void UpdatePlayState(Common.PlayState userPlayState) { - Types.PlayState oldServerPlayState = PlayState; + PlayState oldServerPlayState = PlayState; PreviousPlayState = oldServerPlayState; - Types.PlayState newServerPlayState; + PlayState newServerPlayState; switch (userPlayState) { case Common.PlayState.Start: - newServerPlayState = Types.PlayState.Started; + newServerPlayState = PlayState.Started; break; case Common.PlayState.Stop: - if (oldServerPlayState == Types.PlayState.Stopped) + if (oldServerPlayState == PlayState.Stopped) { return; } - newServerPlayState = Types.PlayState.Stopping; + newServerPlayState = PlayState.Stopping; break; case Common.PlayState.Pause: - newServerPlayState = Types.PlayState.Paused; + newServerPlayState = PlayState.Paused; break; default: @@ -434,7 +436,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice for (int i = 0; i < parameter.ChannelCount; i++) { - voiceUpdateStates[i].Span[0].IsWaveBufferValid.Fill(false); + voiceUpdateStates[i].Span[0].IsWaveBufferValid.Clear(); } } @@ -530,7 +532,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice Memory dspSharedState = context.GetUpdateStateForDsp(channelResourceId); - MemoryMarshal.Cast(dspSharedState.Span).Fill(0); + MemoryMarshal.Cast(dspSharedState.Span).Clear(); voiceChannelResource.UpdateState(); } @@ -579,7 +581,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice switch (PlayState) { - case Types.PlayState.Started: + case PlayState.Started: for (int i = 0; i < WaveBuffers.Length; i++) { ref WaveBuffer wavebuffer = ref WaveBuffers[i]; @@ -611,7 +613,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice return false; - case Types.PlayState.Stopping: + case PlayState.Stopping: for (int i = 0; i < WaveBuffers.Length; i++) { ref WaveBuffer wavebuffer = ref WaveBuffers[i]; @@ -638,18 +640,18 @@ namespace Ryujinx.Audio.Renderer.Server.Voice voiceUpdateState.Offset = 0; voiceUpdateState.PlayedSampleCount = 0; - voiceUpdateState.Pitch.AsSpan().Fill(0); + voiceUpdateState.Pitch.AsSpan().Clear(); voiceUpdateState.Fraction = 0; - voiceUpdateState.LoopContext = new Dsp.State.AdpcmLoopContext(); + voiceUpdateState.LoopContext = new AdpcmLoopContext(); } - PlayState = Types.PlayState.Stopped; - WasPlaying = PreviousPlayState == Types.PlayState.Started; + PlayState = PlayState.Stopped; + WasPlaying = PreviousPlayState == PlayState.Started; return WasPlaying; - case Types.PlayState.Stopped: - case Types.PlayState.Paused: + case PlayState.Stopped: + case PlayState.Paused: foreach (ref WaveBuffer wavebuffer in WaveBuffers.AsSpan()) { wavebuffer.BufferAddressInfo.GetReference(true); @@ -664,7 +666,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice } } - WasPlaying = PreviousPlayState == Types.PlayState.Started; + WasPlaying = PreviousPlayState == PlayState.Started; return WasPlaying; default: @@ -696,4 +698,4 @@ namespace Ryujinx.Audio.Renderer.Server.Voice return UpdateParametersForCommandGeneration(voiceUpdateStates); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Server/Voice/WaveBuffer.cs b/src/Ryujinx.Audio/Renderer/Server/Voice/WaveBuffer.cs index 4bf7dd280..a9946ba44 100644 --- a/src/Ryujinx.Audio/Renderer/Server/Voice/WaveBuffer.cs +++ b/src/Ryujinx.Audio/Renderer/Server/Voice/WaveBuffer.cs @@ -71,10 +71,11 @@ namespace Ryujinx.Audio.Renderer.Server.Voice /// A new for use by the . public Common.WaveBuffer ToCommon(int version) { - Common.WaveBuffer waveBuffer = new Common.WaveBuffer(); - - waveBuffer.Buffer = BufferAddressInfo.GetReference(true); - waveBuffer.BufferSize = (uint)BufferAddressInfo.Size; + Common.WaveBuffer waveBuffer = new() + { + Buffer = BufferAddressInfo.GetReference(true), + BufferSize = (uint)BufferAddressInfo.Size, + }; if (ContextAddressInfo.CpuAddress != 0) { @@ -101,4 +102,4 @@ namespace Ryujinx.Audio.Renderer.Server.Voice return waveBuffer; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Utils/AudioProcessorMemoryManager.cs b/src/Ryujinx.Audio/Renderer/Utils/AudioProcessorMemoryManager.cs index 973f0672a..8ebf20340 100644 --- a/src/Ryujinx.Audio/Renderer/Utils/AudioProcessorMemoryManager.cs +++ b/src/Ryujinx.Audio/Renderer/Utils/AudioProcessorMemoryManager.cs @@ -54,4 +54,4 @@ namespace Ryujinx.Audio.Renderer.Utils { } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Utils/BitArray.cs b/src/Ryujinx.Audio/Renderer/Utils/BitArray.cs index 8b1054771..8fd0baeae 100644 --- a/src/Ryujinx.Audio/Renderer/Utils/BitArray.cs +++ b/src/Ryujinx.Audio/Renderer/Utils/BitArray.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Audio.Renderer.Utils /// /// The backing storage of the . /// - private Memory _storage; + private readonly Memory _storage; /// /// Create a new from . @@ -97,7 +97,7 @@ namespace Ryujinx.Audio.Renderer.Utils [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Reset() { - _storage.Span.Fill(0); + _storage.Span.Clear(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Utils/FileHardwareDevice.cs b/src/Ryujinx.Audio/Renderer/Utils/FileHardwareDevice.cs index d49313ea1..bc2313ccf 100644 --- a/src/Ryujinx.Audio/Renderer/Utils/FileHardwareDevice.cs +++ b/src/Ryujinx.Audio/Renderer/Utils/FileHardwareDevice.cs @@ -2,7 +2,6 @@ using Ryujinx.Audio.Integration; using System; using System.IO; using System.Runtime.InteropServices; -using System.Text; namespace Ryujinx.Audio.Renderer.Utils { @@ -12,8 +11,8 @@ namespace Ryujinx.Audio.Renderer.Utils public class FileHardwareDevice : IHardwareDevice { private FileStream _stream; - private uint _channelCount; - private uint _sampleRate; + private readonly uint _channelCount; + private readonly uint _sampleRate; private const int HeaderSize = 44; @@ -82,6 +81,7 @@ namespace Ryujinx.Audio.Renderer.Utils public void Dispose() { + GC.SuppressFinalize(this); Dispose(true); } @@ -96,4 +96,4 @@ namespace Ryujinx.Audio.Renderer.Utils } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Utils/Mailbox.cs b/src/Ryujinx.Audio/Renderer/Utils/Mailbox.cs index 35c71ae36..26907af91 100644 --- a/src/Ryujinx.Audio/Renderer/Utils/Mailbox.cs +++ b/src/Ryujinx.Audio/Renderer/Utils/Mailbox.cs @@ -9,8 +9,8 @@ namespace Ryujinx.Audio.Renderer.Utils /// The target unmanaged type used public class Mailbox : IDisposable where T : unmanaged { - private BlockingCollection _messageQueue; - private BlockingCollection _responseQueue; + private readonly BlockingCollection _messageQueue; + private readonly BlockingCollection _responseQueue; public Mailbox() { @@ -40,6 +40,7 @@ namespace Ryujinx.Audio.Renderer.Utils public void Dispose() { + GC.SuppressFinalize(this); Dispose(true); } @@ -52,4 +53,4 @@ namespace Ryujinx.Audio.Renderer.Utils } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Utils/Math/Matrix2x2.cs b/src/Ryujinx.Audio/Renderer/Utils/Math/Matrix2x2.cs index 5b513aff3..7a6edab19 100644 --- a/src/Ryujinx.Audio/Renderer/Utils/Math/Matrix2x2.cs +++ b/src/Ryujinx.Audio/Renderer/Utils/Math/Matrix2x2.cs @@ -68,4 +68,4 @@ namespace Ryujinx.Audio.Renderer.Utils.Math return m; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Utils/Math/Matrix6x6.cs b/src/Ryujinx.Audio/Renderer/Utils/Math/Matrix6x6.cs index 415a81fdf..ff0123026 100644 --- a/src/Ryujinx.Audio/Renderer/Utils/Math/Matrix6x6.cs +++ b/src/Ryujinx.Audio/Renderer/Utils/Math/Matrix6x6.cs @@ -94,4 +94,4 @@ namespace Ryujinx.Audio.Renderer.Utils.Math M66 = m66; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Utils/Math/MatrixHelper.cs b/src/Ryujinx.Audio/Renderer/Utils/Math/MatrixHelper.cs index 209a81c46..7b4b7ad1d 100644 --- a/src/Ryujinx.Audio/Renderer/Utils/Math/MatrixHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Utils/Math/MatrixHelper.cs @@ -28,7 +28,7 @@ namespace Ryujinx.Audio.Renderer.Dsp X = value2.M11 * value1.X + value2.M12 * value1.Y + value2.M13 * value1.Z + value2.M14 * value1.W, Y = value2.M21 * value1.X + value2.M22 * value1.Y + value2.M23 * value1.Z + value2.M24 * value1.W, Z = value2.M31 * value1.X + value2.M32 * value1.Y + value2.M33 * value1.Z + value2.M34 * value1.W, - W = value2.M41 * value1.X + value2.M42 * value1.Y + value2.M43 * value1.Z + value2.M44 * value1.W + W = value2.M41 * value1.X + value2.M42 * value1.Y + value2.M43 * value1.Z + value2.M44 * value1.W, }; } @@ -42,4 +42,4 @@ namespace Ryujinx.Audio.Renderer.Dsp }; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Utils/Math/Vector6.cs b/src/Ryujinx.Audio/Renderer/Utils/Math/Vector6.cs index 81bcb6982..303c5e9d0 100644 --- a/src/Ryujinx.Audio/Renderer/Utils/Math/Vector6.cs +++ b/src/Ryujinx.Audio/Renderer/Utils/Math/Vector6.cs @@ -53,4 +53,4 @@ namespace Ryujinx.Audio.Renderer.Utils.Math return left * new Vector6(right); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Utils/SpanIOHelper.cs b/src/Ryujinx.Audio/Renderer/Utils/SpanIOHelper.cs index 103fb6a04..4771ae4dd 100644 --- a/src/Ryujinx.Audio/Renderer/Utils/SpanIOHelper.cs +++ b/src/Ryujinx.Audio/Renderer/Utils/SpanIOHelper.cs @@ -22,12 +22,12 @@ namespace Ryujinx.Audio.Renderer.Utils if (size > backingMemory.Length) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(backingMemory), backingMemory.Length, null); } - MemoryMarshal.Write(backingMemory.Span.Slice(0, size), ref data); + MemoryMarshal.Write(backingMemory.Span[..size], ref data); - backingMemory = backingMemory.Slice(size); + backingMemory = backingMemory[size..]; } /// @@ -42,12 +42,12 @@ namespace Ryujinx.Audio.Renderer.Utils if (size > backingMemory.Length) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(backingMemory), backingMemory.Length, null); } - MemoryMarshal.Write(backingMemory.Slice(0, size), ref data); + MemoryMarshal.Write(backingMemory[..size], ref data); - backingMemory = backingMemory.Slice(size); + backingMemory = backingMemory[size..]; } /// @@ -62,12 +62,12 @@ namespace Ryujinx.Audio.Renderer.Utils if (size > backingMemory.Length) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(backingMemory), backingMemory.Length, null); } - Span result = MemoryMarshal.Cast(backingMemory.Span.Slice(0, size)); + Span result = MemoryMarshal.Cast(backingMemory.Span[..size]); - backingMemory = backingMemory.Slice(size); + backingMemory = backingMemory[size..]; return result; } @@ -84,12 +84,12 @@ namespace Ryujinx.Audio.Renderer.Utils if (size > backingMemory.Length) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(backingMemory), backingMemory.Length, null); } - Span result = MemoryMarshal.Cast(backingMemory.Slice(0, size)); + Span result = MemoryMarshal.Cast(backingMemory[..size]); - backingMemory = backingMemory.Slice(size); + backingMemory = backingMemory[size..]; return result; } @@ -106,12 +106,12 @@ namespace Ryujinx.Audio.Renderer.Utils if (size > backingMemory.Length) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(backingMemory), backingMemory.Length, null); } - T result = MemoryMarshal.Read(backingMemory.Span.Slice(0, size)); + T result = MemoryMarshal.Read(backingMemory.Span[..size]); - backingMemory = backingMemory.Slice(size); + backingMemory = backingMemory[size..]; return result; } @@ -128,12 +128,12 @@ namespace Ryujinx.Audio.Renderer.Utils if (size > backingMemory.Length) { - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(nameof(backingMemory), backingMemory.Length, null); } - T result = MemoryMarshal.Read(backingMemory.Slice(0, size)); + T result = MemoryMarshal.Read(backingMemory[..size]); - backingMemory = backingMemory.Slice(size); + backingMemory = backingMemory[size..]; return result; } @@ -168,4 +168,4 @@ namespace Ryujinx.Audio.Renderer.Utils return ref GetMemory(memory, id, count).Span[0]; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Utils/SpanMemoryManager.cs b/src/Ryujinx.Audio/Renderer/Utils/SpanMemoryManager.cs index 2c48da6aa..b6bafbe0f 100644 --- a/src/Ryujinx.Audio/Renderer/Utils/SpanMemoryManager.cs +++ b/src/Ryujinx.Audio/Renderer/Utils/SpanMemoryManager.cs @@ -19,7 +19,7 @@ namespace Ryujinx.Audio.Renderer.Utils } } - public override Span GetSpan() => new Span(_pointer, _length); + public override Span GetSpan() => new(_pointer, _length); public override MemoryHandle Pin(int elementIndex = 0) { @@ -40,4 +40,4 @@ namespace Ryujinx.Audio.Renderer.Utils return new SpanMemoryManager(MemoryMarshal.Cast(memory.Span)).Memory; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/Renderer/Utils/SplitterHardwareDevice.cs b/src/Ryujinx.Audio/Renderer/Utils/SplitterHardwareDevice.cs index 183960789..32d50e12f 100644 --- a/src/Ryujinx.Audio/Renderer/Utils/SplitterHardwareDevice.cs +++ b/src/Ryujinx.Audio/Renderer/Utils/SplitterHardwareDevice.cs @@ -5,8 +5,8 @@ namespace Ryujinx.Audio.Renderer.Utils { public class SplitterHardwareDevice : IHardwareDevice { - private IHardwareDevice _baseDevice; - private IHardwareDevice _secondaryDevice; + private readonly IHardwareDevice _baseDevice; + private readonly IHardwareDevice _secondaryDevice; public SplitterHardwareDevice(IHardwareDevice baseDevice, IHardwareDevice secondaryDevice) { @@ -43,6 +43,7 @@ namespace Ryujinx.Audio.Renderer.Utils public void Dispose() { + GC.SuppressFinalize(this); Dispose(true); } @@ -55,4 +56,4 @@ namespace Ryujinx.Audio.Renderer.Utils } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio/ResultCode.cs b/src/Ryujinx.Audio/ResultCode.cs index 1d05ac65e..eab27c16d 100644 --- a/src/Ryujinx.Audio/ResultCode.cs +++ b/src/Ryujinx.Audio/ResultCode.cs @@ -19,4 +19,4 @@ namespace Ryujinx.Audio UnsupportedOperation = (513 << ErrorCodeShift) | ModuleId, InvalidExecutionContextOperation = (514 << ErrorCodeShift) | ModuleId, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManager.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManager.cs index 2d342206b..36b0ed282 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioInManager.cs @@ -1,7 +1,6 @@ using Ryujinx.Audio.Common; using Ryujinx.Audio.Input; using Ryujinx.HLE.HOS.Services.Audio.AudioIn; - using AudioInManagerImpl = Ryujinx.Audio.Input.AudioInputManager; namespace Ryujinx.HLE.HOS.Services.Audio diff --git a/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManager.cs b/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManager.cs index 7b2891963..e95de0575 100644 --- a/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManager.cs +++ b/src/Ryujinx.HLE/HOS/Services/Audio/AudioOutManager.cs @@ -1,7 +1,6 @@ using Ryujinx.Audio.Common; using Ryujinx.Audio.Output; using Ryujinx.HLE.HOS.Services.Audio.AudioOut; - using AudioOutManagerImpl = Ryujinx.Audio.Output.AudioOutputManager; namespace Ryujinx.HLE.HOS.Services.Audio