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
|
using Ryujinx.Audio;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager;
namespace Ryujinx.HLE.HOS.Services.Audio
{
[Service("audren:u")]
class IAudioRendererManager : IpcService
{
public IAudioRendererManager(ServiceCtx context) { }
[Command(0)]
// OpenAudioRenderer(nn::audio::detail::AudioRendererParameterInternal, u64, nn::applet::AppletResourceUserId, pid, handle<copy>, handle<copy>)
// -> object<nn::audio::detail::IAudioRenderer>
public ResultCode OpenAudioRenderer(ServiceCtx context)
{
IAalOutput audioOut = context.Device.AudioOut;
AudioRendererParameter Params = GetAudioRendererParameter(context);
MakeObject(context, new IAudioRenderer(
context.Device.System,
context.Memory,
audioOut,
Params));
return ResultCode.Success;
}
[Command(1)]
// GetWorkBufferSize(nn::audio::detail::AudioRendererParameterInternal) -> u64
public ResultCode GetAudioRendererWorkBufferSize(ServiceCtx context)
{
AudioRendererParameter parameters = GetAudioRendererParameter(context);
if (AudioRendererCommon.CheckValidRevision(parameters))
{
BehaviorInfo behaviorInfo = new BehaviorInfo();
behaviorInfo.SetUserLibRevision(parameters.Revision);
long size;
int totalMixCount = parameters.SubMixCount + 1;
size = BitUtils.AlignUp(parameters.MixBufferCount * 4, AudioRendererConsts.BufferAlignment) +
parameters.SubMixCount * 0x400 +
totalMixCount * 0x940 +
parameters.VoiceCount * 0x3F0 +
BitUtils.AlignUp(totalMixCount * 8, 16) +
BitUtils.AlignUp(parameters.VoiceCount * 8, 16) +
BitUtils.AlignUp(((parameters.SinkCount + parameters.SubMixCount) * 0x3C0 + parameters.SampleCount * 4) *
(parameters.MixBufferCount + 6), AudioRendererConsts.BufferAlignment) +
(parameters.SinkCount + parameters.SubMixCount) * 0x2C0 +
(parameters.EffectCount + parameters.VoiceCount * 4) * 0x30 +
0x50;
if (behaviorInfo.IsSplitterSupported())
{
size += BitUtils.AlignUp(NodeStates.GetWorkBufferSize(totalMixCount) + EdgeMatrix.GetWorkBufferSize(totalMixCount), 16);
}
size = parameters.SinkCount * 0x170 +
(parameters.SinkCount + parameters.SubMixCount) * 0x280 +
parameters.EffectCount * 0x4C0 +
((size + SplitterContext.CalcWorkBufferSize(behaviorInfo, parameters) + 0x30 * parameters.EffectCount + (4 * parameters.VoiceCount) + 0x8F) & ~0x3FL) +
((parameters.VoiceCount << 8) | 0x40);
if (parameters.PerformanceManagerCount >= 1)
{
size += (PerformanceManager.GetRequiredBufferSizeForPerformanceMetricsPerFrame(behaviorInfo, parameters) *
(parameters.PerformanceManagerCount + 1) + 0xFF) & ~0x3FL;
}
if (behaviorInfo.IsVariadicCommandBufferSizeSupported())
{
size += CommandGenerator.CalculateCommandBufferSize(parameters) + 0x7E;
}
else
{
size += 0x1807E;
}
size = BitUtils.AlignUp(size, 0x1000);
context.ResponseData.Write(size);
Logger.PrintDebug(LogClass.ServiceAudio, $"WorkBufferSize is 0x{size:x16}.");
return ResultCode.Success;
}
else
{
context.ResponseData.Write(0L);
Logger.PrintWarning(LogClass.ServiceAudio, $"Library Revision REV{AudioRendererCommon.GetRevisionVersion(parameters.Revision)} is not supported!");
return ResultCode.UnsupportedRevision;
}
}
private AudioRendererParameter GetAudioRendererParameter(ServiceCtx context)
{
AudioRendererParameter Params = new AudioRendererParameter
{
SampleRate = context.RequestData.ReadInt32(),
SampleCount = context.RequestData.ReadInt32(),
MixBufferCount = context.RequestData.ReadInt32(),
SubMixCount = context.RequestData.ReadInt32(),
VoiceCount = context.RequestData.ReadInt32(),
SinkCount = context.RequestData.ReadInt32(),
EffectCount = context.RequestData.ReadInt32(),
PerformanceManagerCount = context.RequestData.ReadInt32(),
VoiceDropEnable = context.RequestData.ReadInt32(),
SplitterCount = context.RequestData.ReadInt32(),
SplitterDestinationDataCount = context.RequestData.ReadInt32(),
Unknown2C = context.RequestData.ReadInt32(),
Revision = context.RequestData.ReadInt32()
};
return Params;
}
[Command(2)]
// GetAudioDeviceService(nn::applet::AppletResourceUserId) -> object<nn::audio::detail::IAudioDevice>
public ResultCode GetAudioDeviceService(ServiceCtx context)
{
long appletResourceUserId = context.RequestData.ReadInt64();
MakeObject(context, new IAudioDevice(context.Device.System));
return ResultCode.Success;
}
[Command(4)] // 4.0.0+
// GetAudioDeviceServiceWithRevisionInfo(nn::applet::AppletResourceUserId, u32) -> object<nn::audio::detail::IAudioDevice>
public ResultCode GetAudioDeviceServiceWithRevisionInfo(ServiceCtx context)
{
long appletResourceUserId = context.RequestData.ReadInt64();
int revisionInfo = context.RequestData.ReadInt32();
Logger.PrintStub(LogClass.ServiceAudio, new { appletResourceUserId, revisionInfo });
return GetAudioDeviceService(context);
}
}
}
|