SoundIo.cs 6.4 KB

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