SoundIoDeviceContext.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Runtime.InteropServices;
  4. using static Ryujinx.Audio.Backends.SoundIo.Native.SoundIo;
  5. namespace Ryujinx.Audio.Backends.SoundIo.Native
  6. {
  7. public class SoundIoDeviceContext
  8. {
  9. private readonly IntPtr _context;
  10. public IntPtr Context => _context;
  11. internal SoundIoDeviceContext(IntPtr context)
  12. {
  13. _context = context;
  14. }
  15. private ref SoundIoDevice GetDeviceContext()
  16. {
  17. unsafe
  18. {
  19. return ref Unsafe.AsRef<SoundIoDevice>((SoundIoDevice*)_context);
  20. }
  21. }
  22. public bool IsRaw => GetDeviceContext().IsRaw;
  23. public string Id => Marshal.PtrToStringAnsi(GetDeviceContext().Id);
  24. public bool SupportsSampleRate(int sampleRate) => soundio_device_supports_sample_rate(_context, sampleRate);
  25. public bool SupportsFormat(SoundIoFormat format) => soundio_device_supports_format(_context, format);
  26. public bool SupportsChannelCount(int channelCount) => soundio_device_supports_layout(_context, SoundIoChannelLayout.GetDefault(channelCount));
  27. public SoundIoOutStreamContext CreateOutStream()
  28. {
  29. IntPtr context = soundio_outstream_create(_context);
  30. if (context == IntPtr.Zero)
  31. {
  32. return null;
  33. }
  34. return new SoundIoOutStreamContext(context);
  35. }
  36. }
  37. }