From 5cbdfbc7a4b7413a4f633c77190a79bfc6520e98 Mon Sep 17 00:00:00 2001 From: Mary Date: Fri, 12 May 2023 00:19:19 +0200 Subject: [PATCH] amadeus: Allow 5.1 sink output (#4894) * amadeus: Allow 5.1 sink output Also add a simple Stereo to 5.1 change for device sink. Tested against NES - Nintendo Switch Online that output stereo on the audio renderer. * Remove outdated comment --- src/Ryujinx.Audio/Renderer/Dsp/AudioProcessor.cs | 4 +--- .../Renderer/Dsp/Command/DeviceSinkCommand.cs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Ryujinx.Audio/Renderer/Dsp/AudioProcessor.cs b/src/Ryujinx.Audio/Renderer/Dsp/AudioProcessor.cs index 7bd0443c..899c2ef9 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/AudioProcessor.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/AudioProcessor.cs @@ -65,9 +65,7 @@ namespace Ryujinx.Audio.Renderer.Dsp { OutputDevices = new IHardwareDevice[Constants.AudioRendererSessionCountMax]; - // TODO: Before enabling this, we need up-mixing from stereo to 5.1. - // uint channelCount = GetHardwareChannelCount(deviceDriver); - uint channelCount = 2; + uint channelCount = GetHardwareChannelCount(deviceDriver); for (int i = 0; i < OutputDevices.Length; i++) { diff --git a/src/Ryujinx.Audio/Renderer/Dsp/Command/DeviceSinkCommand.cs b/src/Ryujinx.Audio/Renderer/Dsp/Command/DeviceSinkCommand.cs index 9c88a4e7..27bb34bf 100644 --- a/src/Ryujinx.Audio/Renderer/Dsp/Command/DeviceSinkCommand.cs +++ b/src/Ryujinx.Audio/Renderer/Dsp/Command/DeviceSinkCommand.cs @@ -67,7 +67,19 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command const int sampleCount = Constants.TargetSampleCount; - short[] outputBuffer = new short[bufferCount * sampleCount]; + uint inputCount; + + // In case of upmixing to 5.1, we allocate the right amount. + if (bufferCount != channelCount && channelCount == 6) + { + inputCount = (uint)channelCount; + } + else + { + inputCount = bufferCount; + } + + short[] outputBuffer = new short[inputCount * sampleCount]; for (int i = 0; i < bufferCount; i++) { @@ -79,7 +91,7 @@ namespace Ryujinx.Audio.Renderer.Dsp.Command } } - device.AppendBuffer(outputBuffer, InputCount); + device.AppendBuffer(outputBuffer, inputCount); } else {