mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2026-05-21 04:35:46 +00:00
audio effects fix and audio object pooling (ryubing/ryujinx!192)
See merge request ryubing/ryujinx!192
This commit is contained in:
@@ -8,6 +8,7 @@ using Ryujinx.Audio.Renderer.Server.Sink;
|
||||
using Ryujinx.Audio.Renderer.Server.Splitter;
|
||||
using Ryujinx.Audio.Renderer.Server.Upsampler;
|
||||
using Ryujinx.Audio.Renderer.Server.Voice;
|
||||
using Ryujinx.Common;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using CpuAddress = System.UInt64;
|
||||
@@ -34,6 +35,170 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// </summary>
|
||||
public CommandList CommandList { get; }
|
||||
|
||||
private readonly static ObjectPool<PcmInt16DataSourceCommandVersion1> _pcmInt16DataSourceCommandVersion1Pool = new(() => new PcmInt16DataSourceCommandVersion1());
|
||||
private readonly static ObjectPool<PcmFloatDataSourceCommandVersion1> _pcmFloatDataSourceCommandVersion1Pool = new(() => new PcmFloatDataSourceCommandVersion1());
|
||||
private readonly static ObjectPool<AdpcmDataSourceCommandVersion1> _adpcmDataSourceCommandVersion1Pool = new(() => new AdpcmDataSourceCommandVersion1());
|
||||
private readonly static ObjectPool<DataSourceVersion2Command> _dataSourceVersion2CommandPool = new(() => new DataSourceVersion2Command());
|
||||
private readonly static ObjectPool<VolumeCommand> _volumeCommandPool = new(() => new VolumeCommand());
|
||||
private readonly static ObjectPool<VolumeRampCommand> _volumeRampCommandPool = new(() => new VolumeRampCommand());
|
||||
private readonly static ObjectPool<BiquadFilterCommand> _biquadFilterCommandPool = new(() => new BiquadFilterCommand());
|
||||
private readonly static ObjectPool<MixCommand> _mixCommandPool = new(() => new MixCommand());
|
||||
private readonly static ObjectPool<MixRampCommand> _mixRampCommandPool = new(() => new MixRampCommand());
|
||||
private readonly static ObjectPool<MixRampGroupedCommand> _mixRampGroupedCommandPool = new(() => new MixRampGroupedCommand());
|
||||
private readonly static ObjectPool<DepopPrepareCommand> _depopPrepareCommandPool = new(() => new DepopPrepareCommand());
|
||||
private readonly static ObjectPool<DepopForMixBuffersCommand> _depopForMixBuffersCommandPool = new(() => new DepopForMixBuffersCommand());
|
||||
private readonly static ObjectPool<DelayCommand> _delayCommandPool = new(() => new DelayCommand());
|
||||
private readonly static ObjectPool<UpsampleCommand> _upsampleCommandPool = new(() => new UpsampleCommand());
|
||||
private readonly static ObjectPool<DownMixSurroundToStereoCommand> _downMixSurroundToStereoCommandPool = new(() => new DownMixSurroundToStereoCommand());
|
||||
private readonly static ObjectPool<AuxiliaryBufferCommand> _auxiliaryBufferCommandPool = new(() => new AuxiliaryBufferCommand());
|
||||
private readonly static ObjectPool<DeviceSinkCommand> _deviceSinkCommandPool = new(() => new DeviceSinkCommand());
|
||||
private readonly static ObjectPool<CircularBufferSinkCommand> _circularBufferSinkCommandPool = new(() => new CircularBufferSinkCommand());
|
||||
private readonly static ObjectPool<ReverbCommand> _reverbCommandPool = new(() => new ReverbCommand());
|
||||
private readonly static ObjectPool<Reverb3dCommand> _reverb3dCommandPool = new(() => new Reverb3dCommand());
|
||||
private readonly static ObjectPool<PerformanceCommand> _performanceCommandPool = new(() => new PerformanceCommand());
|
||||
private readonly static ObjectPool<ClearMixBufferCommand> _clearMixBufferCommandPool = new(() => new ClearMixBufferCommand());
|
||||
private readonly static ObjectPool<CopyMixBufferCommand> _copyMixBufferCommandPool = new(() => new CopyMixBufferCommand());
|
||||
private readonly static ObjectPool<LimiterCommandVersion1> _limiterCommandVersion1Pool = new(() => new LimiterCommandVersion1());
|
||||
private readonly static ObjectPool<LimiterCommandVersion2> _limiterCommandVersion2Pool = new(() => new LimiterCommandVersion2());
|
||||
private readonly static ObjectPool<MultiTapBiquadFilterCommand> _multiTapBiquadFilterCommandPool = new(() => new MultiTapBiquadFilterCommand());
|
||||
private readonly static ObjectPool<CaptureBufferCommand> _captureBufferCommandPool = new(() => new CaptureBufferCommand());
|
||||
private readonly static ObjectPool<CompressorCommand> _compressorCommandPool = new(() => new CompressorCommand());
|
||||
private readonly static ObjectPool<BiquadFilterAndMixCommand> _biquadFilterAndMixCommandPool = new(() => new BiquadFilterAndMixCommand());
|
||||
private readonly static ObjectPool<MultiTapBiquadFilterAndMixCommand> _multiTapBiquadFilterAndMixCommandPool = new(() => new MultiTapBiquadFilterAndMixCommand());
|
||||
private readonly static ObjectPool<FillBufferCommand> _fillBufferCommandPool = new(() => new FillBufferCommand());
|
||||
|
||||
public static void ReleaseCommand(ICommand command)
|
||||
{
|
||||
switch (command.CommandType)
|
||||
{
|
||||
case CommandType.PcmInt16DataSourceVersion1:
|
||||
_pcmInt16DataSourceCommandVersion1Pool.Release((PcmInt16DataSourceCommandVersion1)command);
|
||||
break;
|
||||
case CommandType.PcmInt16DataSourceVersion2:
|
||||
_dataSourceVersion2CommandPool.Release((DataSourceVersion2Command)command);
|
||||
break;
|
||||
case CommandType.PcmFloatDataSourceVersion1:
|
||||
_pcmFloatDataSourceCommandVersion1Pool.Release((PcmFloatDataSourceCommandVersion1)command);
|
||||
break;
|
||||
case CommandType.PcmFloatDataSourceVersion2:
|
||||
_dataSourceVersion2CommandPool.Release((DataSourceVersion2Command)command);
|
||||
break;
|
||||
case CommandType.AdpcmDataSourceVersion1:
|
||||
_adpcmDataSourceCommandVersion1Pool.Release((AdpcmDataSourceCommandVersion1)command);
|
||||
break;
|
||||
case CommandType.AdpcmDataSourceVersion2:
|
||||
_dataSourceVersion2CommandPool.Release((DataSourceVersion2Command)command);
|
||||
break;
|
||||
case CommandType.Volume:
|
||||
_volumeCommandPool.Release((VolumeCommand)command);
|
||||
break;
|
||||
case CommandType.VolumeRamp:
|
||||
_volumeRampCommandPool.Release((VolumeRampCommand)command);
|
||||
break;
|
||||
case CommandType.BiquadFilter:
|
||||
_biquadFilterCommandPool.Release((BiquadFilterCommand)command);
|
||||
break;
|
||||
case CommandType.BiquadFilterFloatCoeff:
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
case CommandType.Mix:
|
||||
_mixCommandPool.Release((MixCommand)command);
|
||||
break;
|
||||
case CommandType.MixRamp:
|
||||
_mixRampCommandPool.Release((MixRampCommand)command);
|
||||
break;
|
||||
case CommandType.MixRampGrouped:
|
||||
_mixRampGroupedCommandPool.Release((MixRampGroupedCommand)command);
|
||||
break;
|
||||
case CommandType.DepopPrepare:
|
||||
_depopPrepareCommandPool.Release((DepopPrepareCommand)command);
|
||||
break;
|
||||
case CommandType.DepopForMixBuffers:
|
||||
_depopForMixBuffersCommandPool.Release((DepopForMixBuffersCommand)command);
|
||||
break;
|
||||
case CommandType.Delay:
|
||||
_delayCommandPool.Release((DelayCommand)command);
|
||||
break;
|
||||
case CommandType.Upsample:
|
||||
_upsampleCommandPool.Release((UpsampleCommand)command);
|
||||
break;
|
||||
case CommandType.DownMixSurroundToStereo:
|
||||
_downMixSurroundToStereoCommandPool.Release((DownMixSurroundToStereoCommand)command);
|
||||
break;
|
||||
case CommandType.AuxiliaryBuffer:
|
||||
_auxiliaryBufferCommandPool.Release((AuxiliaryBufferCommand)command);
|
||||
break;
|
||||
case CommandType.DeviceSink:
|
||||
_deviceSinkCommandPool.Release((DeviceSinkCommand)command);
|
||||
break;
|
||||
case CommandType.CircularBufferSink:
|
||||
_circularBufferSinkCommandPool.Release((CircularBufferSinkCommand)command);
|
||||
break;
|
||||
case CommandType.Reverb:
|
||||
_reverbCommandPool.Release((ReverbCommand)command);
|
||||
break;
|
||||
case CommandType.Reverb3d:
|
||||
_reverb3dCommandPool.Release((Reverb3dCommand)command);
|
||||
break;
|
||||
case CommandType.Performance:
|
||||
_performanceCommandPool.Release((PerformanceCommand)command);
|
||||
break;
|
||||
case CommandType.ClearMixBuffer:
|
||||
_clearMixBufferCommandPool.Release((ClearMixBufferCommand)command);
|
||||
break;
|
||||
case CommandType.CopyMixBuffer:
|
||||
_copyMixBufferCommandPool.Release((CopyMixBufferCommand)command);
|
||||
break;
|
||||
case CommandType.LimiterVersion1:
|
||||
_limiterCommandVersion1Pool.Release((LimiterCommandVersion1)command);
|
||||
break;
|
||||
case CommandType.LimiterVersion2:
|
||||
_limiterCommandVersion2Pool.Release((LimiterCommandVersion2)command);
|
||||
break;
|
||||
case CommandType.MultiTapBiquadFilter:
|
||||
_multiTapBiquadFilterCommandPool.Release((MultiTapBiquadFilterCommand)command);
|
||||
break;
|
||||
case CommandType.MultiTapBiquadFilterFloatCoeff:
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
case CommandType.CaptureBuffer:
|
||||
_captureBufferCommandPool.Release((CaptureBufferCommand)command);
|
||||
break;
|
||||
case CommandType.Compressor:
|
||||
_compressorCommandPool.Release((CompressorCommand)command);
|
||||
break;
|
||||
case CommandType.BiquadFilterAndMix:
|
||||
_biquadFilterAndMixCommandPool.Release((BiquadFilterAndMixCommand)command);
|
||||
break;
|
||||
case CommandType.BiquadFilterAndMixFloatCoeff:
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
case CommandType.MultiTapBiquadFilterAndMix:
|
||||
_multiTapBiquadFilterAndMixCommandPool.Release((MultiTapBiquadFilterAndMixCommand)command);
|
||||
break;
|
||||
case CommandType.MultiTapBiquadFilterAndMixFloatCoef:
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
case CommandType.AuxiliaryBufferGrouped:
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
case CommandType.FillMixBuffer:
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
case CommandType.BiquadFilterCrossFade:
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
case CommandType.MultiTapBiquadFilterCrossFade:
|
||||
throw new NotImplementedException();
|
||||
break;
|
||||
case CommandType.FillBuffer:
|
||||
_fillBufferCommandPool.Release((FillBufferCommand)command);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="CommandBuffer"/>.
|
||||
/// </summary>
|
||||
@@ -63,7 +228,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateClearMixBuffer(int nodeId)
|
||||
{
|
||||
ClearMixBufferCommand command = new(nodeId);
|
||||
ClearMixBufferCommand command = _clearMixBufferCommandPool.Allocate().Initialize(nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -81,7 +246,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="wasPlaying">Set to true if the voice was playing previously.</param>
|
||||
public void GenerateDepopPrepare(Memory<VoiceState> state, Memory<float> depopBuffer, uint bufferCount, uint bufferOffset, int nodeId, bool wasPlaying)
|
||||
{
|
||||
DepopPrepareCommand command = new(state, depopBuffer, bufferCount, bufferOffset, nodeId, wasPlaying);
|
||||
DepopPrepareCommand command = _depopPrepareCommandPool.Allocate().Initialize(state, depopBuffer, bufferCount, bufferOffset, nodeId, wasPlaying);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -96,7 +261,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GeneratePerformance(ref PerformanceEntryAddresses performanceEntryAddresses, PerformanceCommand.Type type, int nodeId)
|
||||
{
|
||||
PerformanceCommand command = new(ref performanceEntryAddresses, type, nodeId);
|
||||
PerformanceCommand command = _performanceCommandPool.Allocate().Initialize(ref performanceEntryAddresses, type, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -112,7 +277,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateVolumeRamp(float previousVolume, float volume, uint bufferIndex, int nodeId)
|
||||
{
|
||||
VolumeRampCommand command = new(previousVolume, volume, bufferIndex, nodeId);
|
||||
VolumeRampCommand command = _volumeRampCommandPool.Allocate().Initialize(previousVolume, volume, bufferIndex, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -129,7 +294,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateDataSourceVersion2(ref VoiceInfo voiceInfo, Memory<VoiceState> state, ushort outputBufferIndex, ushort channelIndex, int nodeId)
|
||||
{
|
||||
DataSourceVersion2Command command = new(ref voiceInfo, state, outputBufferIndex, channelIndex, nodeId);
|
||||
DataSourceVersion2Command command = _dataSourceVersion2CommandPool.Allocate().Initialize(ref voiceInfo, state, outputBufferIndex, channelIndex, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -146,7 +311,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GeneratePcmInt16DataSourceVersion1(ref VoiceInfo voiceInfo, Memory<VoiceState> state, ushort outputBufferIndex, ushort channelIndex, int nodeId)
|
||||
{
|
||||
PcmInt16DataSourceCommandVersion1 command = new(ref voiceInfo, state, outputBufferIndex, channelIndex, nodeId);
|
||||
PcmInt16DataSourceCommandVersion1 command = _pcmInt16DataSourceCommandVersion1Pool.Allocate().Initialize(ref voiceInfo, state, outputBufferIndex, channelIndex, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -163,7 +328,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GeneratePcmFloatDataSourceVersion1(ref VoiceInfo voiceInfo, Memory<VoiceState> state, ushort outputBufferIndex, ushort channelIndex, int nodeId)
|
||||
{
|
||||
PcmFloatDataSourceCommandVersion1 command = new(ref voiceInfo, state, outputBufferIndex, channelIndex, nodeId);
|
||||
PcmFloatDataSourceCommandVersion1 command = _pcmFloatDataSourceCommandVersion1Pool.Allocate().Initialize(ref voiceInfo, state, outputBufferIndex, channelIndex, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -179,7 +344,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateAdpcmDataSourceVersion1(ref VoiceInfo voiceInfo, Memory<VoiceState> state, ushort outputBufferIndex, int nodeId)
|
||||
{
|
||||
AdpcmDataSourceCommandVersion1 command = new(ref voiceInfo, state, outputBufferIndex, nodeId);
|
||||
AdpcmDataSourceCommandVersion1 command = _adpcmDataSourceCommandVersion1Pool.Allocate().Initialize(ref voiceInfo, state, outputBufferIndex, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -198,7 +363,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateBiquadFilter(int baseIndex, ref BiquadFilterParameter2 filter, Memory<BiquadFilterState> biquadFilterStateMemory, int inputBufferOffset, int outputBufferOffset, bool needInitialization, int nodeId)
|
||||
{
|
||||
BiquadFilterCommand command = new(baseIndex, ref filter, biquadFilterStateMemory, inputBufferOffset, outputBufferOffset, needInitialization, nodeId);
|
||||
BiquadFilterCommand command = _biquadFilterCommandPool.Allocate().Initialize(baseIndex, ref filter, biquadFilterStateMemory, inputBufferOffset, outputBufferOffset, needInitialization, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -217,7 +382,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateMultiTapBiquadFilter(int baseIndex, ReadOnlySpan<BiquadFilterParameter2> filters, Memory<BiquadFilterState> biquadFilterStatesMemory, int inputBufferOffset, int outputBufferOffset, ReadOnlySpan<bool> isInitialized, int nodeId)
|
||||
{
|
||||
MultiTapBiquadFilterCommand command = new(baseIndex, filters, biquadFilterStatesMemory, inputBufferOffset, outputBufferOffset, isInitialized, nodeId);
|
||||
MultiTapBiquadFilterCommand command = _multiTapBiquadFilterCommandPool.Allocate().Initialize(baseIndex, filters, biquadFilterStatesMemory, inputBufferOffset, outputBufferOffset, isInitialized, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -236,7 +401,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateMixRampGrouped(uint mixBufferCount, uint inputBufferIndex, uint outputBufferIndex, ReadOnlySpan<float> previousVolume, ReadOnlySpan<float> volume, Memory<VoiceState> state, int nodeId)
|
||||
{
|
||||
MixRampGroupedCommand command = new(mixBufferCount, inputBufferIndex, outputBufferIndex, previousVolume, volume, state, nodeId);
|
||||
MixRampGroupedCommand command = _mixRampGroupedCommandPool.Allocate().Initialize(mixBufferCount, inputBufferIndex, outputBufferIndex, previousVolume, volume, state, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -255,7 +420,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateMixRamp(float previousVolume, float volume, uint inputBufferIndex, uint outputBufferIndex, int lastSampleIndex, Memory<VoiceState> state, int nodeId)
|
||||
{
|
||||
MixRampCommand command = new(previousVolume, volume, inputBufferIndex, outputBufferIndex, lastSampleIndex, state, nodeId);
|
||||
MixRampCommand command = _mixRampCommandPool.Allocate().Initialize(previousVolume, volume, inputBufferIndex, outputBufferIndex, lastSampleIndex, state, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -293,7 +458,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
bool isFirstMixBuffer,
|
||||
int nodeId)
|
||||
{
|
||||
BiquadFilterAndMixCommand command = new(
|
||||
BiquadFilterAndMixCommand command = _biquadFilterAndMixCommandPool.Allocate().Initialize(
|
||||
previousVolume,
|
||||
volume,
|
||||
inputBufferIndex,
|
||||
@@ -352,7 +517,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
bool isFirstMixBuffer,
|
||||
int nodeId)
|
||||
{
|
||||
MultiTapBiquadFilterAndMixCommand command = new(
|
||||
MultiTapBiquadFilterAndMixCommand command = _multiTapBiquadFilterAndMixCommandPool.Allocate().Initialize(
|
||||
previousVolume,
|
||||
volume,
|
||||
inputBufferIndex,
|
||||
@@ -386,7 +551,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="sampleRate">The target sample rate in use.</param>
|
||||
public void GenerateDepopForMixBuffers(Memory<float> depopBuffer, uint bufferOffset, uint bufferCount, int nodeId, uint sampleRate)
|
||||
{
|
||||
DepopForMixBuffersCommand command = new(depopBuffer, bufferOffset, bufferCount, nodeId, sampleRate);
|
||||
DepopForMixBuffersCommand command = _depopForMixBuffersCommandPool.Allocate().Initialize(depopBuffer, bufferOffset, bufferCount, nodeId, sampleRate);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -401,7 +566,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateCopyMixBuffer(uint inputBufferIndex, uint outputBufferIndex, int nodeId)
|
||||
{
|
||||
CopyMixBufferCommand command = new(inputBufferIndex, outputBufferIndex, nodeId);
|
||||
CopyMixBufferCommand command = _copyMixBufferCommandPool.Allocate().Initialize(inputBufferIndex, outputBufferIndex, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -417,7 +582,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="volume">The mix volume.</param>
|
||||
public void GenerateMix(uint inputBufferIndex, uint outputBufferIndex, int nodeId, float volume)
|
||||
{
|
||||
MixCommand command = new(inputBufferIndex, outputBufferIndex, nodeId, volume);
|
||||
MixCommand command = _mixCommandPool.Allocate().Initialize(inputBufferIndex, outputBufferIndex, nodeId, volume);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -439,7 +604,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
if (parameter.IsChannelCountValid())
|
||||
{
|
||||
ReverbCommand command = new(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, isLongSizePreDelaySupported, newEffectChannelMappingSupported);
|
||||
ReverbCommand command = _reverbCommandPool.Allocate().Initialize(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, isLongSizePreDelaySupported, newEffectChannelMappingSupported);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -461,7 +626,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
if (parameter.IsChannelCountValid())
|
||||
{
|
||||
Reverb3dCommand command = new(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, newEffectChannelMappingSupported);
|
||||
Reverb3dCommand command = _reverb3dCommandPool.Allocate().Initialize(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, newEffectChannelMappingSupported);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -483,7 +648,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
if (parameter.IsChannelCountValid())
|
||||
{
|
||||
DelayCommand command = new(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, newEffectChannelMappingSupported);
|
||||
DelayCommand command = _delayCommandPool.Allocate().Initialize(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, newEffectChannelMappingSupported);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -504,7 +669,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
if (parameter.IsChannelCountValid())
|
||||
{
|
||||
LimiterCommandVersion1 command = new(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId);
|
||||
LimiterCommandVersion1 command = _limiterCommandVersion1Pool.Allocate().Initialize(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -526,7 +691,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
if (parameter.IsChannelCountValid())
|
||||
{
|
||||
LimiterCommandVersion2 command = new(bufferOffset, parameter, state, effectResultState, isEnabled, workBuffer, nodeId);
|
||||
LimiterCommandVersion2 command = _limiterCommandVersion2Pool.Allocate().Initialize(bufferOffset, parameter, state, effectResultState, isEnabled, workBuffer, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -552,7 +717,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
if (state.SendBufferInfoBase != 0 && state.ReturnBufferInfoBase != 0)
|
||||
{
|
||||
AuxiliaryBufferCommand command = new(bufferOffset, inputBufferOffset, outputBufferOffset, ref state, isEnabled, countMax, outputBuffer, inputBuffer, updateCount, writeOffset, nodeId);
|
||||
AuxiliaryBufferCommand command = _auxiliaryBufferCommandPool.Allocate().Initialize(bufferOffset, inputBufferOffset, outputBufferOffset, ref state, isEnabled, countMax, outputBuffer, inputBuffer, updateCount, writeOffset, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -576,7 +741,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
if (sendBufferInfo != 0)
|
||||
{
|
||||
CaptureBufferCommand command = new(bufferOffset, inputBufferOffset, sendBufferInfo, isEnabled, countMax, outputBuffer, updateCount, writeOffset, nodeId);
|
||||
CaptureBufferCommand command = _captureBufferCommandPool.Allocate().Initialize(bufferOffset, inputBufferOffset, sendBufferInfo, isEnabled, countMax, outputBuffer, updateCount, writeOffset, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -597,7 +762,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
if (parameter.IsChannelCountValid())
|
||||
{
|
||||
CompressorCommand command = new(bufferOffset, parameter, state, effectResultState, isEnabled, nodeId);
|
||||
CompressorCommand command = _compressorCommandPool.Allocate().Initialize(bufferOffset, parameter, state, effectResultState, isEnabled, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -613,7 +778,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateVolume(float volume, uint bufferOffset, int nodeId)
|
||||
{
|
||||
VolumeCommand command = new(volume, bufferOffset, nodeId);
|
||||
VolumeCommand command = _volumeCommandPool.Allocate().Initialize(volume, bufferOffset, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -628,7 +793,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateCircularBuffer(uint bufferOffset, CircularBufferSink sink, int nodeId)
|
||||
{
|
||||
CircularBufferSinkCommand command = new(bufferOffset, ref sink.Parameter, ref sink.CircularBufferAddressInfo, sink.CurrentWriteOffset, nodeId);
|
||||
CircularBufferSinkCommand command = _circularBufferSinkCommandPool.Allocate().Initialize(bufferOffset, ref sink.Parameter, ref sink.CircularBufferAddressInfo, sink.CurrentWriteOffset, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -645,7 +810,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateDownMixSurroundToStereo(uint bufferOffset, Span<byte> inputBufferOffset, Span<byte> outputBufferOffset, float[] downMixParameter, int nodeId)
|
||||
{
|
||||
DownMixSurroundToStereoCommand command = new(bufferOffset, inputBufferOffset, outputBufferOffset, downMixParameter, nodeId);
|
||||
DownMixSurroundToStereoCommand command = _downMixSurroundToStereoCommandPool.Allocate().Initialize(bufferOffset, inputBufferOffset, outputBufferOffset, downMixParameter, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -665,7 +830,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateUpsample(uint bufferOffset, UpsamplerInfo upsampler, uint inputCount, Span<byte> inputBufferOffset, uint bufferCountPerSample, uint sampleCount, uint sampleRate, int nodeId)
|
||||
{
|
||||
UpsampleCommand command = new(bufferOffset, upsampler, inputCount, inputBufferOffset, bufferCountPerSample, sampleCount, sampleRate, nodeId);
|
||||
UpsampleCommand command = _upsampleCommandPool.Allocate().Initialize(bufferOffset, upsampler, inputCount, inputBufferOffset, bufferCountPerSample, sampleCount, sampleRate, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -682,7 +847,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
/// <param name="nodeId">The node id associated to this command.</param>
|
||||
public void GenerateDeviceSink(uint bufferOffset, DeviceSink sink, int sessionId, Memory<float> buffer, int nodeId)
|
||||
{
|
||||
DeviceSinkCommand command = new(bufferOffset, sink, sessionId, buffer, nodeId);
|
||||
DeviceSinkCommand command = _deviceSinkCommandPool.Allocate().Initialize(bufferOffset, sink, sessionId, buffer, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
@@ -691,16 +856,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
public void GenerateFillBuffer(SplitterDestination destination, float value, int length, int nodeId)
|
||||
{
|
||||
FillBufferCommand command;
|
||||
|
||||
if (Unsafe.IsNullRef(ref destination.GetV2RefOrNull()))
|
||||
{
|
||||
command = new(destination.GetV1RefOrNull(), length, value, nodeId);
|
||||
}
|
||||
else
|
||||
{
|
||||
command = new(destination.GetV2RefOrNull(), length, value, nodeId);
|
||||
}
|
||||
FillBufferCommand command = _fillBufferCommandPool.Allocate().Initialize(destination, length, value, nodeId);
|
||||
|
||||
command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
|
||||
|
||||
|
||||
@@ -339,7 +339,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
bool performanceInitialized = false;
|
||||
|
||||
PerformanceEntryAddresses performanceEntry = new();
|
||||
PerformanceEntryAddresses performanceEntry = null;
|
||||
|
||||
if (_performanceManager != null && _performanceManager.IsTargetNodeId(nodeId) && _performanceManager.GetNextEntry(out performanceEntry, dataSourceDetailType, PerformanceEntryType.Voice, nodeId))
|
||||
{
|
||||
@@ -500,7 +500,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
int nodeId = sortedInfo.NodeId;
|
||||
|
||||
PerformanceEntryAddresses performanceEntry = new();
|
||||
PerformanceEntryAddresses performanceEntry = null;
|
||||
|
||||
bool performanceInitialized = false;
|
||||
|
||||
@@ -786,7 +786,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
bool isFinalMix = mix.MixId == Constants.FinalMixId;
|
||||
|
||||
PerformanceEntryAddresses performanceEntry = new();
|
||||
PerformanceEntryAddresses performanceEntry = null;
|
||||
|
||||
bool performanceInitialized = false;
|
||||
|
||||
@@ -1050,7 +1050,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
GenerateEffects(ref subMix);
|
||||
|
||||
PerformanceEntryAddresses performanceEntry = new();
|
||||
PerformanceEntryAddresses performanceEntry = null;
|
||||
|
||||
int nodeId = subMix.NodeId;
|
||||
|
||||
@@ -1081,7 +1081,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
int nodeId = sortedInfo.NodeId;
|
||||
|
||||
PerformanceEntryAddresses performanceEntry = new();
|
||||
PerformanceEntryAddresses performanceEntry = null;
|
||||
|
||||
bool performanceInitialized = false;
|
||||
|
||||
@@ -1115,7 +1115,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
GenerateEffects(ref finalMix);
|
||||
|
||||
PerformanceEntryAddresses performanceEntry = new();
|
||||
PerformanceEntryAddresses performanceEntry = null;
|
||||
|
||||
int nodeId = finalMix.NodeId;
|
||||
|
||||
@@ -1164,7 +1164,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
int nodeId = _mixContext.GetFinalState().NodeId;
|
||||
|
||||
PerformanceEntryAddresses performanceEntry = new();
|
||||
PerformanceEntryAddresses performanceEntry = null;
|
||||
|
||||
bool performanceInitialized = false;
|
||||
|
||||
@@ -1244,7 +1244,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
{
|
||||
bool performanceInitialized = false;
|
||||
|
||||
PerformanceEntryAddresses performanceEntry = new();
|
||||
PerformanceEntryAddresses performanceEntry = null;
|
||||
|
||||
if (_performanceManager != null && _performanceManager.GetNextEntry(out performanceEntry, PerformanceEntryType.Sink, sink.NodeId))
|
||||
{
|
||||
|
||||
@@ -174,19 +174,6 @@ namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
|
||||
updateErrorInfo = new ErrorInfo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the internal state from a user version 3 parameter.
|
||||
/// </summary>
|
||||
/// <param name="updateErrorInfo">The possible <see cref="ErrorInfo"/> that was generated.</param>
|
||||
/// <param name="parameter">The user parameter.</param>
|
||||
/// <param name="mapper">The mapper to use.</param>
|
||||
public virtual void Update(out ErrorInfo updateErrorInfo, in EffectInParameterVersion3 parameter, PoolMapper mapper)
|
||||
{
|
||||
Debug.Assert(IsTypeValid(in parameter));
|
||||
|
||||
updateErrorInfo = new ErrorInfo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the work buffer DSP address at the given index.
|
||||
|
||||
@@ -25,13 +25,19 @@ namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
/// </summary>
|
||||
public Memory<BiquadFilterState> State { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The biquad filter effect version.
|
||||
/// </summary>
|
||||
public int BiquadFilterEffectVersion;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="BiquadFilterEffect"/>.
|
||||
/// </summary>
|
||||
public BiquadFilterEffect()
|
||||
public BiquadFilterEffect(int version)
|
||||
{
|
||||
Parameter = new BiquadFilterEffectParameter2();
|
||||
State = new BiquadFilterState[Constants.ChannelCountMax];
|
||||
BiquadFilterEffectVersion = version;
|
||||
}
|
||||
|
||||
public override EffectType TargetEffectType => EffectType.BiquadFilter;
|
||||
@@ -45,11 +51,6 @@ namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
{
|
||||
Update(out updateErrorInfo, in parameter, mapper);
|
||||
}
|
||||
|
||||
public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, in EffectInParameterVersion3 parameter, PoolMapper mapper)
|
||||
{
|
||||
Update(out updateErrorInfo, in parameter, mapper);
|
||||
}
|
||||
|
||||
public void Update<T>(out BehaviourParameter.ErrorInfo updateErrorInfo, in T parameter, PoolMapper mapper) where T : unmanaged, IEffectInParameter
|
||||
{
|
||||
@@ -57,7 +58,7 @@ namespace Ryujinx.Audio.Renderer.Server.Effect
|
||||
|
||||
UpdateParameterBase(in parameter);
|
||||
|
||||
if (typeof(T) == typeof(EffectInParameterVersion3))
|
||||
if (BiquadFilterEffectVersion == 2)
|
||||
{
|
||||
Parameter = MemoryMarshal.Cast<byte, BiquadFilterEffectParameter2>(parameter.SpecificData)[0];
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Ryujinx.Common;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.Audio.Renderer.Server.Performance
|
||||
@@ -7,6 +8,8 @@ namespace Ryujinx.Audio.Renderer.Server.Performance
|
||||
/// </summary>
|
||||
public class PerformanceEntryAddresses
|
||||
{
|
||||
public static readonly ObjectPool<PerformanceEntryAddresses> PerformanceEntryAddressesPool = new(() => new PerformanceEntryAddresses());
|
||||
|
||||
/// <summary>
|
||||
/// The memory storing the performance entry.
|
||||
/// </summary>
|
||||
@@ -52,5 +55,10 @@ namespace Ryujinx.Audio.Renderer.Server.Performance
|
||||
{
|
||||
BaseMemory.Span[(int)ProcessingTimeOffset / 4] = (int)(endTimeNano / 1000) - BaseMemory.Span[(int)StartTimeOffset / 4];
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,11 +208,9 @@ namespace Ryujinx.Audio.Renderer.Server.Performance
|
||||
|
||||
public override bool GetNextEntry(out PerformanceEntryAddresses performanceEntry, PerformanceEntryType entryType, int nodeId)
|
||||
{
|
||||
performanceEntry = new PerformanceEntryAddresses
|
||||
{
|
||||
BaseMemory = SpanMemoryManager<int>.Cast(CurrentBuffer),
|
||||
EntryCountOffset = (uint)CurrentHeader.GetEntryCountOffset(),
|
||||
};
|
||||
performanceEntry = PerformanceEntryAddresses.PerformanceEntryAddressesPool.Allocate();
|
||||
performanceEntry.BaseMemory = SpanMemoryManager<int>.Cast(CurrentBuffer);
|
||||
performanceEntry.EntryCountOffset = (uint)CurrentHeader.GetEntryCountOffset();
|
||||
|
||||
uint baseEntryOffset = (uint)(Unsafe.SizeOf<THeader>() + Unsafe.SizeOf<TEntry>() * _entryIndex);
|
||||
|
||||
@@ -238,12 +236,10 @@ namespace Ryujinx.Audio.Renderer.Server.Performance
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
performanceEntry = new PerformanceEntryAddresses
|
||||
{
|
||||
BaseMemory = SpanMemoryManager<int>.Cast(CurrentBuffer),
|
||||
EntryCountOffset = (uint)CurrentHeader.GetEntryCountOffset(),
|
||||
};
|
||||
|
||||
performanceEntry = PerformanceEntryAddresses.PerformanceEntryAddressesPool.Allocate();
|
||||
performanceEntry.BaseMemory = SpanMemoryManager<int>.Cast(CurrentBuffer);
|
||||
performanceEntry.EntryCountOffset = (uint)CurrentHeader.GetEntryCountOffset();
|
||||
|
||||
uint baseEntryOffset = (uint)(Unsafe.SizeOf<THeader>() + GetEntriesSize() + Unsafe.SizeOf<TEntryDetail>() * _entryDetailIndex);
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
private static void ResetEffect<T>(ref BaseEffect effect, in T parameter, PoolMapper mapper) where T : unmanaged, IEffectInParameter
|
||||
private void ResetEffect<T>(ref BaseEffect effect, in T parameter, PoolMapper mapper) where T : unmanaged, IEffectInParameter
|
||||
{
|
||||
effect.ForceUnmapBuffers(mapper);
|
||||
|
||||
@@ -312,7 +312,8 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
EffectType.Delay => new DelayEffect(),
|
||||
EffectType.Reverb => new ReverbEffect(),
|
||||
EffectType.Reverb3d => new Reverb3dEffect(),
|
||||
EffectType.BiquadFilter => new BiquadFilterEffect(),
|
||||
EffectType.BiquadFilter when _behaviourInfo.IsBiquadFilterParameterFloatSupported() => new BiquadFilterEffect(2),
|
||||
EffectType.BiquadFilter => new BiquadFilterEffect(1),
|
||||
EffectType.Limiter => new LimiterEffect(),
|
||||
EffectType.CaptureBuffer => new CaptureBufferEffect(),
|
||||
EffectType.Compressor => new CompressorEffect(),
|
||||
@@ -322,11 +323,6 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
public ResultCode UpdateEffects(EffectContext context, bool isAudioRendererActive, PoolMapper mapper)
|
||||
{
|
||||
if (_behaviourInfo.IsBiquadFilterParameterFloatSupported())
|
||||
{
|
||||
return UpdateEffectsVersion3(context, isAudioRendererActive, mapper);
|
||||
}
|
||||
|
||||
if (_behaviourInfo.IsEffectInfoVersion2Supported())
|
||||
{
|
||||
return UpdateEffectsVersion2(context, isAudioRendererActive, mapper);
|
||||
@@ -334,60 +330,6 @@ namespace Ryujinx.Audio.Renderer.Server
|
||||
|
||||
return UpdateEffectsVersion1(context, isAudioRendererActive, mapper);
|
||||
}
|
||||
|
||||
public ResultCode UpdateEffectsVersion3(EffectContext context, bool isAudioRendererActive, PoolMapper mapper)
|
||||
{
|
||||
if (context.GetCount() * Unsafe.SizeOf<EffectInParameterVersion2>() != _inputHeader.EffectsSize)
|
||||
{
|
||||
return ResultCode.InvalidUpdateInfo;
|
||||
}
|
||||
|
||||
int initialOutputSize = _output.Length;
|
||||
|
||||
long initialInputConsumed = _inputReader.Consumed;
|
||||
|
||||
for (int i = 0; i < context.GetCount(); i++)
|
||||
{
|
||||
ref readonly EffectInParameterVersion3 parameter = ref _inputReader.GetRefOrRefToCopy<EffectInParameterVersion3>(out _);
|
||||
|
||||
ref EffectOutStatusVersion2 outStatus = ref SpanIOHelper.GetWriteRef<EffectOutStatusVersion2>(ref _output)[0];
|
||||
|
||||
ref BaseEffect effect = ref context.GetEffect(i);
|
||||
|
||||
if (!effect.IsTypeValid(in parameter))
|
||||
{
|
||||
ResetEffect(ref effect, in parameter, mapper);
|
||||
}
|
||||
|
||||
effect.Update(out ErrorInfo updateErrorInfo, in parameter, mapper);
|
||||
|
||||
if (updateErrorInfo.ErrorCode != ResultCode.Success)
|
||||
{
|
||||
_behaviourInfo.AppendError(ref updateErrorInfo);
|
||||
}
|
||||
|
||||
effect.StoreStatus(ref outStatus, isAudioRendererActive);
|
||||
|
||||
if (parameter.IsNew)
|
||||
{
|
||||
effect.InitializeResultState(ref context.GetDspState(i));
|
||||
effect.InitializeResultState(ref context.GetState(i));
|
||||
}
|
||||
|
||||
effect.UpdateResultState(ref outStatus.ResultState, ref context.GetState(i));
|
||||
}
|
||||
|
||||
int currentOutputSize = _output.Length;
|
||||
|
||||
OutputHeader.EffectsSize = (uint)(Unsafe.SizeOf<EffectOutStatusVersion2>() * context.GetCount());
|
||||
OutputHeader.TotalSize += OutputHeader.EffectsSize;
|
||||
|
||||
Debug.Assert((initialOutputSize - currentOutputSize) == OutputHeader.EffectsSize);
|
||||
|
||||
_inputReader.SetConsumed(initialInputConsumed + _inputHeader.EffectsSize);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
public ResultCode UpdateEffectsVersion2(EffectContext context, bool isAudioRendererActive, PoolMapper mapper)
|
||||
{
|
||||
|
||||
@@ -4,9 +4,11 @@ using Ryujinx.Audio.Renderer.Dsp;
|
||||
using Ryujinx.Audio.Renderer.Dsp.State;
|
||||
using Ryujinx.Audio.Renderer.Parameter;
|
||||
using Ryujinx.Audio.Renderer.Server.MemoryPool;
|
||||
using Ryujinx.Common;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using static Ryujinx.Audio.Renderer.Common.BehaviourParameter;
|
||||
@@ -20,6 +22,8 @@ namespace Ryujinx.Audio.Renderer.Server.Voice
|
||||
{
|
||||
public const int Alignment = 0x10;
|
||||
|
||||
private static readonly ObjectPool<Memory<VoiceState>[]> voiceStatesPool = new(() => new Memory<VoiceState>[Constants.VoiceChannelCountMax]);
|
||||
|
||||
/// <summary>
|
||||
/// Set to true if the voice is used.
|
||||
/// </summary>
|
||||
@@ -568,7 +572,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice
|
||||
PoolMapper mapper,
|
||||
ref BehaviourInfo behaviourInfo)
|
||||
{
|
||||
errorInfos = new ErrorInfo[Constants.VoiceWaveBufferCount * 2];
|
||||
|
||||
|
||||
if (parameter.IsNew)
|
||||
{
|
||||
@@ -584,11 +588,14 @@ namespace Ryujinx.Audio.Renderer.Server.Voice
|
||||
|
||||
Span<WaveBuffer> waveBuffersSpan = WaveBuffers.AsSpan();
|
||||
Span<WaveBufferInternal> pWaveBuffersSpan = parameter.WaveBuffers.AsSpan();
|
||||
List<ErrorInfo> errorInfosList = [];
|
||||
|
||||
for (int i = 0; i < Constants.VoiceWaveBufferCount; i++)
|
||||
{
|
||||
UpdateWaveBuffer(errorInfos.AsSpan(i * 2, 2), ref waveBuffersSpan[i], ref pWaveBuffersSpan[i], parameter.SampleFormat, voiceState.IsWaveBufferValid[i], mapper, ref behaviourInfo);
|
||||
UpdateWaveBuffer(errorInfosList, ref waveBuffersSpan[i], ref pWaveBuffersSpan[i], parameter.SampleFormat, voiceState.IsWaveBufferValid[i], mapper, ref behaviourInfo);
|
||||
}
|
||||
|
||||
errorInfos = errorInfosList.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -606,7 +613,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice
|
||||
PoolMapper mapper,
|
||||
ref BehaviourInfo behaviourInfo)
|
||||
{
|
||||
errorInfos = new ErrorInfo[Constants.VoiceWaveBufferCount * 2];
|
||||
|
||||
|
||||
if (parameter.IsNew)
|
||||
{
|
||||
@@ -622,11 +629,14 @@ namespace Ryujinx.Audio.Renderer.Server.Voice
|
||||
|
||||
Span<WaveBuffer> waveBuffersSpan = WaveBuffers.AsSpan();
|
||||
Span<WaveBufferInternal> pWaveBuffersSpan = parameter.WaveBuffers.AsSpan();
|
||||
List<ErrorInfo> errorInfosList = [];
|
||||
|
||||
for (int i = 0; i < Constants.VoiceWaveBufferCount; i++)
|
||||
{
|
||||
UpdateWaveBuffer(errorInfos.AsSpan(i * 2, 2), ref waveBuffersSpan[i], ref pWaveBuffersSpan[i], parameter.SampleFormat, voiceState.IsWaveBufferValid[i], mapper, ref behaviourInfo);
|
||||
UpdateWaveBuffer(errorInfosList, ref waveBuffersSpan[i], ref pWaveBuffersSpan[i], parameter.SampleFormat, voiceState.IsWaveBufferValid[i], mapper, ref behaviourInfo);
|
||||
}
|
||||
|
||||
errorInfos = errorInfosList.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -640,7 +650,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice
|
||||
/// <param name="mapper">The mapper to use.</param>
|
||||
/// <param name="behaviourInfo">The behaviour context.</param>
|
||||
private void UpdateWaveBuffer(
|
||||
Span<ErrorInfo> errorInfos,
|
||||
List<ErrorInfo> errorInfos,
|
||||
ref WaveBuffer waveBuffer,
|
||||
ref WaveBufferInternal inputWaveBuffer,
|
||||
SampleFormat sampleFormat,
|
||||
@@ -671,7 +681,10 @@ namespace Ryujinx.Audio.Renderer.Server.Voice
|
||||
|
||||
BufferInfoUnmapped = !mapper.TryAttachBuffer(out ErrorInfo bufferInfoError, ref waveBuffer.BufferAddressInfo, inputWaveBuffer.Address, inputWaveBuffer.Size);
|
||||
|
||||
errorInfos[0] = bufferInfoError;
|
||||
if (bufferInfoError.ErrorCode != ResultCode.Success)
|
||||
{
|
||||
errorInfos.Add(bufferInfoError);
|
||||
}
|
||||
|
||||
if (sampleFormat == SampleFormat.Adpcm && behaviourInfo.IsAdpcmLoopContextBugFixed() && inputWaveBuffer.ContextAddress != 0)
|
||||
{
|
||||
@@ -680,7 +693,10 @@ namespace Ryujinx.Audio.Renderer.Server.Voice
|
||||
inputWaveBuffer.ContextAddress,
|
||||
inputWaveBuffer.ContextSize);
|
||||
|
||||
errorInfos[1] = adpcmLoopContextInfoError;
|
||||
if (adpcmLoopContextInfoError.ErrorCode != ResultCode.Success)
|
||||
{
|
||||
errorInfos.Add(adpcmLoopContextInfoError);
|
||||
}
|
||||
|
||||
if (!adpcmLoopContextMapped || BufferInfoUnmapped)
|
||||
{
|
||||
@@ -698,8 +714,11 @@ namespace Ryujinx.Audio.Renderer.Server.Voice
|
||||
}
|
||||
else
|
||||
{
|
||||
errorInfos[0].ErrorCode = ResultCode.InvalidAddressInfo;
|
||||
errorInfos[0].ExtraErrorInfo = inputWaveBuffer.Address;
|
||||
errorInfos.Add(new ErrorInfo
|
||||
{
|
||||
ErrorCode = ResultCode.InvalidAddressInfo,
|
||||
ExtraErrorInfo = inputWaveBuffer.Address
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -891,7 +910,7 @@ namespace Ryujinx.Audio.Renderer.Server.Voice
|
||||
IsNew = false;
|
||||
}
|
||||
|
||||
Memory<VoiceState>[] voiceStates = new Memory<VoiceState>[Constants.VoiceChannelCountMax];
|
||||
Memory<VoiceState>[] voiceStates = voiceStatesPool.Allocate();
|
||||
|
||||
Span<int> channelResourceIdsSpan = ChannelResourceIds.AsSpan();
|
||||
|
||||
@@ -900,7 +919,12 @@ namespace Ryujinx.Audio.Renderer.Server.Voice
|
||||
voiceStates[i] = context.GetUpdateStateForDsp(channelResourceIdsSpan[i]);
|
||||
}
|
||||
|
||||
return UpdateParametersForCommandGeneration(voiceStates);
|
||||
bool result = UpdateParametersForCommandGeneration(voiceStates);
|
||||
|
||||
voiceStatesPool.Release(voiceStates);
|
||||
//might contain garbage data, but said data will never be accessed
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user