diff options
| author | Mary-nyan <mary@mary.zone> | 2022-12-11 00:57:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-11 00:57:01 +0100 |
| commit | 403e67d9835b7412022ff4d98685f83590641c88 (patch) | |
| tree | 5d86f83be23c065edfa92329570cf37d64c1f4d6 /Ryujinx.Audio.Backends.SoundIo/Native/SoundIoDeviceContext.cs | |
| parent | c6f1908e0f07b6dd4b60cbe333a9b5f1adec276b (diff) | |
audio: Rewrite SoundIo bindings (#4088)
* audio: Rewrite SoundIo bindings
This rewrite SoundIo bindings to be safer and not a pedantic autogenerated mess.
* Address comments
* Switch DllImport to LibraryImport
* Address gdkchan's comment
Diffstat (limited to 'Ryujinx.Audio.Backends.SoundIo/Native/SoundIoDeviceContext.cs')
| -rw-r--r-- | Ryujinx.Audio.Backends.SoundIo/Native/SoundIoDeviceContext.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoDeviceContext.cs b/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoDeviceContext.cs new file mode 100644 index 00000000..42bcc6e3 --- /dev/null +++ b/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoDeviceContext.cs @@ -0,0 +1,49 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using static Ryujinx.Audio.Backends.SoundIo.Native.SoundIo; + +namespace Ryujinx.Audio.Backends.SoundIo.Native +{ + public class SoundIoDeviceContext + { + private readonly IntPtr _context; + + public IntPtr Context => _context; + + internal SoundIoDeviceContext(IntPtr context) + { + _context = context; + } + + private ref SoundIoDevice GetDeviceContext() + { + unsafe + { + return ref Unsafe.AsRef<SoundIoDevice>((SoundIoDevice*)_context); + } + } + + public bool IsRaw => GetDeviceContext().IsRaw; + + public string Id => Marshal.PtrToStringAnsi(GetDeviceContext().Id); + + public bool SupportsSampleRate(int sampleRate) => soundio_device_supports_sample_rate(_context, sampleRate); + + public bool SupportsFormat(SoundIoFormat format) => soundio_device_supports_format(_context, format); + + public bool SupportsChannelCount(int channelCount) => soundio_device_supports_layout(_context, SoundIoChannelLayout.GetDefault(channelCount)); + + public SoundIoOutStreamContext CreateOutStream() + { + IntPtr context = soundio_outstream_create(_context); + + if (context == IntPtr.Zero) + { + return null; + } + + return new SoundIoOutStreamContext(context); + } + } +} |
