aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs')
-rw-r--r--Ryujinx.Audio/Renderer/Dsp/AdpcmHelper.cs22
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;