2018-07-14 22:57:41 -04:00
|
|
|
using Ryujinx.Audio;
|
2018-10-17 13:15:50 -04:00
|
|
|
using Ryujinx.Common.Logging;
|
2018-08-16 19:47:36 -04:00
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Aud.AudioRenderer;
|
|
|
|
using Ryujinx.HLE.Utilities;
|
2018-02-24 23:34:16 -05:00
|
|
|
using System.Collections.Generic;
|
2018-07-14 22:57:41 -04:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
using static Ryujinx.HLE.HOS.ErrorCode;
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Aud
|
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
|
|
|
{
|
2018-05-07 15:03:30 -04:00
|
|
|
private const int Rev0Magic = ('R' << 0) |
|
|
|
|
('E' << 8) |
|
|
|
|
('V' << 16) |
|
|
|
|
('0' << 24);
|
|
|
|
|
2019-04-24 10:22:06 -04:00
|
|
|
private const int Rev = 5;
|
2018-07-14 22:57:41 -04:00
|
|
|
|
2018-07-14 23:42:59 -04:00
|
|
|
public const int RevMagic = Rev0Magic + (Rev << 24);
|
2018-07-14 22:57:41 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
private Dictionary<int, ServiceProcessRequest> _commands;
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2019-07-10 11:59:54 -04:00
|
|
|
public IAudioRendererManager(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
_commands = new Dictionary<int, ServiceProcessRequest>
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2018-10-07 11:12:11 -04:00
|
|
|
{ 0, OpenAudioRenderer },
|
|
|
|
{ 1, GetAudioRendererWorkBufferSize },
|
|
|
|
{ 2, GetAudioDeviceService },
|
|
|
|
{ 4, GetAudioDeviceServiceWithRevisionInfo }
|
2018-02-24 23:34:16 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
public long 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
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
public long GetAudioRendererWorkBufferSize(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
AudioRendererParameter Params = GetAudioRendererParameter(context);
|
2018-07-14 22:57:41 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
int revision = (Params.Revision - Rev0Magic) >> 24;
|
2018-07-14 22:57:41 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (revision <= Rev)
|
2018-05-01 20:02:28 -04:00
|
|
|
{
|
2019-04-24 10:22:06 -04:00
|
|
|
bool isSplitterSupported = revision >= 3;
|
|
|
|
bool isVariadicCommandBufferSizeSupported = revision >= 5;
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
long size;
|
2018-07-14 22:57:41 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
size = IntUtils.AlignUp(Params.Unknown8 * 4, 64);
|
|
|
|
size += Params.MixCount * 0x400;
|
|
|
|
size += (Params.MixCount + 1) * 0x940;
|
|
|
|
size += Params.VoiceCount * 0x3F0;
|
|
|
|
size += IntUtils.AlignUp((Params.MixCount + 1) * 8, 16);
|
|
|
|
size += IntUtils.AlignUp(Params.VoiceCount * 8, 16);
|
|
|
|
size += IntUtils.AlignUp(
|
2018-07-14 22:57:41 -04:00
|
|
|
((Params.SinkCount + Params.MixCount) * 0x3C0 + Params.SampleCount * 4) *
|
|
|
|
(Params.Unknown8 + 6), 64);
|
2018-12-06 06:16:24 -05:00
|
|
|
size += (Params.SinkCount + Params.MixCount) * 0x2C0;
|
|
|
|
size += (Params.EffectCount + Params.VoiceCount * 4) * 0x30 + 0x50;
|
2018-07-14 22:57:41 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (isSplitterSupported)
|
2018-05-04 10:52:07 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
size += IntUtils.AlignUp((
|
2018-07-14 22:57:41 -04:00
|
|
|
NodeStatesGetWorkBufferSize(Params.MixCount + 1) +
|
|
|
|
EdgeMatrixGetWorkBufferSize(Params.MixCount + 1)), 16);
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
size += Params.SplitterDestinationDataCount * 0xE0;
|
|
|
|
size += Params.SplitterCount * 0x20;
|
|
|
|
size += IntUtils.AlignUp(Params.SplitterDestinationDataCount * 4, 16);
|
2018-05-04 10:52:07 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
size = Params.EffectCount * 0x4C0 +
|
2018-07-14 22:57:41 -04:00
|
|
|
Params.SinkCount * 0x170 +
|
|
|
|
Params.VoiceCount * 0x100 +
|
2018-12-06 06:16:24 -05:00
|
|
|
IntUtils.AlignUp(size, 64) + 0x40;
|
2018-05-04 10:52:07 -04:00
|
|
|
|
2018-07-14 22:57:41 -04:00
|
|
|
if (Params.PerformanceManagerCount >= 1)
|
2018-05-01 20:02:28 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
size += (((Params.EffectCount +
|
2018-07-14 22:57:41 -04:00
|
|
|
Params.SinkCount +
|
|
|
|
Params.VoiceCount +
|
|
|
|
Params.MixCount + 1) * 16 + 0x658) *
|
|
|
|
(Params.PerformanceManagerCount + 1) + 0x13F) & ~0x3FL;
|
2018-05-01 20:02:28 -04:00
|
|
|
}
|
|
|
|
|
2019-04-24 10:22:06 -04:00
|
|
|
if (isVariadicCommandBufferSizeSupported)
|
|
|
|
{
|
|
|
|
size += Params.EffectCount * 0x840 +
|
|
|
|
Params.MixCount * 0x5A38 +
|
|
|
|
Params.SinkCount * 0x148 +
|
|
|
|
Params.SplitterDestinationDataCount * 0x540 +
|
|
|
|
Params.VoiceCount * (Params.SplitterCount * 0x68 + 0x2E0) +
|
|
|
|
((Params.VoiceCount + Params.MixCount + Params.EffectCount + Params.SinkCount + 0x65) << 6) + 0x3F8 + 0x7E;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size += 0x1807E;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = size & ~0xFFFL;
|
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
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
context.ResponseData.Write(0L);
|
2018-05-01 20:02:28 -04:00
|
|
|
|
2018-10-17 13:15:50 -04:00
|
|
|
Logger.PrintWarning(LogClass.ServiceAudio, $"Library Revision 0x{Params.Revision:x8} is not supported!");
|
2018-05-01 20:02:28 -04:00
|
|
|
|
2018-07-14 22:57:41 -04:00
|
|
|
return MakeError(ErrorModule.Audio, AudErr.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
|
|
|
{
|
2018-07-14 22:57:41 -04:00
|
|
|
AudioRendererParameter Params = new AudioRendererParameter();
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
Params.SampleRate = context.RequestData.ReadInt32();
|
|
|
|
Params.SampleCount = context.RequestData.ReadInt32();
|
|
|
|
Params.Unknown8 = context.RequestData.ReadInt32();
|
|
|
|
Params.MixCount = context.RequestData.ReadInt32();
|
|
|
|
Params.VoiceCount = context.RequestData.ReadInt32();
|
|
|
|
Params.SinkCount = context.RequestData.ReadInt32();
|
|
|
|
Params.EffectCount = context.RequestData.ReadInt32();
|
|
|
|
Params.PerformanceManagerCount = context.RequestData.ReadInt32();
|
|
|
|
Params.VoiceDropEnable = context.RequestData.ReadInt32();
|
|
|
|
Params.SplitterCount = context.RequestData.ReadInt32();
|
|
|
|
Params.SplitterDestinationDataCount = context.RequestData.ReadInt32();
|
|
|
|
Params.Unknown2C = context.RequestData.ReadInt32();
|
|
|
|
Params.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
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
private static int NodeStatesGetWorkBufferSize(int value)
|
2018-05-04 10:52:07 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
int result = IntUtils.AlignUp(value, 64);
|
2018-05-04 10:52:07 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (result < 0)
|
2018-05-04 10:52:07 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
result |= 7;
|
2018-05-04 10:52:07 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
return 4 * (value * value) + 0x12 * value + 2 * (result / 8);
|
2018-05-04 10:52:07 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
private static int EdgeMatrixGetWorkBufferSize(int value)
|
2018-05-04 10:52:07 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
int result = IntUtils.AlignUp(value * value, 64);
|
2018-05-04 10:52:07 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (result < 0)
|
2018-05-04 10:52:07 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
result |= 7;
|
2018-05-04 10:52:07 -04:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
return result / 8;
|
2018-05-04 10:52:07 -04:00
|
|
|
}
|
|
|
|
|
2018-10-07 11:12:11 -04:00
|
|
|
// GetAudioDeviceService(nn::applet::AppletResourceUserId) -> object<nn::audio::detail::IAudioDevice>
|
2018-12-06 06:16:24 -05:00
|
|
|
public long 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
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-10-07 11:12:11 -04:00
|
|
|
|
|
|
|
// GetAudioDeviceServiceWithRevisionInfo(nn::applet::AppletResourceUserId, u32) -> object<nn::audio::detail::IAudioDevice>
|
2018-12-06 06:16:24 -05:00
|
|
|
private long GetAudioDeviceServiceWithRevisionInfo(ServiceCtx context)
|
2018-10-07 11:12:11 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
long appletResourceUserId = context.RequestData.ReadInt64();
|
|
|
|
int revisionInfo = context.RequestData.ReadInt32();
|
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
|
|
|
}
|