diff options
author | Mary-nyan <mary@mary.zone> | 2022-11-28 08:28:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-28 08:28:45 +0100 |
commit | dff138229c79483c189be6f3829ed88a5f95575d (patch) | |
tree | 2e5c37fdc4c6dcd44ad3a0a294885d8d81bed91d /Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs | |
parent | 472119c8da7edaf7bf60fa75e87812e5cb16e33b (diff) |
amadeus: Fixes and initial 15.0.0 support (#3908)1.1.394
* amadeus: Allow OOB read of GC-ADPCM coefficients
Fixes "Ninja Gaiden Sigma 2" and possibly "NINJA GAIDEN 3: Razor's Edge"
* amadeus: Fix wrong variable usage in delay effect
We should transform the delay line values, not the input.
* amadeus: Update GroupedBiquadFilterCommand documentation
* amadeus: Simplify PoolMapper alignment checks
* amadeus: Update Surround delay effect matrix to REV11
* amadeus: Add drop parameter support and use 32 bits integers for estimate time
Also implement accurate ExecuteAudioRendererRendering stub.
* Address gdkchan's comments
* Address gdkchan's other comments
* Address gdkchan's comment
Diffstat (limited to 'Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs')
-rw-r--r-- | Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs b/Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs index f6638a9a..2680dcb1 100644 --- a/Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs +++ b/Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs @@ -1,4 +1,5 @@ using Ryujinx.Audio.Renderer.Dsp.State; +using Ryujinx.Common.Logging; using System; using System.Diagnostics; using System.Runtime.CompilerServices; @@ -72,6 +73,19 @@ namespace Ryujinx.Audio.Renderer.Dsp } [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static short GetCoefficientAtIndex(ReadOnlySpan<short> coefficients, int index) + { + if ((uint)index > (uint)coefficients.Length) + { + Logger.Error?.Print(LogClass.AudioRenderer, $"Out of bound read for coefficient at index {index}"); + + return 0; + } + + return coefficients[index]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Decode(Span<short> output, ReadOnlySpan<byte> input, int startSampleOffset, int endSampleOffset, int offset, int count, ReadOnlySpan<short> coefficients, ref AdpcmLoopContext loopContext) { if (input.IsEmpty || endSampleOffset < startSampleOffset) @@ -84,8 +98,8 @@ namespace Ryujinx.Audio.Renderer.Dsp byte coefficientIndex = (byte)((predScale >> 4) & 0xF); short history0 = loopContext.History0; short history1 = loopContext.History1; - short coefficient0 = coefficients[coefficientIndex * 2 + 0]; - short coefficient1 = coefficients[coefficientIndex * 2 + 1]; + short coefficient0 = GetCoefficientAtIndex(coefficients, coefficientIndex * 2 + 0); + short coefficient1 = GetCoefficientAtIndex(coefficients, coefficientIndex * 2 + 1); int decodedCount = Math.Min(count, endSampleOffset - startSampleOffset - offset); int nibbles = GetNibblesFromSampleCount(offset + startSampleOffset); @@ -109,8 +123,8 @@ namespace Ryujinx.Audio.Renderer.Dsp coefficientIndex = (byte)((predScale >> 4) & 0xF); - coefficient0 = coefficients[coefficientIndex * 2 + 0]; - coefficient1 = coefficients[coefficientIndex * 2 + 1]; + coefficient0 = GetCoefficientAtIndex(coefficients, coefficientIndex * 2); + coefficient1 = GetCoefficientAtIndex(coefficients, coefficientIndex * 2 + 1); nibbles += 2; |