2018-07-15 04:57:41 +02:00
|
|
|
using Ryujinx.Audio;
|
2018-10-17 19:15:50 +02:00
|
|
|
using Ryujinx.Common.Logging;
|
2018-08-17 01:47:36 +02:00
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
|
|
|
using Ryujinx.HLE.HOS.Services.Aud.AudioRenderer;
|
|
|
|
using Ryujinx.HLE.Utilities;
|
2018-02-25 05:34:16 +01:00
|
|
|
using System.Collections.Generic;
|
2018-07-15 04:57:41 +02:00
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
using static Ryujinx.HLE.HOS.ErrorCode;
|
2018-02-25 05:34:16 +01:00
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Aud
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-03-22 00:30:10 +01:00
|
|
|
class IAudioRendererManager : IpcService
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-05-07 21:03:30 +02:00
|
|
|
private const int Rev0Magic = ('R' << 0) |
|
|
|
|
('E' << 8) |
|
|
|
|
('V' << 16) |
|
|
|
|
('0' << 24);
|
|
|
|
|
2018-07-15 04:57:41 +02:00
|
|
|
private const int Rev = 4;
|
|
|
|
|
2018-07-15 05:42:59 +02:00
|
|
|
public const int RevMagic = Rev0Magic + (Rev << 24);
|
2018-07-15 04:57:41 +02:00
|
|
|
|
2018-02-25 05:34:16 +01:00
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
2018-02-25 05:34:16 +01:00
|
|
|
|
2018-03-22 00:30:10 +01:00
|
|
|
public IAudioRendererManager()
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
|
|
|
{
|
2018-10-07 17:12:11 +02:00
|
|
|
{ 0, OpenAudioRenderer },
|
|
|
|
{ 1, GetAudioRendererWorkBufferSize },
|
|
|
|
{ 2, GetAudioDeviceService },
|
|
|
|
{ 4, GetAudioDeviceServiceWithRevisionInfo }
|
2018-02-25 05:34:16 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public long OpenAudioRenderer(ServiceCtx Context)
|
|
|
|
{
|
2018-08-17 01:47:36 +02:00
|
|
|
IAalOutput AudioOut = Context.Device.AudioOut;
|
2018-05-04 16:52:07 +02:00
|
|
|
|
2018-07-15 04:57:41 +02:00
|
|
|
AudioRendererParameter Params = GetAudioRendererParameter(Context);
|
2018-06-23 07:00:14 +02:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
MakeObject(Context, new IAudioRenderer(
|
|
|
|
Context.Device.System,
|
|
|
|
Context.Memory,
|
|
|
|
AudioOut,
|
|
|
|
Params));
|
2018-02-25 05:34:16 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long GetAudioRendererWorkBufferSize(ServiceCtx Context)
|
|
|
|
{
|
2018-07-15 04:57:41 +02:00
|
|
|
AudioRendererParameter Params = GetAudioRendererParameter(Context);
|
|
|
|
|
|
|
|
int Revision = (Params.Revision - Rev0Magic) >> 24;
|
|
|
|
|
2018-07-15 05:37:30 +02:00
|
|
|
if (Revision <= Rev)
|
2018-05-02 02:02:28 +02:00
|
|
|
{
|
2018-07-15 04:57:41 +02:00
|
|
|
bool IsSplitterSupported = Revision >= 3;
|
|
|
|
|
|
|
|
long Size;
|
|
|
|
|
|
|
|
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(
|
|
|
|
((Params.SinkCount + Params.MixCount) * 0x3C0 + Params.SampleCount * 4) *
|
|
|
|
(Params.Unknown8 + 6), 64);
|
|
|
|
Size += (Params.SinkCount + Params.MixCount) * 0x2C0;
|
2018-07-15 05:34:12 +02:00
|
|
|
Size += (Params.EffectCount + Params.VoiceCount * 4) * 0x30 + 0x50;
|
2018-07-15 04:57:41 +02:00
|
|
|
|
|
|
|
if (IsSplitterSupported)
|
2018-05-04 16:52:07 +02:00
|
|
|
{
|
2018-07-15 04:57:41 +02:00
|
|
|
Size += IntUtils.AlignUp((
|
|
|
|
NodeStatesGetWorkBufferSize(Params.MixCount + 1) +
|
|
|
|
EdgeMatrixGetWorkBufferSize(Params.MixCount + 1)), 16);
|
|
|
|
|
|
|
|
Size += Params.SplitterDestinationDataCount * 0xE0;
|
|
|
|
Size += Params.SplitterCount * 0x20;
|
|
|
|
Size += IntUtils.AlignUp(Params.SplitterDestinationDataCount * 4, 16);
|
2018-05-04 16:52:07 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 04:57:41 +02:00
|
|
|
Size = Params.EffectCount * 0x4C0 +
|
|
|
|
Params.SinkCount * 0x170 +
|
|
|
|
Params.VoiceCount * 0x100 +
|
|
|
|
IntUtils.AlignUp(Size, 64) + 0x40;
|
2018-05-04 16:52:07 +02:00
|
|
|
|
2018-07-15 04:57:41 +02:00
|
|
|
if (Params.PerformanceManagerCount >= 1)
|
2018-05-02 02:02:28 +02:00
|
|
|
{
|
2018-07-15 04:57:41 +02:00
|
|
|
Size += (((Params.EffectCount +
|
|
|
|
Params.SinkCount +
|
|
|
|
Params.VoiceCount +
|
|
|
|
Params.MixCount + 1) * 16 + 0x658) *
|
|
|
|
(Params.PerformanceManagerCount + 1) + 0x13F) & ~0x3FL;
|
2018-05-02 02:02:28 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 04:57:41 +02:00
|
|
|
Size = (Size + 0x1907D) & ~0xFFFL;
|
2018-05-02 02:02:28 +02:00
|
|
|
|
2018-07-15 04:57:41 +02:00
|
|
|
Context.ResponseData.Write(Size);
|
2018-05-02 02:02:28 +02:00
|
|
|
|
2018-10-17 19:15:50 +02:00
|
|
|
Logger.PrintDebug(LogClass.ServiceAudio, $"WorkBufferSize is 0x{Size:x16}.");
|
2018-05-02 02:02:28 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Context.ResponseData.Write(0L);
|
|
|
|
|
2018-10-17 19:15:50 +02:00
|
|
|
Logger.PrintWarning(LogClass.ServiceAudio, $"Library Revision 0x{Params.Revision:x8} is not supported!");
|
2018-05-02 02:02:28 +02:00
|
|
|
|
2018-07-15 04:57:41 +02:00
|
|
|
return MakeError(ErrorModule.Audio, AudErr.UnsupportedRevision);
|
2018-05-02 02:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-15 04:57:41 +02:00
|
|
|
private AudioRendererParameter GetAudioRendererParameter(ServiceCtx Context)
|
2018-05-02 02:02:28 +02:00
|
|
|
{
|
2018-07-15 04:57:41 +02:00
|
|
|
AudioRendererParameter Params = new AudioRendererParameter();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
return Params;
|
2018-02-25 05:34:16 +01:00
|
|
|
}
|
2018-03-12 06:07:48 +01:00
|
|
|
|
2018-05-04 16:52:07 +02:00
|
|
|
private static int NodeStatesGetWorkBufferSize(int Value)
|
|
|
|
{
|
2018-07-15 04:57:41 +02:00
|
|
|
int Result = IntUtils.AlignUp(Value, 64);
|
2018-05-04 16:52:07 +02:00
|
|
|
|
|
|
|
if (Result < 0)
|
|
|
|
{
|
|
|
|
Result |= 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 4 * (Value * Value) + 0x12 * Value + 2 * (Result / 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int EdgeMatrixGetWorkBufferSize(int Value)
|
|
|
|
{
|
2018-07-15 04:57:41 +02:00
|
|
|
int Result = IntUtils.AlignUp(Value * Value, 64);
|
2018-05-04 16:52:07 +02:00
|
|
|
|
|
|
|
if (Result < 0)
|
|
|
|
{
|
|
|
|
Result |= 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result / 8;
|
|
|
|
}
|
|
|
|
|
2018-10-07 17:12:11 +02:00
|
|
|
// GetAudioDeviceService(nn::applet::AppletResourceUserId) -> object<nn::audio::detail::IAudioDevice>
|
|
|
|
public long GetAudioDeviceService(ServiceCtx Context)
|
2018-03-12 06:07:48 +01:00
|
|
|
{
|
2018-10-07 17:12:11 +02:00
|
|
|
long AppletResourceUserId = Context.RequestData.ReadInt64();
|
2018-03-12 20:29:06 +01:00
|
|
|
|
2018-09-19 01:36:43 +02:00
|
|
|
MakeObject(Context, new IAudioDevice(Context.Device.System));
|
2018-03-12 06:07:48 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-10-07 17:12:11 +02:00
|
|
|
|
|
|
|
// GetAudioDeviceServiceWithRevisionInfo(nn::applet::AppletResourceUserId, u32) -> object<nn::audio::detail::IAudioDevice>
|
|
|
|
private long GetAudioDeviceServiceWithRevisionInfo(ServiceCtx Context)
|
|
|
|
{
|
|
|
|
long AppletResourceUserId = Context.RequestData.ReadInt64();
|
|
|
|
int RevisionInfo = Context.RequestData.ReadInt32();
|
|
|
|
|
2018-10-17 19:15:50 +02:00
|
|
|
Logger.PrintStub(LogClass.ServiceAudio, $"Stubbed. AppletResourceUserId: {AppletResourceUserId} - " +
|
2018-10-07 17:12:11 +02:00
|
|
|
$"RevisionInfo: {RevisionInfo}");
|
|
|
|
|
|
|
|
return GetAudioDeviceService(Context);
|
|
|
|
}
|
2018-02-25 05:34:16 +01:00
|
|
|
}
|
2018-05-02 02:02:28 +02:00
|
|
|
}
|