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