Compare commits

..

3 Commits

Author SHA1 Message Date
TSRBerry
7c2f07d124 [Ryujinx.Horizon.Common] Address dotnet-format issues (#5382)
* dotnet format style --severity info

Some changes were manually reverted.

* Address most dotnet format whitespace warnings

* Address IDE0251 warnings

* dotnet format whitespace after rebase
2023-06-25 13:40:37 +02:00
TSRBerry
ede5b3c324 [Ryujinx.Audio.Backends.SoundIo] Address dotnet-format issues (#5360)
* dotnet format style --severity info

Some changes were manually reverted.

* Address dotnet format CA1816 warnings

* Address dotnet format CA1401 warnings

* Address most dotnet format whitespace warnings

* Run dotnet format after rebase and remove unused usings

- analyzers
- style
- whitespace

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* Address review feedback
2023-06-25 02:15:56 +02:00
TSRBerry
df5be5812f [Ryujinx.Audio.Backends.OpenAL] Address dotnet-format issues (#5359)
* dotnet format style --severity info

Some changes were manually reverted.

* Restore a few unused methods and variables

* Address dotnet format CA1816 warnings

* Address most dotnet format whitespace warnings

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase
2023-06-25 01:29:40 +02:00
10 changed files with 98 additions and 102 deletions

View File

@@ -18,7 +18,7 @@ namespace Ryujinx.Audio.Backends.OpenAL
private readonly ManualResetEvent _pauseEvent;
private readonly ConcurrentDictionary<OpenALHardwareDeviceSession, byte> _sessions;
private bool _stillRunning;
private Thread _updaterThread;
private readonly Thread _updaterThread;
public OpenALHardwareDeviceDriver()
{
@@ -73,7 +73,7 @@ namespace Ryujinx.Audio.Backends.OpenAL
throw new ArgumentException($"{channelCount}");
}
OpenALHardwareDeviceSession session = new OpenALHardwareDeviceSession(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
OpenALHardwareDeviceSession session = new(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
_sessions.TryAdd(session, 0);
@@ -123,6 +123,7 @@ namespace Ryujinx.Audio.Backends.OpenAL
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}

View File

@@ -10,11 +10,11 @@ namespace Ryujinx.Audio.Backends.OpenAL
{
class OpenALHardwareDeviceSession : HardwareDeviceSessionOutputBase
{
private OpenALHardwareDeviceDriver _driver;
private int _sourceId;
private ALFormat _targetFormat;
private readonly OpenALHardwareDeviceDriver _driver;
private readonly int _sourceId;
private readonly ALFormat _targetFormat;
private bool _isActive;
private Queue<OpenALAudioBuffer> _queuedBuffers;
private readonly Queue<OpenALAudioBuffer> _queuedBuffers;
private ulong _playedSampleCount;
private readonly object _lock = new();
@@ -32,23 +32,17 @@ namespace Ryujinx.Audio.Backends.OpenAL
private ALFormat GetALFormat()
{
switch (RequestedSampleFormat)
return RequestedSampleFormat switch
{
case SampleFormat.PcmInt16:
switch (RequestedChannelCount)
{
case 1:
return ALFormat.Mono16;
case 2:
return ALFormat.Stereo16;
case 6:
return ALFormat.Multi51Chn16Ext;
default:
throw new NotImplementedException($"Unsupported channel config {RequestedChannelCount}");
}
default:
throw new NotImplementedException($"Unsupported sample format {RequestedSampleFormat}");
}
SampleFormat.PcmInt16 => RequestedChannelCount switch
{
1 => ALFormat.Mono16,
2 => ALFormat.Stereo16,
6 => ALFormat.Multi51Chn16Ext,
_ => throw new NotImplementedException($"Unsupported channel config {RequestedChannelCount}"),
},
_ => throw new NotImplementedException($"Unsupported sample format {RequestedSampleFormat}"),
};
}
public override void PrepareToClose() { }
@@ -69,7 +63,7 @@ namespace Ryujinx.Audio.Backends.OpenAL
{
lock (_lock)
{
OpenALAudioBuffer driverBuffer = new OpenALAudioBuffer
OpenALAudioBuffer driverBuffer = new()
{
DriverIdentifier = buffer.DataPointer,
BufferId = AL.GenBuffer(),

View File

@@ -10,19 +10,19 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native
private const string LibraryName = "libsoundio";
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void OnDeviceChangeNativeDelegate(IntPtr ctx);
public delegate void OnDeviceChangeNativeDelegate(IntPtr ctx);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void OnBackendDisconnectedDelegate(IntPtr ctx, SoundIoError err);
public delegate void OnBackendDisconnectedDelegate(IntPtr ctx, SoundIoError err);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void OnEventsSignalDelegate(IntPtr ctx);
public delegate void OnEventsSignalDelegate(IntPtr ctx);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void EmitRtPrioWarningDelegate();
public delegate void EmitRtPrioWarningDelegate();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void JackCallbackDelegate(IntPtr msg);
public delegate void JackCallbackDelegate(IntPtr msg);
[StructLayout(LayoutKind.Sequential)]
public struct SoundIoStruct
@@ -110,69 +110,69 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native
}
[LibraryImport(LibraryName)]
public static partial IntPtr soundio_create();
internal static partial IntPtr soundio_create();
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_connect(IntPtr ctx);
internal static partial SoundIoError soundio_connect(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial void soundio_disconnect(IntPtr ctx);
internal static partial void soundio_disconnect(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial void soundio_flush_events(IntPtr ctx);
internal static partial void soundio_flush_events(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial int soundio_output_device_count(IntPtr ctx);
internal static partial int soundio_output_device_count(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial int soundio_default_output_device_index(IntPtr ctx);
internal static partial int soundio_default_output_device_index(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial IntPtr soundio_get_output_device(IntPtr ctx, int index);
internal static partial IntPtr soundio_get_output_device(IntPtr ctx, int index);
[LibraryImport(LibraryName)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool soundio_device_supports_format(IntPtr devCtx, SoundIoFormat format);
internal static partial bool soundio_device_supports_format(IntPtr devCtx, SoundIoFormat format);
[LibraryImport(LibraryName)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool soundio_device_supports_layout(IntPtr devCtx, IntPtr layout);
internal static partial bool soundio_device_supports_layout(IntPtr devCtx, IntPtr layout);
[LibraryImport(LibraryName)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool soundio_device_supports_sample_rate(IntPtr devCtx, int sampleRate);
internal static partial bool soundio_device_supports_sample_rate(IntPtr devCtx, int sampleRate);
[LibraryImport(LibraryName)]
public static partial IntPtr soundio_outstream_create(IntPtr devCtx);
internal static partial IntPtr soundio_outstream_create(IntPtr devCtx);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_open(IntPtr outStreamCtx);
internal static partial SoundIoError soundio_outstream_open(IntPtr outStreamCtx);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_start(IntPtr outStreamCtx);
internal static partial SoundIoError soundio_outstream_start(IntPtr outStreamCtx);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_begin_write(IntPtr outStreamCtx, IntPtr areas, IntPtr frameCount);
internal static partial SoundIoError soundio_outstream_begin_write(IntPtr outStreamCtx, IntPtr areas, IntPtr frameCount);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_end_write(IntPtr outStreamCtx);
internal static partial SoundIoError soundio_outstream_end_write(IntPtr outStreamCtx);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_pause(IntPtr devCtx, [MarshalAs(UnmanagedType.Bool)] bool pause);
internal static partial SoundIoError soundio_outstream_pause(IntPtr devCtx, [MarshalAs(UnmanagedType.Bool)] bool pause);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_set_volume(IntPtr devCtx, double volume);
internal static partial SoundIoError soundio_outstream_set_volume(IntPtr devCtx, double volume);
[LibraryImport(LibraryName)]
public static partial void soundio_outstream_destroy(IntPtr streamCtx);
internal static partial void soundio_outstream_destroy(IntPtr streamCtx);
[LibraryImport(LibraryName)]
public static partial void soundio_destroy(IntPtr ctx);
internal static partial void soundio_destroy(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial IntPtr soundio_channel_layout_get_default(int channelCount);
internal static partial IntPtr soundio_channel_layout_get_default(int channelCount);
[LibraryImport(LibraryName)]
public static partial IntPtr soundio_strerror(SoundIoError err);
internal static partial IntPtr soundio_strerror(SoundIoError err);
}
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;

View File

@@ -141,7 +141,7 @@ namespace Ryujinx.Audio.Backends.SoundIo
throw new NotImplementedException("Input direction is currently not implemented on SoundIO backend!");
}
SoundIoHardwareDeviceSession session = new SoundIoHardwareDeviceSession(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
SoundIoHardwareDeviceSession session = new(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
_sessions.TryAdd(session, 0);
@@ -162,7 +162,7 @@ namespace Ryujinx.Audio.Backends.SoundIo
SampleFormat.PcmInt24 => SoundIoFormat.S24LE,
SampleFormat.PcmInt32 => SoundIoFormat.S32LE,
SampleFormat.PcmFloat => SoundIoFormat.Float32LE,
_ => throw new ArgumentException ($"Unsupported sample format {format}"),
_ => throw new ArgumentException($"Unsupported sample format {format}"),
};
}
@@ -202,6 +202,8 @@ namespace Ryujinx.Audio.Backends.SoundIo
public void Dispose()
{
GC.SuppressFinalize(this);
if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0)
{
Dispose(true);

View File

@@ -12,12 +12,12 @@ namespace Ryujinx.Audio.Backends.SoundIo
{
class SoundIoHardwareDeviceSession : HardwareDeviceSessionOutputBase
{
private SoundIoHardwareDeviceDriver _driver;
private ConcurrentQueue<SoundIoAudioBuffer> _queuedBuffers;
private readonly SoundIoHardwareDeviceDriver _driver;
private readonly ConcurrentQueue<SoundIoAudioBuffer> _queuedBuffers;
private SoundIoOutStreamContext _outputStream;
private DynamicRingBuffer _ringBuffer;
private readonly DynamicRingBuffer _ringBuffer;
private ulong _playedSampleCount;
private ManualResetEvent _updateRequiredEvent;
private readonly ManualResetEvent _updateRequiredEvent;
private int _disposeState;
public SoundIoHardwareDeviceSession(SoundIoHardwareDeviceDriver driver, IVirtualMemoryManager memoryManager, SampleFormat requestedSampleFormat, uint requestedSampleRate, uint requestedChannelCount, float requestedVolume) : base(memoryManager, requestedSampleFormat, requestedSampleRate, requestedChannelCount)
@@ -54,7 +54,7 @@ namespace Ryujinx.Audio.Backends.SoundIo
public override void QueueBuffer(AudioBuffer buffer)
{
SoundIoAudioBuffer driverBuffer = new SoundIoAudioBuffer(buffer.DataPointer, GetSampleCount(buffer));
SoundIoAudioBuffer driverBuffer = new(buffer.DataPointer, GetSampleCount(buffer));
_ringBuffer.Write(buffer.Data, 0, buffer.Data.Length);
@@ -81,7 +81,7 @@ namespace Ryujinx.Audio.Backends.SoundIo
_driver.FlushContextEvents();
}
public override void UnregisterBuffer(AudioBuffer buffer) {}
public override void UnregisterBuffer(AudioBuffer buffer) { }
public override bool WasBufferFullyConsumed(AudioBuffer buffer)
{

View File

@@ -4,36 +4,36 @@
{
private const int ModuleId = 1;
public static Result SessionCountExceeded => new Result(ModuleId, 7);
public static Result InvalidCapability => new Result(ModuleId, 14);
public static Result ThreadNotStarted => new Result(ModuleId, 57);
public static Result ThreadTerminating => new Result(ModuleId, 59);
public static Result InvalidSize => new Result(ModuleId, 101);
public static Result InvalidAddress => new Result(ModuleId, 102);
public static Result OutOfResource => new Result(ModuleId, 103);
public static Result OutOfMemory => new Result(ModuleId, 104);
public static Result HandleTableFull => new Result(ModuleId, 105);
public static Result InvalidMemState => new Result(ModuleId, 106);
public static Result InvalidPermission => new Result(ModuleId, 108);
public static Result InvalidMemRange => new Result(ModuleId, 110);
public static Result InvalidPriority => new Result(ModuleId, 112);
public static Result InvalidCpuCore => new Result(ModuleId, 113);
public static Result InvalidHandle => new Result(ModuleId, 114);
public static Result UserCopyFailed => new Result(ModuleId, 115);
public static Result InvalidCombination => new Result(ModuleId, 116);
public static Result TimedOut => new Result(ModuleId, 117);
public static Result Cancelled => new Result(ModuleId, 118);
public static Result MaximumExceeded => new Result(ModuleId, 119);
public static Result InvalidEnumValue => new Result(ModuleId, 120);
public static Result NotFound => new Result(ModuleId, 121);
public static Result InvalidThread => new Result(ModuleId, 122);
public static Result PortRemoteClosed => new Result(ModuleId, 123);
public static Result InvalidState => new Result(ModuleId, 125);
public static Result ReservedValue => new Result(ModuleId, 126);
public static Result PortClosed => new Result(ModuleId, 131);
public static Result ResLimitExceeded => new Result(ModuleId, 132);
public static Result ReceiveListBroken => new Result(ModuleId, 258);
public static Result OutOfVaSpace => new Result(ModuleId, 259);
public static Result CmdBufferTooSmall => new Result(ModuleId, 260);
public static Result SessionCountExceeded => new(ModuleId, 7);
public static Result InvalidCapability => new(ModuleId, 14);
public static Result ThreadNotStarted => new(ModuleId, 57);
public static Result ThreadTerminating => new(ModuleId, 59);
public static Result InvalidSize => new(ModuleId, 101);
public static Result InvalidAddress => new(ModuleId, 102);
public static Result OutOfResource => new(ModuleId, 103);
public static Result OutOfMemory => new(ModuleId, 104);
public static Result HandleTableFull => new(ModuleId, 105);
public static Result InvalidMemState => new(ModuleId, 106);
public static Result InvalidPermission => new(ModuleId, 108);
public static Result InvalidMemRange => new(ModuleId, 110);
public static Result InvalidPriority => new(ModuleId, 112);
public static Result InvalidCpuCore => new(ModuleId, 113);
public static Result InvalidHandle => new(ModuleId, 114);
public static Result UserCopyFailed => new(ModuleId, 115);
public static Result InvalidCombination => new(ModuleId, 116);
public static Result TimedOut => new(ModuleId, 117);
public static Result Cancelled => new(ModuleId, 118);
public static Result MaximumExceeded => new(ModuleId, 119);
public static Result InvalidEnumValue => new(ModuleId, 120);
public static Result NotFound => new(ModuleId, 121);
public static Result InvalidThread => new(ModuleId, 122);
public static Result PortRemoteClosed => new(ModuleId, 123);
public static Result InvalidState => new(ModuleId, 125);
public static Result ReservedValue => new(ModuleId, 126);
public static Result PortClosed => new(ModuleId, 131);
public static Result ResLimitExceeded => new(ModuleId, 132);
public static Result ReceiveListBroken => new(ModuleId, 258);
public static Result OutOfVaSpace => new(ModuleId, 259);
public static Result CmdBufferTooSmall => new(ModuleId, 260);
}
}

View File

@@ -2,7 +2,7 @@
namespace Ryujinx.Horizon.Common
{
public struct OnScopeExit : IDisposable
public readonly struct OnScopeExit : IDisposable
{
private readonly Action _action;

View File

@@ -13,13 +13,13 @@ namespace Ryujinx.Horizon.Common
public int ErrorCode { get; }
public bool IsSuccess => ErrorCode == 0;
public bool IsFailure => ErrorCode != 0;
public readonly bool IsSuccess => ErrorCode == 0;
public readonly bool IsFailure => ErrorCode != 0;
public int Module => ErrorCode & (ModuleMax - 1);
public int Description => (ErrorCode >> ModuleBits) & (DescriptionMax - 1);
public readonly int Module => ErrorCode & (ModuleMax - 1);
public readonly int Description => (ErrorCode >> ModuleBits) & (DescriptionMax - 1);
public string PrintableResult => $"{2000 + Module:D4}-{Description:D4}";
public readonly string PrintableResult => $"{2000 + Module:D4}-{Description:D4}";
public Result(int module, int description)
{
@@ -36,17 +36,17 @@ namespace Ryujinx.Horizon.Common
ErrorCode = module | (description << ModuleBits);
}
public override bool Equals(object obj)
public readonly override bool Equals(object obj)
{
return obj is Result result && result.Equals(this);
}
public bool Equals(Result other)
public readonly bool Equals(Result other)
{
return other.ErrorCode == ErrorCode;
}
public override int GetHashCode()
public readonly override int GetHashCode()
{
return ErrorCode;
}
@@ -61,7 +61,7 @@ namespace Ryujinx.Horizon.Common
return !lhs.Equals(rhs);
}
public bool InRange(int minInclusive, int maxInclusive)
public readonly bool InRange(int minInclusive, int maxInclusive)
{
return (uint)(Description - minInclusive) <= (uint)(maxInclusive - minInclusive);
}
@@ -105,7 +105,7 @@ namespace Ryujinx.Horizon.Common
throw new InvalidResultException(this);
}
public override string ToString()
public readonly override string ToString()
{
if (ResultNames.TryGet(ErrorCode, out string name))
{
@@ -115,4 +115,4 @@ namespace Ryujinx.Horizon.Common
return PrintableResult;
}
}
}
}

View File

@@ -1698,4 +1698,4 @@ namespace Ryujinx.Horizon.Common
return _names.TryGetValue(errorCode, out name);
}
}
}
}