Audio: Add optional artificial audio delay layer

This driver runs ahead by the given duration (measured in samples at 48000hz). For games that rely on buffer release feedback to know when to provide audio frames, this can trick them into running with a higher audio latency on platforms that require it to avoid stuttering.

See `Switch.cs` for the sampleDelay definition. It's currently 0, though in future it could be configurable or switch on automatically for certain configurations.

For audio sources that _do not_ care about sample release timing, such as the current AudioRenderer, this will not change their behaviour.
This commit is contained in:
riperiperi 2024-01-06 20:06:55 +00:00
parent 7ac6b8e742
commit 60442064e4
9 changed files with 274 additions and 9 deletions

View file

@ -1,4 +1,5 @@
using Ryujinx.Audio.Backends.CompatLayer;
using Ryujinx.Audio.Backends.DelayLayer;
using Ryujinx.Audio.Integration;
using Ryujinx.Common.Configuration;
using Ryujinx.Graphics.Gpu;
@ -46,7 +47,7 @@ namespace Ryujinx.HLE
: MemoryAllocationFlags.Reserve | MemoryAllocationFlags.Mirrorable;
#pragma warning disable IDE0055 // Disable formatting
AudioDeviceDriver = new CompatLayerHardwareDeviceDriver(Configuration.AudioDeviceDriver);
AudioDeviceDriver = AddAudioCompatLayers(Configuration.AudioDeviceDriver);
Memory = new MemoryBlock(Configuration.MemoryConfiguration.ToDramSize(), memoryAllocationFlags);
Gpu = new GpuContext(Configuration.GpuRenderer);
System = new HOS.Horizon(this);
@ -67,6 +68,19 @@ namespace Ryujinx.HLE
#pragma warning restore IDE0055
}
private IHardwareDeviceDriver AddAudioCompatLayers(IHardwareDeviceDriver driver)
{
ulong sampleDelay = 0;
driver = new CompatLayerHardwareDeviceDriver(driver);
if (sampleDelay > 0)
{
driver = new DelayLayerHardwareDeviceDriver(driver, sampleDelay);
}
return driver;
}
public bool LoadCart(string exeFsDir, string romFsFile = null)
{
return Processes.LoadUnpackedNca(exeFsDir, romFsFile);