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