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