SoundIo.cs
1 using Ryujinx.Common.Memory; 2 using System; 3 using System.Runtime.CompilerServices; 4 using System.Runtime.InteropServices; 5 6 namespace Ryujinx.Audio.Backends.SoundIo.Native 7 { 8 public static partial class SoundIo 9 { 10 private const string LibraryName = "libsoundio"; 11 12 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 13 public delegate void OnDeviceChangeNativeDelegate(IntPtr ctx); 14 15 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 16 public delegate void OnBackendDisconnectedDelegate(IntPtr ctx, SoundIoError err); 17 18 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 19 public delegate void OnEventsSignalDelegate(IntPtr ctx); 20 21 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 22 public delegate void EmitRtPrioWarningDelegate(); 23 24 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 25 public delegate void JackCallbackDelegate(IntPtr msg); 26 27 [StructLayout(LayoutKind.Sequential)] 28 public struct SoundIoStruct 29 { 30 public IntPtr UserData; 31 public IntPtr OnDeviceChange; 32 public IntPtr OnBackendDisconnected; 33 public IntPtr OnEventsSignal; 34 public SoundIoBackend CurrentBackend; 35 public IntPtr ApplicationName; 36 public IntPtr EmitRtPrioWarning; 37 public IntPtr JackInfoCallback; 38 public IntPtr JackErrorCallback; 39 } 40 41 public struct SoundIoChannelLayout 42 { 43 public IntPtr Name; 44 public int ChannelCount; 45 public Array24<SoundIoChannelId> Channels; 46 47 public static IntPtr GetDefault(int channelCount) 48 { 49 return soundio_channel_layout_get_default(channelCount); 50 } 51 52 public static unsafe SoundIoChannelLayout GetDefaultValue(int channelCount) 53 { 54 return Unsafe.AsRef<SoundIoChannelLayout>((SoundIoChannelLayout*)GetDefault(channelCount)); 55 } 56 } 57 58 public struct SoundIoSampleRateRange 59 { 60 public int Min; 61 public int Max; 62 } 63 64 public struct SoundIoDevice 65 { 66 public IntPtr SoundIo; 67 public IntPtr Id; 68 public IntPtr Name; 69 public SoundIoDeviceAim Aim; 70 public IntPtr Layouts; 71 public int LayoutCount; 72 public SoundIoChannelLayout CurrentLayout; 73 public IntPtr Formats; 74 public int FormatCount; 75 public SoundIoFormat CurrentFormat; 76 public IntPtr SampleRates; 77 public int SampleRateCount; 78 public int SampleRateCurrent; 79 public double SoftwareLatencyMin; 80 public double SoftwareLatencyMax; 81 public double SoftwareLatencyCurrent; 82 public bool IsRaw; 83 public int RefCount; 84 public SoundIoError ProbeError; 85 } 86 87 public struct SoundIoOutStream 88 { 89 public IntPtr Device; 90 public SoundIoFormat Format; 91 public int SampleRate; 92 public SoundIoChannelLayout Layout; 93 public double SoftwareLatency; 94 public float Volume; 95 public IntPtr UserData; 96 public IntPtr WriteCallback; 97 public IntPtr UnderflowCallback; 98 public IntPtr ErrorCallback; 99 public IntPtr Name; 100 public bool NonTerminalHint; 101 public int BytesPerFrame; 102 public int BytesPerSample; 103 public SoundIoError LayoutError; 104 } 105 106 public struct SoundIoChannelArea 107 { 108 public IntPtr Pointer; 109 public int Step; 110 } 111 112 [LibraryImport(LibraryName)] 113 internal static partial IntPtr soundio_create(); 114 115 [LibraryImport(LibraryName)] 116 internal static partial SoundIoError soundio_connect(IntPtr ctx); 117 118 [LibraryImport(LibraryName)] 119 internal static partial void soundio_disconnect(IntPtr ctx); 120 121 [LibraryImport(LibraryName)] 122 internal static partial void soundio_flush_events(IntPtr ctx); 123 124 [LibraryImport(LibraryName)] 125 internal static partial int soundio_output_device_count(IntPtr ctx); 126 127 [LibraryImport(LibraryName)] 128 internal static partial int soundio_default_output_device_index(IntPtr ctx); 129 130 [LibraryImport(LibraryName)] 131 internal static partial IntPtr soundio_get_output_device(IntPtr ctx, int index); 132 133 [LibraryImport(LibraryName)] 134 [return: MarshalAs(UnmanagedType.Bool)] 135 internal static partial bool soundio_device_supports_format(IntPtr devCtx, SoundIoFormat format); 136 137 [LibraryImport(LibraryName)] 138 [return: MarshalAs(UnmanagedType.Bool)] 139 internal static partial bool soundio_device_supports_layout(IntPtr devCtx, IntPtr layout); 140 141 [LibraryImport(LibraryName)] 142 [return: MarshalAs(UnmanagedType.Bool)] 143 internal static partial bool soundio_device_supports_sample_rate(IntPtr devCtx, int sampleRate); 144 145 [LibraryImport(LibraryName)] 146 internal static partial IntPtr soundio_outstream_create(IntPtr devCtx); 147 148 [LibraryImport(LibraryName)] 149 internal static partial SoundIoError soundio_outstream_open(IntPtr outStreamCtx); 150 151 [LibraryImport(LibraryName)] 152 internal static partial SoundIoError soundio_outstream_start(IntPtr outStreamCtx); 153 154 [LibraryImport(LibraryName)] 155 internal static partial SoundIoError soundio_outstream_begin_write(IntPtr outStreamCtx, IntPtr areas, IntPtr frameCount); 156 157 [LibraryImport(LibraryName)] 158 internal static partial SoundIoError soundio_outstream_end_write(IntPtr outStreamCtx); 159 160 [LibraryImport(LibraryName)] 161 internal static partial SoundIoError soundio_outstream_pause(IntPtr devCtx, [MarshalAs(UnmanagedType.Bool)] bool pause); 162 163 [LibraryImport(LibraryName)] 164 internal static partial SoundIoError soundio_outstream_set_volume(IntPtr devCtx, double volume); 165 166 [LibraryImport(LibraryName)] 167 internal static partial void soundio_outstream_destroy(IntPtr streamCtx); 168 169 [LibraryImport(LibraryName)] 170 internal static partial void soundio_destroy(IntPtr ctx); 171 172 [LibraryImport(LibraryName)] 173 internal static partial IntPtr soundio_channel_layout_get_default(int channelCount); 174 175 [LibraryImport(LibraryName)] 176 internal static partial IntPtr soundio_strerror(SoundIoError err); 177 } 178 }