amadeus: Update to REV10 (#2654)
* amadeus: Update to REV10 This implements all the changes made with REV10 on 13.0.0. * Address Ack's comment * Address gdkchan's comment
This commit is contained in:
parent
fe9d5a1981
commit
e17eb7bfaf
29 changed files with 923 additions and 96 deletions
|
@ -156,7 +156,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
|
|||
Span<int> outputBufferInt = MemoryMarshal.Cast<float, int>(outputBuffer);
|
||||
|
||||
// Convert input data to the target format for user (int)
|
||||
DataSourceHelper.ToInt(inputBufferInt, inputBuffer, outputBuffer.Length);
|
||||
DataSourceHelper.ToInt(inputBufferInt, inputBuffer, inputBuffer.Length);
|
||||
|
||||
// Send the input to the user
|
||||
Write(context.MemoryManager, OutputBuffer, CountMax, inputBufferInt, context.SampleCount, WriteOffset, UpdateCount);
|
||||
|
@ -177,8 +177,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
|
|||
}
|
||||
else
|
||||
{
|
||||
context.MemoryManager.Fill(BufferInfo.SendBufferInfo, (ulong)Unsafe.SizeOf<AuxiliaryBufferInfo>(), 0);
|
||||
context.MemoryManager.Fill(BufferInfo.ReturnBufferInfo, (ulong)Unsafe.SizeOf<AuxiliaryBufferInfo>(), 0);
|
||||
AuxiliaryBufferInfo.Reset(context.MemoryManager, BufferInfo.SendBufferInfo);
|
||||
AuxiliaryBufferInfo.Reset(context.MemoryManager, BufferInfo.ReturnBufferInfo);
|
||||
|
||||
if (InputBufferIndex != OutputBufferIndex)
|
||||
{
|
||||
|
|
|
@ -32,15 +32,16 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
|
|||
|
||||
public ulong EstimatedProcessingTime { get; set; }
|
||||
|
||||
public BiquadFilterParameter Parameter { get; }
|
||||
public Memory<BiquadFilterState> BiquadFilterState { get; }
|
||||
public int InputBufferIndex { get; }
|
||||
public int OutputBufferIndex { get; }
|
||||
public bool NeedInitialization { get; }
|
||||
|
||||
private BiquadFilterParameter _parameter;
|
||||
|
||||
public BiquadFilterCommand(int baseIndex, ref BiquadFilterParameter filter, Memory<BiquadFilterState> biquadFilterStateMemory, int inputBufferOffset, int outputBufferOffset, bool needInitialization, int nodeId)
|
||||
{
|
||||
Parameter = filter;
|
||||
_parameter = filter;
|
||||
BiquadFilterState = biquadFilterStateMemory;
|
||||
InputBufferIndex = baseIndex + inputBufferOffset;
|
||||
OutputBufferIndex = baseIndex + outputBufferOffset;
|
||||
|
@ -50,30 +51,6 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
|
|||
NodeId = nodeId;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private void ProcessBiquadFilter(ref BiquadFilterState state, Span<float> outputBuffer, ReadOnlySpan<float> inputBuffer, uint sampleCount)
|
||||
{
|
||||
const int fixedPointPrecisionForParameter = 14;
|
||||
|
||||
float a0 = FixedPointHelper.ToFloat(Parameter.Numerator[0], fixedPointPrecisionForParameter);
|
||||
float a1 = FixedPointHelper.ToFloat(Parameter.Numerator[1], fixedPointPrecisionForParameter);
|
||||
float a2 = FixedPointHelper.ToFloat(Parameter.Numerator[2], fixedPointPrecisionForParameter);
|
||||
|
||||
float b1 = FixedPointHelper.ToFloat(Parameter.Denominator[0], fixedPointPrecisionForParameter);
|
||||
float b2 = FixedPointHelper.ToFloat(Parameter.Denominator[1], fixedPointPrecisionForParameter);
|
||||
|
||||
for (int i = 0; i < sampleCount; i++)
|
||||
{
|
||||
float input = inputBuffer[i];
|
||||
float output = input * a0 + state.Z1;
|
||||
|
||||
state.Z1 = input * a1 + output * b1 + state.Z2;
|
||||
state.Z2 = input * a2 + output * b2;
|
||||
|
||||
outputBuffer[i] = output;
|
||||
}
|
||||
}
|
||||
|
||||
public void Process(CommandList context)
|
||||
{
|
||||
ref BiquadFilterState state = ref BiquadFilterState.Span[0];
|
||||
|
@ -86,7 +63,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
|
|||
state = new BiquadFilterState();
|
||||
}
|
||||
|
||||
ProcessBiquadFilter(ref state, outputBuffer, inputBuffer, context.SampleCount);
|
||||
BiquadFilterHelper.ProcessBiquadFilter(ref _parameter, ref state, outputBuffer, inputBuffer, context.SampleCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
154
Ryujinx.Audio/Renderer/Dsp/Command/CaptureBufferCommand.cs
Normal file
154
Ryujinx.Audio/Renderer/Dsp/Command/CaptureBufferCommand.cs
Normal file
|
@ -0,0 +1,154 @@
|
|||
//
|
||||
// Copyright (c) 2019-2021 Ryujinx
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
using Ryujinx.Audio.Renderer.Dsp.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using static Ryujinx.Audio.Renderer.Dsp.State.AuxiliaryBufferHeader;
|
||||
using CpuAddress = System.UInt64;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Dsp.Command
|
||||
{
|
||||
public class CaptureBufferCommand : ICommand
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public int NodeId { get; }
|
||||
|
||||
public CommandType CommandType => CommandType.CaptureBuffer;
|
||||
|
||||
public ulong EstimatedProcessingTime { get; set; }
|
||||
|
||||
public uint InputBufferIndex { get; }
|
||||
|
||||
public ulong CpuBufferInfoAddress { get; }
|
||||
public ulong DspBufferInfoAddress { get; }
|
||||
|
||||
public CpuAddress OutputBuffer { get; }
|
||||
public uint CountMax { get; }
|
||||
public uint UpdateCount { get; }
|
||||
public uint WriteOffset { get; }
|
||||
|
||||
public bool IsEffectEnabled { get; }
|
||||
|
||||
public CaptureBufferCommand(uint bufferOffset, byte inputBufferOffset, ulong sendBufferInfo, bool isEnabled,
|
||||
uint countMax, CpuAddress outputBuffer, uint updateCount, uint writeOffset, int nodeId)
|
||||
{
|
||||
Enabled = true;
|
||||
NodeId = nodeId;
|
||||
InputBufferIndex = bufferOffset + inputBufferOffset;
|
||||
CpuBufferInfoAddress = sendBufferInfo;
|
||||
DspBufferInfoAddress = sendBufferInfo + (ulong)Unsafe.SizeOf<AuxiliaryBufferHeader>();
|
||||
OutputBuffer = outputBuffer;
|
||||
CountMax = countMax;
|
||||
UpdateCount = updateCount;
|
||||
WriteOffset = writeOffset;
|
||||
IsEffectEnabled = isEnabled;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private uint Write(IVirtualMemoryManager memoryManager, ulong outBufferAddress, uint countMax, ReadOnlySpan<int> buffer, uint count, uint writeOffset, uint updateCount)
|
||||
{
|
||||
if (countMax == 0 || outBufferAddress == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint targetWriteOffset = writeOffset + AuxiliaryBufferInfo.GetWriteOffset(memoryManager, DspBufferInfoAddress);
|
||||
|
||||
if (targetWriteOffset > countMax)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint remaining = count;
|
||||
|
||||
uint inBufferOffset = 0;
|
||||
|
||||
while (remaining != 0)
|
||||
{
|
||||
uint countToWrite = Math.Min(countMax - targetWriteOffset, remaining);
|
||||
|
||||
memoryManager.Write(outBufferAddress + targetWriteOffset * sizeof(int), MemoryMarshal.Cast<int, byte>(buffer.Slice((int)inBufferOffset, (int)countToWrite)));
|
||||
|
||||
targetWriteOffset = (targetWriteOffset + countToWrite) % countMax;
|
||||
remaining -= countToWrite;
|
||||
inBufferOffset += countToWrite;
|
||||
}
|
||||
|
||||
if (updateCount != 0)
|
||||
{
|
||||
uint dspTotalSampleCount = AuxiliaryBufferInfo.GetTotalSampleCount(memoryManager, DspBufferInfoAddress);
|
||||
uint cpuTotalSampleCount = AuxiliaryBufferInfo.GetTotalSampleCount(memoryManager, CpuBufferInfoAddress);
|
||||
|
||||
uint totalSampleCountDiff = dspTotalSampleCount - cpuTotalSampleCount;
|
||||
|
||||
if (totalSampleCountDiff >= countMax)
|
||||
{
|
||||
uint dspLostSampleCount = AuxiliaryBufferInfo.GetLostSampleCount(memoryManager, DspBufferInfoAddress);
|
||||
uint cpuLostSampleCount = AuxiliaryBufferInfo.GetLostSampleCount(memoryManager, CpuBufferInfoAddress);
|
||||
|
||||
uint lostSampleCountDiff = dspLostSampleCount - cpuLostSampleCount;
|
||||
uint newLostSampleCount = lostSampleCountDiff + updateCount;
|
||||
|
||||
if (lostSampleCountDiff > newLostSampleCount)
|
||||
{
|
||||
newLostSampleCount = cpuLostSampleCount - 1;
|
||||
}
|
||||
|
||||
AuxiliaryBufferInfo.SetLostSampleCount(memoryManager, DspBufferInfoAddress, newLostSampleCount);
|
||||
}
|
||||
|
||||
uint newWriteOffset = (AuxiliaryBufferInfo.GetWriteOffset(memoryManager, DspBufferInfoAddress) + updateCount) % countMax;
|
||||
|
||||
AuxiliaryBufferInfo.SetWriteOffset(memoryManager, DspBufferInfoAddress, newWriteOffset);
|
||||
|
||||
uint newTotalSampleCount = totalSampleCountDiff + newWriteOffset;
|
||||
|
||||
AuxiliaryBufferInfo.SetTotalSampleCount(memoryManager, DspBufferInfoAddress, newTotalSampleCount);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public void Process(CommandList context)
|
||||
{
|
||||
Span<float> inputBuffer = context.GetBuffer((int)InputBufferIndex);
|
||||
|
||||
if (IsEffectEnabled)
|
||||
{
|
||||
Span<int> inputBufferInt = MemoryMarshal.Cast<float, int>(inputBuffer);
|
||||
|
||||
// Convert input data to the target format for user (int)
|
||||
DataSourceHelper.ToInt(inputBufferInt, inputBuffer, inputBuffer.Length);
|
||||
|
||||
// Send the input to the user
|
||||
Write(context.MemoryManager, OutputBuffer, CountMax, inputBufferInt, context.SampleCount, WriteOffset, UpdateCount);
|
||||
|
||||
// Convert back to float
|
||||
DataSourceHelper.ToFloat(inputBuffer, inputBufferInt, inputBuffer.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
AuxiliaryBufferInfo.Reset(context.MemoryManager, DspBufferInfoAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,6 +46,8 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command
|
|||
ClearMixBuffer,
|
||||
CopyMixBuffer,
|
||||
LimiterVersion1,
|
||||
LimiterVersion2
|
||||
LimiterVersion2,
|
||||
GroupedBiquadFilter,
|
||||
CaptureBuffer
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
//
|
||||
// Copyright (c) 2019-2021 Ryujinx
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
using Ryujinx.Audio.Renderer.Dsp.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Dsp.Command
|
||||
{
|
||||
public class GroupedBiquadFilterCommand : ICommand
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public int NodeId { get; }
|
||||
|
||||
public CommandType CommandType => CommandType.GroupedBiquadFilter;
|
||||
|
||||
public ulong EstimatedProcessingTime { get; set; }
|
||||
|
||||
private BiquadFilterParameter[] _parameters;
|
||||
private Memory<BiquadFilterState> _biquadFilterStates;
|
||||
private int _inputBufferIndex;
|
||||
private int _outputBufferIndex;
|
||||
private bool[] _isInitialized;
|
||||
|
||||
public GroupedBiquadFilterCommand(int baseIndex, ReadOnlySpan<BiquadFilterParameter> filters, Memory<BiquadFilterState> biquadFilterStateMemory, int inputBufferOffset, int outputBufferOffset, ReadOnlySpan<bool> isInitialized, int nodeId)
|
||||
{
|
||||
_parameters = filters.ToArray();
|
||||
_biquadFilterStates = biquadFilterStateMemory;
|
||||
_inputBufferIndex = baseIndex + inputBufferOffset;
|
||||
_outputBufferIndex = baseIndex + outputBufferOffset;
|
||||
_isInitialized = isInitialized.ToArray();
|
||||
|
||||
Enabled = true;
|
||||
NodeId = nodeId;
|
||||
}
|
||||
|
||||
public void Process(CommandList context)
|
||||
{
|
||||
Span<BiquadFilterState> states = _biquadFilterStates.Span;
|
||||
|
||||
ReadOnlySpan<float> inputBuffer = context.GetBuffer(_inputBufferIndex);
|
||||
Span<float> outputBuffer = context.GetBuffer(_outputBufferIndex);
|
||||
|
||||
for (int i = 0; i < _parameters.Length; i++)
|
||||
{
|
||||
if (!_isInitialized[i])
|
||||
{
|
||||
states[i] = new BiquadFilterState();
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Nintendo also implements a hot path for double biquad filters, but no generic path when the command definition suggests it could be done.
|
||||
// As such we currently only implement a generic path for simplicity.
|
||||
// TODO: Implement double biquad filters fast path.
|
||||
if (_parameters.Length == 1)
|
||||
{
|
||||
BiquadFilterHelper.ProcessBiquadFilter(ref _parameters[0], ref states[0], outputBuffer, inputBuffer, context.SampleCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
BiquadFilterHelper.ProcessBiquadFilter(_parameters, states, outputBuffer, inputBuffer, context.SampleCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue