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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
using Ryujinx.Audio.Common;
using Ryujinx.Audio.Input;
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Sf;
using Ryujinx.Horizon.Sdk.Sf.Hipc;
using System;
namespace Ryujinx.Horizon.Sdk.Audio.Detail
{
partial class AudioIn : IAudioIn, IDisposable
{
private readonly AudioInputSystem _impl;
private int _processHandle;
public AudioIn(AudioInputSystem impl, int processHandle)
{
_impl = impl;
_processHandle = processHandle;
}
[CmifCommand(0)]
public Result GetAudioInState(out AudioDeviceState state)
{
state = _impl.GetState();
return Result.Success;
}
[CmifCommand(1)]
public Result Start()
{
return new Result((int)_impl.Start());
}
[CmifCommand(2)]
public Result Stop()
{
return new Result((int)_impl.Stop());
}
[CmifCommand(3)]
public Result AppendAudioInBuffer(ulong bufferTag, [Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySpan<AudioUserBuffer> buffer)
{
AudioUserBuffer userBuffer = default;
if (buffer.Length > 0)
{
userBuffer = buffer[0];
}
return new Result((int)_impl.AppendBuffer(bufferTag, ref userBuffer));
}
[CmifCommand(4)]
public Result RegisterBufferEvent([CopyHandle] out int eventHandle)
{
eventHandle = 0;
if (_impl.RegisterBufferEvent() is AudioEvent audioEvent)
{
eventHandle = audioEvent.GetReadableHandle();
}
return Result.Success;
}
[CmifCommand(5)]
public Result GetReleasedAudioInBuffers(out uint count, [Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span<ulong> bufferTags)
{
return new Result((int)_impl.GetReleasedBuffers(bufferTags, out count));
}
[CmifCommand(6)]
public Result ContainsAudioInBuffer(out bool contains, ulong bufferTag)
{
contains = _impl.ContainsBuffer(bufferTag);
return Result.Success;
}
[CmifCommand(7)] // 3.0.0+
public Result AppendUacInBuffer(
ulong bufferTag,
[Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias)] ReadOnlySpan<AudioUserBuffer> buffer,
[CopyHandle] int eventHandle)
{
AudioUserBuffer userBuffer = default;
if (buffer.Length > 0)
{
userBuffer = buffer[0];
}
return new Result((int)_impl.AppendUacBuffer(bufferTag, ref userBuffer, (uint)eventHandle));
}
[CmifCommand(8)] // 3.0.0+
public Result AppendAudioInBufferAuto(ulong bufferTag, [Buffer(HipcBufferFlags.In | HipcBufferFlags.AutoSelect)] ReadOnlySpan<AudioUserBuffer> buffer)
{
return AppendAudioInBuffer(bufferTag, buffer);
}
[CmifCommand(9)] // 3.0.0+
public Result GetReleasedAudioInBuffersAuto(out uint count, [Buffer(HipcBufferFlags.Out | HipcBufferFlags.AutoSelect)] Span<ulong> bufferTags)
{
return GetReleasedAudioInBuffers(out count, bufferTags);
}
[CmifCommand(10)] // 3.0.0+
public Result AppendUacInBufferAuto(
ulong bufferTag,
[Buffer(HipcBufferFlags.In | HipcBufferFlags.AutoSelect)] ReadOnlySpan<AudioUserBuffer> buffer,
[CopyHandle] int eventHandle)
{
return AppendUacInBuffer(bufferTag, buffer, eventHandle);
}
[CmifCommand(11)] // 4.0.0+
public Result GetAudioInBufferCount(out uint bufferCount)
{
bufferCount = _impl.GetBufferCount();
return Result.Success;
}
[CmifCommand(12)] // 4.0.0+
public Result SetDeviceGain(float gain)
{
_impl.SetVolume(gain);
return Result.Success;
}
[CmifCommand(13)] // 4.0.0+
public Result GetDeviceGain(out float gain)
{
gain = _impl.GetVolume();
return Result.Success;
}
[CmifCommand(14)] // 6.0.0+
public Result FlushAudioInBuffers(out bool pending)
{
pending = _impl.FlushBuffers();
return Result.Success;
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_impl.Dispose();
if (_processHandle != 0)
{
HorizonStatic.Syscall.CloseHandle(_processHandle);
_processHandle = 0;
}
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
|