aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoDeviceContext.cs
blob: 42bcc6e3bcea82b3a24850dfd308433e6e9cf9ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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);
        }
    }
}