SoundIoDeviceContext.cs 1.4 KB

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