From 82074eb19121fb96c82454a2a63e8e3bedff5137 Mon Sep 17 00:00:00 2001 From: GreemDev Date: Tue, 27 Jan 2026 17:34:51 -0600 Subject: [PATCH] audio backend projects code cleanup --- .../AppleHardwareDeviceDriver.cs | 66 +++++++------------ .../AppleHardwareDeviceSession.cs | 2 +- .../Native/AudioToolbox.cs | 5 +- .../OpenALHardwareDeviceDriver.cs | 5 +- .../OpenALHardwareDeviceSession.cs | 5 +- .../SDL3HardwareDeviceDriver.cs | 4 +- .../SDL3HardwareDeviceSession.cs | 7 +- .../SoundIoHardwareDeviceDriver.cs | 4 +- .../SoundIoHardwareDeviceSession.cs | 4 +- 9 files changed, 42 insertions(+), 60 deletions(-) diff --git a/src/Ryujinx.Audio.Backends.Apple/AppleHardwareDeviceDriver.cs b/src/Ryujinx.Audio.Backends.Apple/AppleHardwareDeviceDriver.cs index 2c659f6a0..80e55b9e5 100644 --- a/src/Ryujinx.Audio.Backends.Apple/AppleHardwareDeviceDriver.cs +++ b/src/Ryujinx.Audio.Backends.Apple/AppleHardwareDeviceDriver.cs @@ -15,7 +15,7 @@ namespace Ryujinx.Audio.Backends.Apple { [SupportedOSPlatform("macos")] [SupportedOSPlatform("ios")] - public class AppleHardwareDeviceDriver : IHardwareDeviceDriver + public sealed class AppleHardwareDeviceDriver : IHardwareDeviceDriver { private readonly ManualResetEvent _updateRequiredEvent; private readonly ManualResetEvent _pauseEvent; @@ -38,9 +38,10 @@ namespace Ryujinx.Audio.Backends.Apple private bool TestSurroundSupport() { try - { - var format = GetAudioFormat(SampleFormat.PcmFloat, Constants.TargetSampleRate, 6); - + { + AudioStreamBasicDescription format = + GetAudioFormat(SampleFormat.PcmFloat, Constants.TargetSampleRate, 6); + int result = AudioQueueNewOutput( ref format, IntPtr.Zero, @@ -60,9 +61,9 @@ namespace Ryujinx.Audio.Backends.Apple }; int layoutResult = AudioQueueSetProperty( - testQueue, - kAudioQueueProperty_ChannelLayout, - ref layout, + testQueue, + kAudioQueueProperty_ChannelLayout, + ref layout, (uint)Marshal.SizeOf()); if (layoutResult == 0) @@ -70,7 +71,7 @@ namespace Ryujinx.Audio.Backends.Apple AudioQueueDispose(testQueue, true); return true; } - + AudioQueueDispose(testQueue, true); } @@ -90,7 +91,8 @@ namespace Ryujinx.Audio.Backends.Apple try { - var format = GetAudioFormat(SampleFormat.PcmInt16, Constants.TargetSampleRate, 2); + AudioStreamBasicDescription format = + GetAudioFormat(SampleFormat.PcmInt16, Constants.TargetSampleRate, 2); int result = AudioQueueNewOutput( ref format, IntPtr.Zero, @@ -115,16 +117,13 @@ namespace Ryujinx.Audio.Backends.Apple } public ManualResetEvent GetUpdateRequiredEvent() - { - return _updateRequiredEvent; - } + => _updateRequiredEvent; public ManualResetEvent GetPauseEvent() - { - return _pauseEvent; - } + => _pauseEvent; - public IHardwareDeviceSession OpenDeviceSession(Direction direction, IVirtualMemoryManager memoryManager, SampleFormat sampleFormat, uint sampleRate, uint channelCount) + public IHardwareDeviceSession OpenDeviceSession(Direction direction, IVirtualMemoryManager memoryManager, + SampleFormat sampleFormat, uint sampleRate, uint channelCount) { if (channelCount == 0) { @@ -149,11 +148,10 @@ namespace Ryujinx.Audio.Backends.Apple } internal bool Unregister(AppleHardwareDeviceSession session) - { - return _sessions.TryRemove(session, out _); - } + => _sessions.TryRemove(session, out _); - internal static AudioStreamBasicDescription GetAudioFormat(SampleFormat sampleFormat, uint sampleRate, uint channelCount) + internal static AudioStreamBasicDescription GetAudioFormat(SampleFormat sampleFormat, uint sampleRate, + uint channelCount) { uint formatFlags; uint bitsPerChannel; @@ -202,7 +200,7 @@ namespace Ryujinx.Audio.Backends.Apple Dispose(true); } - protected virtual void Dispose(bool disposing) + private void Dispose(bool disposing) { if (disposing) { @@ -215,29 +213,15 @@ namespace Ryujinx.Audio.Backends.Apple } } - public bool SupportsSampleRate(uint sampleRate) - { - return true; - } + public bool SupportsDirection(Direction direction) + => direction != Direction.Input; + + public bool SupportsSampleRate(uint sampleRate) => true; public bool SupportsSampleFormat(SampleFormat sampleFormat) - { - return sampleFormat != SampleFormat.PcmInt24; - } + => sampleFormat != SampleFormat.PcmInt24; public bool SupportsChannelCount(uint channelCount) - { - if (channelCount == 6) - { - return _supportSurroundConfiguration; - } - - return true; - } - - public bool SupportsDirection(Direction direction) - { - return direction != Direction.Input; - } + => channelCount != 6 || _supportSurroundConfiguration; } } diff --git a/src/Ryujinx.Audio.Backends.Apple/AppleHardwareDeviceSession.cs b/src/Ryujinx.Audio.Backends.Apple/AppleHardwareDeviceSession.cs index 08aefe4a5..c9443dcd3 100644 --- a/src/Ryujinx.Audio.Backends.Apple/AppleHardwareDeviceSession.cs +++ b/src/Ryujinx.Audio.Backends.Apple/AppleHardwareDeviceSession.cs @@ -67,7 +67,7 @@ namespace Ryujinx.Audio.Backends.Apple { lock (_lock) { - var format = AppleHardwareDeviceDriver.GetAudioFormat( + AudioStreamBasicDescription format = AppleHardwareDeviceDriver.GetAudioFormat( RequestedSampleFormat, RequestedSampleRate, RequestedChannelCount); diff --git a/src/Ryujinx.Audio.Backends.Apple/Native/AudioToolbox.cs b/src/Ryujinx.Audio.Backends.Apple/Native/AudioToolbox.cs index 9a6e8e189..ea2a7867a 100644 --- a/src/Ryujinx.Audio.Backends.Apple/Native/AudioToolbox.cs +++ b/src/Ryujinx.Audio.Backends.Apple/Native/AudioToolbox.cs @@ -1,6 +1,5 @@ -using Ryujinx.Common.Memory; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +// ReSharper disable InconsistentNaming namespace Ryujinx.Audio.Backends.Apple.Native { @@ -100,4 +99,4 @@ namespace Ryujinx.Audio.Backends.Apple.Native internal const uint kAudioQueueParam_Volume = 1; } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs b/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs index 8be6197f6..911b131ed 100644 --- a/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs +++ b/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs @@ -10,7 +10,8 @@ using static Ryujinx.Audio.Integration.IHardwareDeviceDriver; namespace Ryujinx.Audio.Backends.OpenAL { - public class OpenALHardwareDeviceDriver : IHardwareDeviceDriver + // ReSharper disable once InconsistentNaming + public sealed class OpenALHardwareDeviceDriver : IHardwareDeviceDriver { private readonly ALDevice _device; private readonly ALContext _context; @@ -148,7 +149,7 @@ namespace Ryujinx.Audio.Backends.OpenAL Dispose(true); } - protected virtual void Dispose(bool disposing) + private void Dispose(bool disposing) { if (disposing) { diff --git a/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs b/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs index 7292450a6..61fb4a369 100644 --- a/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs +++ b/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs @@ -9,7 +9,8 @@ using System.Threading; namespace Ryujinx.Audio.Backends.OpenAL { - class OpenALHardwareDeviceSession : HardwareDeviceSessionOutputBase + // ReSharper disable once InconsistentNaming + sealed class OpenALHardwareDeviceSession : HardwareDeviceSessionOutputBase { private readonly OpenALHardwareDeviceDriver _driver; private readonly int _sourceId; @@ -190,7 +191,7 @@ namespace Ryujinx.Audio.Backends.OpenAL } } - protected virtual void Dispose(bool disposing) + private void Dispose(bool disposing) { if (disposing && _driver.Unregister(this)) { diff --git a/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceDriver.cs b/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceDriver.cs index bdc9f02f4..598de8835 100644 --- a/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceDriver.cs +++ b/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceDriver.cs @@ -17,7 +17,7 @@ namespace Ryujinx.Audio.Backends.SDL3 using unsafe SDL_AudioStreamCallbackPointer = delegate* unmanaged[Cdecl]; - public class SDL3HardwareDeviceDriver : IHardwareDeviceDriver + public sealed class SDL3HardwareDeviceDriver : IHardwareDeviceDriver { private readonly ManualResetEvent _updateRequiredEvent; private readonly ManualResetEvent _pauseEvent; @@ -162,7 +162,7 @@ namespace Ryujinx.Audio.Backends.SDL3 Dispose(true); } - protected virtual void Dispose(bool disposing) + private void Dispose(bool disposing) { if (disposing) { diff --git a/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs b/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs index 377d86d2b..ca7b131dd 100644 --- a/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs +++ b/src/Ryujinx.Audio.Backends.SDL3/SDL3HardwareDeviceSession.cs @@ -12,10 +12,7 @@ using System.Runtime.InteropServices; namespace Ryujinx.Audio.Backends.SDL3 { - - - - unsafe class SDL3HardwareDeviceSession : HardwareDeviceSessionOutputBase + sealed unsafe class SDL3HardwareDeviceSession : HardwareDeviceSessionOutputBase { private readonly SDL3HardwareDeviceDriver _driver; private readonly ConcurrentQueue _queuedBuffers; @@ -226,7 +223,7 @@ namespace Ryujinx.Audio.Backends.SDL3 return driverBuffer.DriverIdentifier != buffer.DataPointer; } - protected virtual void Dispose(bool disposing) + private void Dispose(bool disposing) { if (disposing && _driver.Unregister(this)) { diff --git a/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceDriver.cs b/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceDriver.cs index e3e5d2913..1aed0744c 100644 --- a/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceDriver.cs +++ b/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceDriver.cs @@ -10,7 +10,7 @@ using static Ryujinx.Audio.Integration.IHardwareDeviceDriver; namespace Ryujinx.Audio.Backends.SoundIo { - public class SoundIoHardwareDeviceDriver : IHardwareDeviceDriver + public sealed class SoundIoHardwareDeviceDriver : IHardwareDeviceDriver { private readonly SoundIoContext _audioContext; private readonly SoundIoDeviceContext _audioDevice; @@ -227,7 +227,7 @@ namespace Ryujinx.Audio.Backends.SoundIo } } - protected virtual void Dispose(bool disposing) + private void Dispose(bool disposing) { if (disposing) { diff --git a/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs b/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs index 1540cd0e3..39ceac08a 100644 --- a/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs +++ b/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs @@ -11,7 +11,7 @@ using static Ryujinx.Audio.Backends.SoundIo.Native.SoundIo; namespace Ryujinx.Audio.Backends.SoundIo { - class SoundIoHardwareDeviceSession : HardwareDeviceSessionOutputBase + sealed class SoundIoHardwareDeviceSession : HardwareDeviceSessionOutputBase { private readonly SoundIoHardwareDeviceDriver _driver; private readonly ConcurrentQueue _queuedBuffers; @@ -428,7 +428,7 @@ namespace Ryujinx.Audio.Backends.SoundIo } } - protected virtual void Dispose(bool disposing) + private void Dispose(bool disposing) { if (disposing && _driver.Unregister(this)) {