2018-06-11 02:46:42 +02:00
|
|
|
using Ryujinx.HLE.Logging;
|
|
|
|
using Ryujinx.HLE.OsHle.Ipc;
|
2018-02-25 05:34:16 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2018-06-11 02:46:42 +02:00
|
|
|
namespace Ryujinx.HLE.OsHle.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-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-03-12 20:29:06 +01:00
|
|
|
{ 0, OpenAudioRenderer },
|
|
|
|
{ 1, GetAudioRendererWorkBufferSize },
|
|
|
|
{ 2, GetAudioDevice }
|
2018-02-25 05:34:16 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public long OpenAudioRenderer(ServiceCtx Context)
|
|
|
|
{
|
2018-05-04 16:52:07 +02:00
|
|
|
//Same buffer as GetAudioRendererWorkBufferSize is receive here.
|
|
|
|
|
2018-02-25 05:34:16 +01:00
|
|
|
MakeObject(Context, new IAudioRenderer());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long GetAudioRendererWorkBufferSize(ServiceCtx Context)
|
|
|
|
{
|
2018-05-02 02:02:28 +02:00
|
|
|
long SampleRate = Context.RequestData.ReadUInt32();
|
|
|
|
long Unknown4 = Context.RequestData.ReadUInt32();
|
|
|
|
long Unknown8 = Context.RequestData.ReadUInt32();
|
|
|
|
long UnknownC = Context.RequestData.ReadUInt32();
|
2018-05-04 16:52:07 +02:00
|
|
|
long Unknown10 = Context.RequestData.ReadUInt32(); //VoiceCount
|
|
|
|
long Unknown14 = Context.RequestData.ReadUInt32(); //SinkCount
|
|
|
|
long Unknown18 = Context.RequestData.ReadUInt32(); //EffectCount
|
|
|
|
long Unknown1c = Context.RequestData.ReadUInt32(); //Boolean
|
|
|
|
long Unknown20 = Context.RequestData.ReadUInt32(); //Not used here in FW3.0.1 - Boolean
|
|
|
|
long Unknown24 = Context.RequestData.ReadUInt32();
|
|
|
|
long Unknown28 = Context.RequestData.ReadUInt32(); //SplitterCount
|
|
|
|
long Unknown2c = Context.RequestData.ReadUInt32(); //Not used here in FW3.0.1
|
2018-05-07 21:03:30 +02:00
|
|
|
int RevMagic = Context.RequestData.ReadInt32();
|
|
|
|
|
|
|
|
int Version = (RevMagic - Rev0Magic) >> 24;
|
2018-05-04 16:52:07 +02:00
|
|
|
|
2018-05-07 21:03:30 +02:00
|
|
|
if (Version <= 3) //REV3 Max is supported
|
2018-05-02 02:02:28 +02:00
|
|
|
{
|
2018-05-04 16:52:07 +02:00
|
|
|
long Size = RoundUp(Unknown8 * 4, 64);
|
|
|
|
Size += (UnknownC << 10);
|
|
|
|
Size += (UnknownC + 1) * 0x940;
|
|
|
|
Size += Unknown10 * 0x3F0;
|
|
|
|
Size += RoundUp((UnknownC + 1) * 8, 16);
|
|
|
|
Size += RoundUp(Unknown10 * 8, 16);
|
|
|
|
Size += RoundUp((0x3C0 * (Unknown14 + UnknownC) + 4 * Unknown4) * (Unknown8 + 6), 64);
|
|
|
|
Size += 0x2C0 * (Unknown14 + UnknownC) + 0x30 * (Unknown18 + (4 * Unknown10)) + 0x50;
|
|
|
|
|
2018-05-07 21:03:30 +02:00
|
|
|
if (Version >= 3) //IsSplitterSupported
|
2018-05-04 16:52:07 +02:00
|
|
|
{
|
|
|
|
Size += RoundUp((NodeStatesGetWorkBufferSize((int)UnknownC + 1) + EdgeMatrixGetWorkBufferSize((int)UnknownC + 1)), 16);
|
|
|
|
Size += 0xE0 * Unknown28 + 0x20 * Unknown24 + RoundUp(Unknown28 * 4, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
Size = 0x4C0 * Unknown18 + RoundUp(Size, 64) + 0x170 * Unknown14 + ((Unknown10 << 8) | 0x40);
|
|
|
|
|
|
|
|
if (Unknown1c >= 1)
|
2018-05-02 02:02:28 +02:00
|
|
|
{
|
2018-05-04 16:52:07 +02:00
|
|
|
Size += ((((Unknown18 + Unknown14 + Unknown10 + UnknownC + 1) * 16) + 0x658) * (Unknown1c + 1) + 0x13F) & ~0x3FL;
|
2018-05-02 02:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
long WorkBufferSize = (Size + 0x1907D) & ~0xFFFL;
|
|
|
|
|
|
|
|
Context.ResponseData.Write(WorkBufferSize);
|
|
|
|
|
|
|
|
Context.Ns.Log.PrintDebug(LogClass.ServiceAudio, $"WorkBufferSize is 0x{WorkBufferSize:x16}.");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Context.ResponseData.Write(0L);
|
|
|
|
|
2018-05-07 21:03:30 +02:00
|
|
|
Context.Ns.Log.PrintError(LogClass.ServiceAudio, $"Library Revision 0x{RevMagic:x8} is not supported!");
|
2018-05-02 02:02:28 +02:00
|
|
|
|
|
|
|
return 0x499;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static long RoundUp(long Value, int Size)
|
|
|
|
{
|
|
|
|
return (Value + (Size - 1)) & ~((long)Size - 1);
|
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)
|
|
|
|
{
|
|
|
|
int Result = (int)RoundUp(Value, 64);
|
|
|
|
|
|
|
|
if (Result < 0)
|
|
|
|
{
|
|
|
|
Result |= 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 4 * (Value * Value) + 0x12 * Value + 2 * (Result / 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int EdgeMatrixGetWorkBufferSize(int Value)
|
|
|
|
{
|
|
|
|
int Result = (int)RoundUp(Value * Value, 64);
|
|
|
|
|
|
|
|
if (Result < 0)
|
|
|
|
{
|
|
|
|
Result |= 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result / 8;
|
|
|
|
}
|
|
|
|
|
2018-03-12 20:29:06 +01:00
|
|
|
public long GetAudioDevice(ServiceCtx Context)
|
2018-03-12 06:07:48 +01:00
|
|
|
{
|
2018-03-12 20:29:06 +01:00
|
|
|
long UserId = Context.RequestData.ReadInt64();
|
|
|
|
|
2018-04-22 06:21:49 +02:00
|
|
|
MakeObject(Context, new IAudioDevice());
|
2018-03-12 06:07:48 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-02-25 05:34:16 +01:00
|
|
|
}
|
2018-05-02 02:02:28 +02:00
|
|
|
}
|