Amadeus: Final Act (#1481)

* Amadeus: Final Act

This is my requiem, I present to you Amadeus, a complete reimplementation of the Audio Renderer!

This reimplementation is based on my reversing of every version of the audio system module that I carried for the past 10 months.
This supports every revision (at the time of writing REV1 to REV8 included) and all features proposed by the Audio Renderer on real hardware.

Because this component could be used outside an emulation context, and to avoid possible "inspirations" not crediting the project, I decided to license the Ryujinx.Audio.Renderer project under LGPLv3.

- FE3H voices in videos and chapter intro are not present.
- Games that use two audio renderer **at the same time** are probably going to have issues right now **until we rewrite the audio output interface** (Crash Team Racing is the only known game to use two renderer at the same time).

- Persona 5 Scrambler now goes ingame but audio is garbage. This is caused by the fact that the game engine is syncing audio and video in a really aggressive way. This will disappears the day this game run at full speed.

* Make timing more precise when sleeping on Windows

Improve precision to a 1ms resolution on Windows NT based OS.
This is used to avoid having totally erratic timings and unify all
Windows users to the same resolution.

NOTE: This is only active when emulation is running.
This commit is contained in:
Mary 2020-08-18 03:49:37 +02:00 committed by GitHub
parent 2a314f3c28
commit a389dd59bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
250 changed files with 23691 additions and 1512 deletions

View file

@ -1,148 +1,19 @@
using Ryujinx.Audio;
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Services.Audio.AudioRendererManager;
using Ryujinx.Audio.Renderer.Parameter;
using Ryujinx.HLE.HOS.Kernel.Memory;
using Ryujinx.HLE.HOS.Services.Audio.AudioRenderer;
namespace Ryujinx.HLE.HOS.Services.Audio
{
[Service("audren:u")]
class IAudioRendererManager : IpcService
interface IAudioRendererManager
{
public IAudioRendererManager(ServiceCtx context) { }
// TODO: Remove ServiceCtx argument
// BODY: This is only needed by the legacy backend. Refactor this when removing the legacy backend.
ResultCode GetAudioDeviceServiceWithRevisionInfo(ServiceCtx context, out IAudioDevice outObject, int revision, ulong appletResourceUserId);
[Command(0)]
// OpenAudioRenderer(nn::audio::detail::AudioRendererParameterInternal, u64, nn::applet::AppletResourceUserId, pid, handle<copy>, handle<copy>)
// -> object<nn::audio::detail::IAudioRenderer>
public ResultCode OpenAudioRenderer(ServiceCtx context)
{
IAalOutput audioOut = context.Device.AudioOut;
// TODO: Remove ServiceCtx argument
// BODY: This is only needed by the legacy backend. Refactor this when removing the legacy backend.
ResultCode OpenAudioRenderer(ServiceCtx context, out IAudioRenderer obj, ref AudioRendererConfiguration parameter, ulong workBufferSize, ulong appletResourceUserId, KTransferMemory workBufferTransferMemory, uint processHandle);
AudioRendererParameter Params = GetAudioRendererParameter(context);
MakeObject(context, new IAudioRenderer(
context.Device.System,
context.Memory,
audioOut,
Params));
return ResultCode.Success;
}
[Command(1)]
// GetWorkBufferSize(nn::audio::detail::AudioRendererParameterInternal) -> u64
public ResultCode GetAudioRendererWorkBufferSize(ServiceCtx context)
{
AudioRendererParameter parameters = GetAudioRendererParameter(context);
if (AudioRendererCommon.CheckValidRevision(parameters))
{
BehaviorInfo behaviorInfo = new BehaviorInfo();
behaviorInfo.SetUserLibRevision(parameters.Revision);
long size;
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())
{
size += BitUtils.AlignUp(NodeStates.GetWorkBufferSize(totalMixCount) + EdgeMatrix.GetWorkBufferSize(totalMixCount), 16);
}
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);
if (parameters.PerformanceManagerCount >= 1)
{
size += (PerformanceManager.GetRequiredBufferSizeForPerformanceMetricsPerFrame(behaviorInfo, parameters) *
(parameters.PerformanceManagerCount + 1) + 0xFF) & ~0x3FL;
}
if (behaviorInfo.IsVariadicCommandBufferSizeSupported())
{
size += CommandGenerator.CalculateCommandBufferSize(parameters) + 0x7E;
}
else
{
size += 0x1807E;
}
size = BitUtils.AlignUp(size, 0x1000);
context.ResponseData.Write(size);
Logger.Debug?.Print(LogClass.ServiceAudio, $"WorkBufferSize is 0x{size:x16}.");
return ResultCode.Success;
}
else
{
context.ResponseData.Write(0L);
Logger.Warning?.Print(LogClass.ServiceAudio, $"Library Revision REV{AudioRendererCommon.GetRevisionVersion(parameters.Revision)} is not supported!");
return ResultCode.UnsupportedRevision;
}
}
private AudioRendererParameter GetAudioRendererParameter(ServiceCtx context)
{
AudioRendererParameter Params = new AudioRendererParameter
{
SampleRate = context.RequestData.ReadInt32(),
SampleCount = context.RequestData.ReadInt32(),
MixBufferCount = context.RequestData.ReadInt32(),
SubMixCount = context.RequestData.ReadInt32(),
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()
};
return Params;
}
[Command(2)]
// GetAudioDeviceService(nn::applet::AppletResourceUserId) -> object<nn::audio::detail::IAudioDevice>
public ResultCode GetAudioDeviceService(ServiceCtx context)
{
long appletResourceUserId = context.RequestData.ReadInt64();
MakeObject(context, new IAudioDevice(context.Device.System));
return ResultCode.Success;
}
[Command(4)] // 4.0.0+
// GetAudioDeviceServiceWithRevisionInfo(u32 revision_info, nn::applet::AppletResourceUserId) -> object<nn::audio::detail::IAudioDevice>
public ResultCode GetAudioDeviceServiceWithRevisionInfo(ServiceCtx context)
{
int revisionInfo = context.RequestData.ReadInt32();
long appletResourceUserId = context.RequestData.ReadInt64();
Logger.Stub?.PrintStub(LogClass.ServiceAudio, new { appletResourceUserId, revisionInfo });
return GetAudioDeviceService(context);
}
ulong GetWorkBufferSize(ref AudioRendererConfiguration parameter);
}
}