diff options
Diffstat (limited to 'Ryujinx.Audio/Renderer/Dsp/ResamplerHelper.cs')
-rw-r--r-- | Ryujinx.Audio/Renderer/Dsp/ResamplerHelper.cs | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/Ryujinx.Audio/Renderer/Dsp/ResamplerHelper.cs b/Ryujinx.Audio/Renderer/Dsp/ResamplerHelper.cs index 4de2e078a..b46a33fe0 100644 --- a/Ryujinx.Audio/Renderer/Dsp/ResamplerHelper.cs +++ b/Ryujinx.Audio/Renderer/Dsp/ResamplerHelper.cs | |||
@@ -579,52 +579,5 @@ namespace Ryujinx.Audio.Renderer.Dsp | |||
579 | fraction -= (int)fraction; | 579 | fraction -= (int)fraction; |
580 | } | 580 | } |
581 | } | 581 | } |
582 | |||
583 | [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
584 | public static void ResampleForUpsampler(Span<float> outputBuffer, ReadOnlySpan<float> inputBuffer, float ratio, ref float fraction, int sampleCount) | ||
585 | { | ||
586 | // Currently a simple cubic interpolation, assuming duplicated values at edges. | ||
587 | // TODO: Discover and use algorithm that the switch uses. | ||
588 | |||
589 | int inputBufferIndex = 0; | ||
590 | int maxIndex = inputBuffer.Length - 1; | ||
591 | int cubicEnd = inputBuffer.Length - 3; | ||
592 | |||
593 | for (int i = 0; i < sampleCount; i++) | ||
594 | { | ||
595 | float s0, s1, s2, s3; | ||
596 | |||
597 | s1 = inputBuffer[inputBufferIndex]; | ||
598 | |||
599 | if (inputBufferIndex == 0 || inputBufferIndex > cubicEnd) | ||
600 | { | ||
601 | // Clamp interplation values at the ends of the input buffer. | ||
602 | s0 = inputBuffer[Math.Max(0, inputBufferIndex - 1)]; | ||
603 | s2 = inputBuffer[Math.Min(maxIndex, inputBufferIndex + 1)]; | ||
604 | s3 = inputBuffer[Math.Min(maxIndex, inputBufferIndex + 2)]; | ||
605 | } | ||
606 | else | ||
607 | { | ||
608 | s0 = inputBuffer[inputBufferIndex - 1]; | ||
609 | s2 = inputBuffer[inputBufferIndex + 1]; | ||
610 | s3 = inputBuffer[inputBufferIndex + 2]; | ||
611 | } | ||
612 | |||
613 | float a = s3 - s2 - s0 + s1; | ||
614 | float b = s0 - s1 - a; | ||
615 | float c = s2 - s0; | ||
616 | float d = s1; | ||
617 | |||
618 | float f2 = fraction * fraction; | ||
619 | float f3 = f2 * fraction; | ||
620 | |||
621 | outputBuffer[i] = a * f3 + b * f2 + c * fraction + d; | ||
622 | |||
623 | fraction += ratio; | ||
624 | inputBufferIndex += (int)MathF.Truncate(fraction); | ||
625 | |||
626 | fraction -= (int)fraction; | ||
627 | } | ||
628 | } | ||
629 | } | 582 | } |
630 | } \ No newline at end of file | 583 | } \ No newline at end of file |