Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f6ada8d169 | ||
|
42d31f646d |
@@ -19,12 +19,14 @@ namespace Ryujinx.Audio.Backends.SDL2
|
|||||||
private readonly ManualResetEvent _pauseEvent;
|
private readonly ManualResetEvent _pauseEvent;
|
||||||
private readonly ConcurrentDictionary<SDL2HardwareDeviceSession, byte> _sessions;
|
private readonly ConcurrentDictionary<SDL2HardwareDeviceSession, byte> _sessions;
|
||||||
|
|
||||||
private bool _supportSurroundConfiguration;
|
private readonly bool _supportSurroundConfiguration;
|
||||||
|
|
||||||
// TODO: Add this to SDL2-CS
|
// TODO: Add this to SDL2-CS
|
||||||
// NOTE: We use a DllImport here because of marshaling issue for spec.
|
// NOTE: We use a DllImport here because of marshaling issue for spec.
|
||||||
|
#pragma warning disable SYSLIB1054
|
||||||
[DllImport("SDL2")]
|
[DllImport("SDL2")]
|
||||||
private static extern int SDL_GetDefaultAudioInfo(IntPtr name, out SDL_AudioSpec spec, int isCapture);
|
private static extern int SDL_GetDefaultAudioInfo(IntPtr name, out SDL_AudioSpec spec, int isCapture);
|
||||||
|
#pragma warning restore SYSLIB1054
|
||||||
|
|
||||||
public SDL2HardwareDeviceDriver()
|
public SDL2HardwareDeviceDriver()
|
||||||
{
|
{
|
||||||
@@ -90,7 +92,7 @@ namespace Ryujinx.Audio.Backends.SDL2
|
|||||||
throw new NotImplementedException("Input direction is currently not implemented on SDL2 backend!");
|
throw new NotImplementedException("Input direction is currently not implemented on SDL2 backend!");
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL2HardwareDeviceSession session = new SDL2HardwareDeviceSession(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
|
SDL2HardwareDeviceSession session = new(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
|
||||||
|
|
||||||
_sessions.TryAdd(session, 0);
|
_sessions.TryAdd(session, 0);
|
||||||
|
|
||||||
@@ -135,8 +137,7 @@ namespace Ryujinx.Audio.Backends.SDL2
|
|||||||
|
|
||||||
if (device == 0)
|
if (device == 0)
|
||||||
{
|
{
|
||||||
Logger.Error?.Print(LogClass.Application,
|
Logger.Error?.Print(LogClass.Application, $"SDL2 open audio device initialization failed with error \"{SDL_GetError()}\"");
|
||||||
$"SDL2 open audio device initialization failed with error \"{SDL_GetError()}\"");
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -156,6 +157,7 @@ namespace Ryujinx.Audio.Backends.SDL2
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,19 +12,19 @@ namespace Ryujinx.Audio.Backends.SDL2
|
|||||||
{
|
{
|
||||||
class SDL2HardwareDeviceSession : HardwareDeviceSessionOutputBase
|
class SDL2HardwareDeviceSession : HardwareDeviceSessionOutputBase
|
||||||
{
|
{
|
||||||
private SDL2HardwareDeviceDriver _driver;
|
private readonly SDL2HardwareDeviceDriver _driver;
|
||||||
private ConcurrentQueue<SDL2AudioBuffer> _queuedBuffers;
|
private readonly ConcurrentQueue<SDL2AudioBuffer> _queuedBuffers;
|
||||||
private DynamicRingBuffer _ringBuffer;
|
private readonly DynamicRingBuffer _ringBuffer;
|
||||||
private ulong _playedSampleCount;
|
private ulong _playedSampleCount;
|
||||||
private ManualResetEvent _updateRequiredEvent;
|
private readonly ManualResetEvent _updateRequiredEvent;
|
||||||
private uint _outputStream;
|
private uint _outputStream;
|
||||||
private bool _hasSetupError;
|
private bool _hasSetupError;
|
||||||
private SDL_AudioCallback _callbackDelegate;
|
private readonly SDL_AudioCallback _callbackDelegate;
|
||||||
private int _bytesPerFrame;
|
private readonly int _bytesPerFrame;
|
||||||
private uint _sampleCount;
|
private uint _sampleCount;
|
||||||
private bool _started;
|
private bool _started;
|
||||||
private float _volume;
|
private float _volume;
|
||||||
private ushort _nativeSampleFormat;
|
private readonly ushort _nativeSampleFormat;
|
||||||
|
|
||||||
public SDL2HardwareDeviceSession(SDL2HardwareDeviceDriver driver, IVirtualMemoryManager memoryManager, SampleFormat requestedSampleFormat, uint requestedSampleRate, uint requestedChannelCount, float requestedVolume) : base(memoryManager, requestedSampleFormat, requestedSampleRate, requestedChannelCount)
|
public SDL2HardwareDeviceSession(SDL2HardwareDeviceDriver driver, IVirtualMemoryManager memoryManager, SampleFormat requestedSampleFormat, uint requestedSampleRate, uint requestedChannelCount, float requestedVolume) : base(memoryManager, requestedSampleFormat, requestedSampleRate, requestedChannelCount)
|
||||||
{
|
{
|
||||||
@@ -72,7 +72,7 @@ namespace Ryujinx.Audio.Backends.SDL2
|
|||||||
|
|
||||||
private unsafe void Update(IntPtr userdata, IntPtr stream, int streamLength)
|
private unsafe void Update(IntPtr userdata, IntPtr stream, int streamLength)
|
||||||
{
|
{
|
||||||
Span<byte> streamSpan = new Span<byte>((void*)stream, streamLength);
|
Span<byte> streamSpan = new((void*)stream, streamLength);
|
||||||
|
|
||||||
int maxFrameCount = (int)GetSampleCount(streamLength);
|
int maxFrameCount = (int)GetSampleCount(streamLength);
|
||||||
int bufferedFrames = _ringBuffer.Length / _bytesPerFrame;
|
int bufferedFrames = _ringBuffer.Length / _bytesPerFrame;
|
||||||
@@ -82,7 +82,7 @@ namespace Ryujinx.Audio.Backends.SDL2
|
|||||||
if (frameCount == 0)
|
if (frameCount == 0)
|
||||||
{
|
{
|
||||||
// SDL2 left the responsibility to the user to clear the buffer.
|
// SDL2 left the responsibility to the user to clear the buffer.
|
||||||
streamSpan.Fill(0);
|
streamSpan.Clear();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ namespace Ryujinx.Audio.Backends.SDL2
|
|||||||
IntPtr pStreamSrc = (IntPtr)p;
|
IntPtr pStreamSrc = (IntPtr)p;
|
||||||
|
|
||||||
// Zero the dest buffer
|
// Zero the dest buffer
|
||||||
streamSpan.Fill(0);
|
streamSpan.Clear();
|
||||||
|
|
||||||
// Apply volume to written data
|
// Apply volume to written data
|
||||||
SDL_MixAudioFormat(stream, pStreamSrc, _nativeSampleFormat, (uint)samples.Length, (int)(_volume * SDL_MIX_MAXVOLUME));
|
SDL_MixAudioFormat(stream, pStreamSrc, _nativeSampleFormat, (uint)samples.Length, (int)(_volume * SDL_MIX_MAXVOLUME));
|
||||||
@@ -151,7 +151,7 @@ namespace Ryujinx.Audio.Backends.SDL2
|
|||||||
|
|
||||||
if (_outputStream != 0)
|
if (_outputStream != 0)
|
||||||
{
|
{
|
||||||
SDL2AudioBuffer driverBuffer = new SDL2AudioBuffer(buffer.DataPointer, GetSampleCount(buffer));
|
SDL2AudioBuffer driverBuffer = new(buffer.DataPointer, GetSampleCount(buffer));
|
||||||
|
|
||||||
_ringBuffer.Write(buffer.Data, 0, buffer.Data.Length);
|
_ringBuffer.Write(buffer.Data, 0, buffer.Data.Length);
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@ namespace Ryujinx.Graphics.Device
|
|||||||
|
|
||||||
public TState State;
|
public TState State;
|
||||||
|
|
||||||
private uint Size => (uint)(Unsafe.SizeOf<TState>() + RegisterSize - 1) / RegisterSize;
|
private static uint Size => (uint)(Unsafe.SizeOf<TState>() + RegisterSize - 1) / RegisterSize;
|
||||||
|
|
||||||
private readonly Func<int>[] _readCallbacks;
|
private readonly Func<int>[] _readCallbacks;
|
||||||
private readonly Action<int>[] _writeCallbacks;
|
private readonly Action<int>[] _writeCallbacks;
|
||||||
|
Reference in New Issue
Block a user