2018-07-15 02:57:41 +00:00
|
|
|
using Ryujinx.Audio;
|
2019-09-19 23:49:05 +00:00
|
|
|
using Ryujinx.Common;
|
2018-10-17 17:15:50 +00:00
|
|
|
using Ryujinx.Common.Logging;
|
2019-09-19 00:45:11 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager;
|
2018-07-15 02:57:41 +00:00
|
|
|
|
2019-09-19 00:45:11 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Audio
|
2018-02-25 04:34:16 +00:00
|
|
|
{
|
2019-07-10 15:59:54 +00:00
|
|
|
[Service("audren:u")]
|
2018-03-21 23:30:10 +00:00
|
|
|
class IAudioRendererManager : IpcService
|
2018-02-25 04:34:16 +00:00
|
|
|
{
|
2019-07-12 01:13:43 +00:00
|
|
|
public IAudioRendererManager(ServiceCtx context) { }
|
2018-02-25 04:34:16 +00:00
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(0)]
|
|
|
|
// OpenAudioRenderer(nn::audio::detail::AudioRendererParameterInternal, u64, nn::applet::AppletResourceUserId, pid, handle<copy>, handle<copy>)
|
|
|
|
// -> object<nn::audio::detail::IAudioRenderer>
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode OpenAudioRenderer(ServiceCtx context)
|
2018-02-25 04:34:16 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
IAalOutput audioOut = context.Device.AudioOut;
|
2018-05-04 14:52:07 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
AudioRendererParameter Params = GetAudioRendererParameter(context);
|
2018-06-23 05:00:14 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
MakeObject(context, new IAudioRenderer(
|
|
|
|
context.Device.System,
|
|
|
|
context.Memory,
|
|
|
|
audioOut,
|
2018-09-18 23:36:43 +00:00
|
|
|
Params));
|
2018-02-25 04:34:16 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-02-25 04:34:16 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(1)]
|
|
|
|
// GetWorkBufferSize(nn::audio::detail::AudioRendererParameterInternal) -> u64
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode GetAudioRendererWorkBufferSize(ServiceCtx context)
|
2018-02-25 04:34:16 +00:00
|
|
|
{
|
2019-09-19 23:49:05 +00:00
|
|
|
AudioRendererParameter parameters = GetAudioRendererParameter(context);
|
2018-07-15 02:57:41 +00:00
|
|
|
|
2019-09-19 23:49:05 +00:00
|
|
|
if (AudioRendererCommon.CheckValidRevision(parameters))
|
2018-05-02 00:02:28 +00:00
|
|
|
{
|
2019-09-19 23:49:05 +00:00
|
|
|
BehaviorInfo behaviorInfo = new BehaviorInfo();
|
|
|
|
|
|
|
|
behaviorInfo.SetUserLibRevision(parameters.Revision);
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
long size;
|
2018-07-15 02:57:41 +00:00
|
|
|
|
2019-09-19 23:49:05 +00:00
|
|
|
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())
|
2018-05-04 14:52:07 +00:00
|
|
|
{
|
2019-09-19 23:49:05 +00:00
|
|
|
size += BitUtils.AlignUp(NodeStates.GetWorkBufferSize(totalMixCount) + EdgeMatrix.GetWorkBufferSize(totalMixCount), 16);
|
2018-05-04 14:52:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 23:49:05 +00:00
|
|
|
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);
|
2018-05-04 14:52:07 +00:00
|
|
|
|
2019-09-19 23:49:05 +00:00
|
|
|
if (parameters.PerformanceManagerCount >= 1)
|
2018-05-02 00:02:28 +00:00
|
|
|
{
|
2019-09-19 23:49:05 +00:00
|
|
|
size += (PerformanceManager.GetRequiredBufferSizeForPerformanceMetricsPerFrame(behaviorInfo, parameters) *
|
|
|
|
(parameters.PerformanceManagerCount + 1) + 0xFF) & ~0x3FL;
|
2018-05-02 00:02:28 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 23:49:05 +00:00
|
|
|
if (behaviorInfo.IsVariadicCommandBufferSizeSupported())
|
2019-04-24 14:22:06 +00:00
|
|
|
{
|
2019-09-19 23:49:05 +00:00
|
|
|
size += CommandGenerator.CalculateCommandBufferSize(parameters) + 0x7E;
|
2019-04-24 14:22:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size += 0x1807E;
|
|
|
|
}
|
|
|
|
|
2019-09-19 23:49:05 +00:00
|
|
|
size = BitUtils.AlignUp(size, 0x1000);
|
2018-05-02 00:02:28 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
context.ResponseData.Write(size);
|
2018-05-02 00:02:28 +00:00
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
Logger.Debug?.Print(LogClass.ServiceAudio, $"WorkBufferSize is 0x{size:x16}.");
|
2018-05-02 00:02:28 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-05-02 00:02:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
context.ResponseData.Write(0L);
|
2018-05-02 00:02:28 +00:00
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
Logger.Warning?.Print(LogClass.ServiceAudio, $"Library Revision REV{AudioRendererCommon.GetRevisionVersion(parameters.Revision)} is not supported!");
|
2018-05-02 00:02:28 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.UnsupportedRevision;
|
2018-05-02 00:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private AudioRendererParameter GetAudioRendererParameter(ServiceCtx context)
|
2018-05-02 00:02:28 +00:00
|
|
|
{
|
2019-09-19 00:45:11 +00:00
|
|
|
AudioRendererParameter Params = new AudioRendererParameter
|
|
|
|
{
|
|
|
|
SampleRate = context.RequestData.ReadInt32(),
|
|
|
|
SampleCount = context.RequestData.ReadInt32(),
|
2019-09-19 23:49:05 +00:00
|
|
|
MixBufferCount = context.RequestData.ReadInt32(),
|
|
|
|
SubMixCount = context.RequestData.ReadInt32(),
|
2019-09-19 00:45:11 +00:00
|
|
|
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()
|
|
|
|
};
|
2018-07-15 02:57:41 +00:00
|
|
|
|
|
|
|
return Params;
|
2018-02-25 04:34:16 +00:00
|
|
|
}
|
2018-03-12 05:07:48 +00:00
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(2)]
|
2018-10-07 15:12:11 +00:00
|
|
|
// GetAudioDeviceService(nn::applet::AppletResourceUserId) -> object<nn::audio::detail::IAudioDevice>
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode GetAudioDeviceService(ServiceCtx context)
|
2018-03-12 05:07:48 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
long appletResourceUserId = context.RequestData.ReadInt64();
|
2018-03-12 19:29:06 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
MakeObject(context, new IAudioDevice(context.Device.System));
|
2018-03-12 05:07:48 +00:00
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-03-12 05:07:48 +00:00
|
|
|
}
|
2018-10-07 15:12:11 +00:00
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(4)] // 4.0.0+
|
2019-11-14 09:06:28 +00:00
|
|
|
// GetAudioDeviceServiceWithRevisionInfo(u32 revision_info, nn::applet::AppletResourceUserId) -> object<nn::audio::detail::IAudioDevice>
|
2019-07-14 21:22:53 +00:00
|
|
|
public ResultCode GetAudioDeviceServiceWithRevisionInfo(ServiceCtx context)
|
2018-10-07 15:12:11 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
int revisionInfo = context.RequestData.ReadInt32();
|
2019-11-14 09:06:28 +00:00
|
|
|
long appletResourceUserId = context.RequestData.ReadInt64();
|
2018-10-07 15:12:11 +00:00
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAudio, new { appletResourceUserId, revisionInfo });
|
2018-10-07 15:12:11 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
return GetAudioDeviceService(context);
|
2018-10-07 15:12:11 +00:00
|
|
|
}
|
2018-02-25 04:34:16 +00:00
|
|
|
}
|
2018-05-02 00:02:28 +00:00
|
|
|
}
|