Audio Renderer improvements (#210)
* Partial voice implementation on audio renderer * Implemented audren resampler (based on original impl) * Fix BiquadFilter struct * Pause audio playback on last stream buffer * Split audren/audout files into separate folders, some minor cleanup * Use AudioRendererParameter on GetWorkBufferSize aswell * Bump audren version to REV4, name a few things, increase sample buffer size * Remove useless new lines
This commit is contained in:
parent
be31f5b46d
commit
98c6ceede5
34 changed files with 1168 additions and 271 deletions
|
@ -1,7 +1,11 @@
|
|||
using Ryujinx.Audio;
|
||||
using Ryujinx.HLE.Logging;
|
||||
using Ryujinx.HLE.OsHle.Ipc;
|
||||
using Ryujinx.HLE.OsHle.Services.Aud.AudioRenderer;
|
||||
using Ryujinx.HLE.OsHle.Utilities;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using static Ryujinx.HLE.OsHle.ErrorCode;
|
||||
|
||||
namespace Ryujinx.HLE.OsHle.Services.Aud
|
||||
{
|
||||
|
@ -12,6 +16,10 @@ namespace Ryujinx.HLE.OsHle.Services.Aud
|
|||
('V' << 16) |
|
||||
('0' << 24);
|
||||
|
||||
private const int Rev = 4;
|
||||
|
||||
public const int RevMagic = Rev0Magic + Rev;
|
||||
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
@ -28,76 +36,69 @@ namespace Ryujinx.HLE.OsHle.Services.Aud
|
|||
|
||||
public long OpenAudioRenderer(ServiceCtx Context)
|
||||
{
|
||||
//Same buffer as GetAudioRendererWorkBufferSize is receive here.
|
||||
IAalOutput AudioOut = Context.Ns.AudioOut;
|
||||
|
||||
AudioRendererParameter Params = new AudioRendererParameter();
|
||||
AudioRendererParameter Params = GetAudioRendererParameter(Context);
|
||||
|
||||
Params.SampleRate = Context.RequestData.ReadInt32();
|
||||
Params.SampleCount = Context.RequestData.ReadInt32();
|
||||
Params.Unknown8 = Context.RequestData.ReadInt32();
|
||||
Params.UnknownC = Context.RequestData.ReadInt32();
|
||||
Params.VoiceCount = Context.RequestData.ReadInt32();
|
||||
Params.SinkCount = Context.RequestData.ReadInt32();
|
||||
Params.EffectCount = Context.RequestData.ReadInt32();
|
||||
Params.Unknown1C = Context.RequestData.ReadInt32();
|
||||
Params.Unknown20 = Context.RequestData.ReadInt32();
|
||||
Params.SplitterCount = Context.RequestData.ReadInt32();
|
||||
Params.Unknown28 = Context.RequestData.ReadInt32();
|
||||
Params.Unknown2C = Context.RequestData.ReadInt32();
|
||||
Params.Revision = Context.RequestData.ReadInt32();
|
||||
|
||||
MakeObject(Context, new IAudioRenderer(Params));
|
||||
MakeObject(Context, new IAudioRenderer(Context.Memory, AudioOut, Params));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetAudioRendererWorkBufferSize(ServiceCtx Context)
|
||||
{
|
||||
long SampleRate = Context.RequestData.ReadUInt32();
|
||||
long Unknown4 = Context.RequestData.ReadUInt32();
|
||||
long Unknown8 = Context.RequestData.ReadUInt32();
|
||||
long UnknownC = Context.RequestData.ReadUInt32();
|
||||
long Unknown10 = Context.RequestData.ReadUInt32(); //VoiceCount
|
||||
long Unknown14 = Context.RequestData.ReadUInt32(); //SinkCount
|
||||
long Unknown18 = Context.RequestData.ReadUInt32(); //EffectCount
|
||||
long Unknown1c = Context.RequestData.ReadUInt32(); //Boolean
|
||||
long Unknown20 = Context.RequestData.ReadUInt32(); //Not used here in FW3.0.1 - Boolean
|
||||
long Unknown24 = Context.RequestData.ReadUInt32();
|
||||
long Unknown28 = Context.RequestData.ReadUInt32(); //SplitterCount
|
||||
long Unknown2c = Context.RequestData.ReadUInt32(); //Not used here in FW3.0.1
|
||||
int RevMagic = Context.RequestData.ReadInt32();
|
||||
AudioRendererParameter Params = GetAudioRendererParameter(Context);
|
||||
|
||||
int Version = (RevMagic - Rev0Magic) >> 24;
|
||||
int Revision = (Params.Revision - Rev0Magic) >> 24;
|
||||
|
||||
if (Version <= 3) //REV3 Max is supported
|
||||
if (Revision <= Rev) //REV3 Max is supported
|
||||
{
|
||||
long Size = RoundUp(Unknown8 * 4, 64);
|
||||
Size += (UnknownC << 10);
|
||||
Size += (UnknownC + 1) * 0x940;
|
||||
Size += Unknown10 * 0x3F0;
|
||||
Size += RoundUp((UnknownC + 1) * 8, 16);
|
||||
Size += RoundUp(Unknown10 * 8, 16);
|
||||
Size += RoundUp((0x3C0 * (Unknown14 + UnknownC) + 4 * Unknown4) * (Unknown8 + 6), 64);
|
||||
Size += 0x2C0 * (Unknown14 + UnknownC) + 0x30 * (Unknown18 + (4 * Unknown10)) + 0x50;
|
||||
bool IsSplitterSupported = Revision >= 3;
|
||||
|
||||
if (Version >= 3) //IsSplitterSupported
|
||||
long Size;
|
||||
|
||||
Size = IntUtils.AlignUp(Params.Unknown8 * 4, 64);
|
||||
Size += Params.MixCount * 0x400;
|
||||
Size += (Params.MixCount + 1) * 0x940;
|
||||
Size += Params.VoiceCount * 0x3F0;
|
||||
Size += IntUtils.AlignUp((Params.MixCount + 1) * 8, 16);
|
||||
Size += IntUtils.AlignUp(Params.VoiceCount * 8, 16);
|
||||
Size += IntUtils.AlignUp(
|
||||
((Params.SinkCount + Params.MixCount) * 0x3C0 + Params.SampleCount * 4) *
|
||||
(Params.Unknown8 + 6), 64);
|
||||
Size += (Params.SinkCount + Params.MixCount) * 0x2C0;
|
||||
Size += (Params.EffectCount + 4 * Params.VoiceCount) * 0x30 + 0x50;
|
||||
|
||||
if (IsSplitterSupported)
|
||||
{
|
||||
Size += RoundUp((NodeStatesGetWorkBufferSize((int)UnknownC + 1) + EdgeMatrixGetWorkBufferSize((int)UnknownC + 1)), 16);
|
||||
Size += 0xE0 * Unknown28 + 0x20 * Unknown24 + RoundUp(Unknown28 * 4, 16);
|
||||
Size += IntUtils.AlignUp((
|
||||
NodeStatesGetWorkBufferSize(Params.MixCount + 1) +
|
||||
EdgeMatrixGetWorkBufferSize(Params.MixCount + 1)), 16);
|
||||
|
||||
Size += Params.SplitterDestinationDataCount * 0xE0;
|
||||
Size += Params.SplitterCount * 0x20;
|
||||
Size += IntUtils.AlignUp(Params.SplitterDestinationDataCount * 4, 16);
|
||||
}
|
||||
|
||||
Size = 0x4C0 * Unknown18 + RoundUp(Size, 64) + 0x170 * Unknown14 + ((Unknown10 << 8) | 0x40);
|
||||
Size = Params.EffectCount * 0x4C0 +
|
||||
Params.SinkCount * 0x170 +
|
||||
Params.VoiceCount * 0x100 +
|
||||
IntUtils.AlignUp(Size, 64) + 0x40;
|
||||
|
||||
if (Unknown1c >= 1)
|
||||
if (Params.PerformanceManagerCount >= 1)
|
||||
{
|
||||
Size += ((((Unknown18 + Unknown14 + Unknown10 + UnknownC + 1) * 16) + 0x658) * (Unknown1c + 1) + 0x13F) & ~0x3FL;
|
||||
Size += (((Params.EffectCount +
|
||||
Params.SinkCount +
|
||||
Params.VoiceCount +
|
||||
Params.MixCount + 1) * 16 + 0x658) *
|
||||
(Params.PerformanceManagerCount + 1) + 0x13F) & ~0x3FL;
|
||||
}
|
||||
|
||||
long WorkBufferSize = (Size + 0x1907D) & ~0xFFFL;
|
||||
Size = (Size + 0x1907D) & ~0xFFFL;
|
||||
|
||||
Context.ResponseData.Write(WorkBufferSize);
|
||||
Context.ResponseData.Write(Size);
|
||||
|
||||
Context.Ns.Log.PrintDebug(LogClass.ServiceAudio, $"WorkBufferSize is 0x{WorkBufferSize:x16}.");
|
||||
Context.Ns.Log.PrintDebug(LogClass.ServiceAudio, $"WorkBufferSize is 0x{Size:x16}.");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -105,20 +106,36 @@ namespace Ryujinx.HLE.OsHle.Services.Aud
|
|||
{
|
||||
Context.ResponseData.Write(0L);
|
||||
|
||||
Context.Ns.Log.PrintError(LogClass.ServiceAudio, $"Library Revision 0x{RevMagic:x8} is not supported!");
|
||||
Context.Ns.Log.PrintWarning(LogClass.ServiceAudio, $"Library Revision 0x{Params.Revision:x8} is not supported!");
|
||||
|
||||
return 0x499;
|
||||
return MakeError(ErrorModule.Audio, AudErr.UnsupportedRevision);
|
||||
}
|
||||
}
|
||||
|
||||
private static long RoundUp(long Value, int Size)
|
||||
private AudioRendererParameter GetAudioRendererParameter(ServiceCtx Context)
|
||||
{
|
||||
return (Value + (Size - 1)) & ~((long)Size - 1);
|
||||
AudioRendererParameter Params = new AudioRendererParameter();
|
||||
|
||||
Params.SampleRate = Context.RequestData.ReadInt32();
|
||||
Params.SampleCount = Context.RequestData.ReadInt32();
|
||||
Params.Unknown8 = Context.RequestData.ReadInt32();
|
||||
Params.MixCount = Context.RequestData.ReadInt32();
|
||||
Params.VoiceCount = Context.RequestData.ReadInt32();
|
||||
Params.SinkCount = Context.RequestData.ReadInt32();
|
||||
Params.EffectCount = Context.RequestData.ReadInt32();
|
||||
Params.PerformanceManagerCount = Context.RequestData.ReadInt32();
|
||||
Params.VoiceDropEnable = Context.RequestData.ReadInt32();
|
||||
Params.SplitterCount = Context.RequestData.ReadInt32();
|
||||
Params.SplitterDestinationDataCount = Context.RequestData.ReadInt32();
|
||||
Params.Unknown2C = Context.RequestData.ReadInt32();
|
||||
Params.Revision = Context.RequestData.ReadInt32();
|
||||
|
||||
return Params;
|
||||
}
|
||||
|
||||
private static int NodeStatesGetWorkBufferSize(int Value)
|
||||
{
|
||||
int Result = (int)RoundUp(Value, 64);
|
||||
int Result = IntUtils.AlignUp(Value, 64);
|
||||
|
||||
if (Result < 0)
|
||||
{
|
||||
|
@ -130,7 +147,7 @@ namespace Ryujinx.HLE.OsHle.Services.Aud
|
|||
|
||||
private static int EdgeMatrixGetWorkBufferSize(int Value)
|
||||
{
|
||||
int Result = (int)RoundUp(Value * Value, 64);
|
||||
int Result = IntUtils.AlignUp(Value * Value, 64);
|
||||
|
||||
if (Result < 0)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue