Skip to content

Commit

Permalink
amadeus: Fix limiter correctness (#3126)
Browse files Browse the repository at this point in the history
This fixes missing audio on Nintendo Switch Sports Online Play Test.
  • Loading branch information
marysaka authored Feb 16, 2022
1 parent 7bfb5f7 commit ab5d77c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
10 changes: 7 additions & 3 deletions Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ private unsafe void ProcessLimiter(CommandList context, ref LimiterState state)
{
for (int sampleIndex = 0; sampleIndex < context.SampleCount; sampleIndex++)
{
float inputSample = *((float*)inputBuffers[channelIndex] + sampleIndex);
float rawInputSample = *((float*)inputBuffers[channelIndex] + sampleIndex);

float sampleInputMax = Math.Abs(inputSample * Parameter.InputGain);
float inputSample = (rawInputSample / short.MaxValue) * Parameter.InputGain;

float sampleInputMax = Math.Abs(inputSample);

float inputCoefficient = Parameter.ReleaseCoefficient;

Expand Down Expand Up @@ -131,7 +133,9 @@ private unsafe void ProcessLimiter(CommandList context, ref LimiterState state)

ref float delayedSample = ref state.DelayedSampleBuffer[channelIndex * Parameter.DelayBufferSampleCountMax + state.DelayedSampleBufferPosition[channelIndex]];

*((float*)outputBuffers[channelIndex] + sampleIndex) = delayedSample * state.CompressionGain[channelIndex] * Parameter.OutputGain;
float outputSample = delayedSample * state.CompressionGain[channelIndex] * Parameter.OutputGain;

*((float*)outputBuffers[channelIndex] + sampleIndex) = outputSample * short.MaxValue;

delayedSample = inputSample;

Expand Down
10 changes: 7 additions & 3 deletions Ryujinx.Audio/Renderer/Dsp/Command/LimiterCommandVersion2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ private unsafe void ProcessLimiter(CommandList context, ref LimiterState state)
{
for (int sampleIndex = 0; sampleIndex < context.SampleCount; sampleIndex++)
{
float inputSample = *((float*)inputBuffers[channelIndex] + sampleIndex);
float rawInputSample = *((float*)inputBuffers[channelIndex] + sampleIndex);

float sampleInputMax = Math.Abs(inputSample * Parameter.InputGain);
float inputSample = (rawInputSample / short.MaxValue) * Parameter.InputGain;

float sampleInputMax = Math.Abs(inputSample);

float inputCoefficient = Parameter.ReleaseCoefficient;

Expand Down Expand Up @@ -142,7 +144,9 @@ private unsafe void ProcessLimiter(CommandList context, ref LimiterState state)

ref float delayedSample = ref state.DelayedSampleBuffer[channelIndex * Parameter.DelayBufferSampleCountMax + state.DelayedSampleBufferPosition[channelIndex]];

*((float*)outputBuffers[channelIndex] + sampleIndex) = delayedSample * state.CompressionGain[channelIndex] * Parameter.OutputGain;
float outputSample = delayedSample * state.CompressionGain[channelIndex] * Parameter.OutputGain;

*((float*)outputBuffers[channelIndex] + sampleIndex) = outputSample * short.MaxValue;

delayedSample = inputSample;

Expand Down
1 change: 1 addition & 0 deletions Ryujinx.Audio/Renderer/Dsp/State/LimiterState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public LimiterState(ref LimiterParameter parameter, ulong workBuffer)
DectectorAverage.AsSpan().Fill(0.0f);
CompressionGain.AsSpan().Fill(1.0f);
DelayedSampleBufferPosition.AsSpan().Fill(0);
DelayedSampleBuffer.AsSpan().Fill(0.0f);

UpdateParameter(ref parameter);
}
Expand Down
11 changes: 10 additions & 1 deletion Ryujinx.Audio/Renderer/Server/CommandGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,16 @@ private void GenerateLimiterEffect(uint bufferOffset, LimiterEffect effect, int

if (_rendererContext.BehaviourContext.IsEffectInfoVersion2Supported())
{
Memory<EffectResultState> dspResultState = _effectContext.GetDspStateMemory(effectId);
Memory<EffectResultState> dspResultState;

if (effect.Parameter.StatisticsEnabled)
{
dspResultState = _effectContext.GetDspStateMemory(effectId);
}
else
{
dspResultState = Memory<EffectResultState>.Empty;
}

_commandBuffer.GenerateLimiterEffectVersion2(bufferOffset, effect.Parameter, effect.State, dspResultState, effect.IsEnabled, workBuffer, nodeId);
}
Expand Down

0 comments on commit ab5d77c

Please sign in to comment.