Started to implement the hwopus service
This commit is contained in:
parent
437962a65d
commit
f031e3a6fe
4 changed files with 138 additions and 0 deletions
|
@ -105,6 +105,9 @@ namespace Ryujinx.HLE.HOS.Services
|
|||
case "ldr:ro":
|
||||
return new IRoInterface();
|
||||
|
||||
case "hwopus":
|
||||
return new IHardwareOpusDecoderManager();
|
||||
|
||||
case "lm":
|
||||
return new ILogService();
|
||||
|
||||
|
|
59
Ryujinx.HLE/OsHle/Services/Aud/IHardwareOpusDecoder.cs
Normal file
59
Ryujinx.HLE/OsHle/Services/Aud/IHardwareOpusDecoder.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
using Concentus.Structs;
|
||||
using Ryujinx.HLE.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.HLE.OsHle.Services.Aud
|
||||
{
|
||||
class IHardwareOpusDecoder : IpcService
|
||||
{
|
||||
private const int FixedSampleRate = 48000;
|
||||
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private int SampleRate;
|
||||
private int ChannelsCount;
|
||||
|
||||
private OpusDecoder Decoder;
|
||||
|
||||
public IHardwareOpusDecoder(int SampleRate, int ChannelsCount)
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, DecodeInterleaved }
|
||||
};
|
||||
|
||||
this.SampleRate = SampleRate;
|
||||
this.ChannelsCount = ChannelsCount;
|
||||
|
||||
Decoder = new OpusDecoder(FixedSampleRate, ChannelsCount);
|
||||
}
|
||||
|
||||
public long DecodeInterleaved(ServiceCtx Context)
|
||||
{
|
||||
long InPosition = Context.Request.SendBuff[0].Position;
|
||||
long InSize = Context.Request.SendBuff[0].Size;
|
||||
|
||||
long OutPosition = Context.Request.ReceiveBuff[0].Position;
|
||||
long OutSize = Context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
byte[] OpusData = Context.Memory.ReadBytes(InPosition, InSize);
|
||||
|
||||
short[] Pcm = new short[OutSize / 2];
|
||||
|
||||
int FrameSize = Pcm.Length / (ChannelsCount * 2);
|
||||
|
||||
int Result = Decoder.Decode(OpusData, 0, OpusData.Length, Pcm, 0, FrameSize);
|
||||
|
||||
foreach (short Sample in Pcm)
|
||||
{
|
||||
Context.Memory.WriteInt16(OutPosition, Sample);
|
||||
|
||||
OutPosition += 2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
using Ryujinx.HLE.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.HLE.OsHle.Services.Aud
|
||||
{
|
||||
class IHardwareOpusDecoderManager : IpcService
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
public IHardwareOpusDecoderManager()
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, Initialize },
|
||||
{ 1, GetWorkBufferSize }
|
||||
};
|
||||
}
|
||||
|
||||
public long Initialize(ServiceCtx Context)
|
||||
{
|
||||
int SampleRate = Context.RequestData.ReadInt32();
|
||||
int ChannelsCount = Context.RequestData.ReadInt32();
|
||||
|
||||
MakeObject(Context, new IHardwareOpusDecoder(SampleRate, ChannelsCount));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetWorkBufferSize(ServiceCtx Context)
|
||||
{
|
||||
//Note: The sample rate is ignored because it is fixed to 48KHz.
|
||||
int SampleRate = Context.RequestData.ReadInt32();
|
||||
int ChannelsCount = Context.RequestData.ReadInt32();
|
||||
|
||||
Context.ResponseData.Write(GetOpusDecoderSize(ChannelsCount));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int GetOpusDecoderSize(int ChannelsCount)
|
||||
{
|
||||
const int SilkDecoderSize = 0x2198;
|
||||
|
||||
if (ChannelsCount < 1 || ChannelsCount > 2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CeltDecoderSize = GetCeltDecoderSize(ChannelsCount);
|
||||
|
||||
int OpusDecoderSize = (ChannelsCount * 0x800 + 0x4807) & -0x800 | 0x50;
|
||||
|
||||
return OpusDecoderSize + SilkDecoderSize + CeltDecoderSize;
|
||||
}
|
||||
|
||||
private static int GetCeltDecoderSize(int ChannelsCount)
|
||||
{
|
||||
const int DecodeBufferSize = 0x2030;
|
||||
const int CeltDecoderSize = 0x58;
|
||||
const int CeltSigSize = 0x4;
|
||||
const int Overlap = 120;
|
||||
const int EBandsCount = 21;
|
||||
|
||||
return (DecodeBufferSize + Overlap * 4) * ChannelsCount +
|
||||
EBandsCount * 16 +
|
||||
CeltDecoderSize +
|
||||
CeltSigSize;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,4 +29,8 @@
|
|||
<PackageReference Include="LibHac" Version="0.1.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Concentus" Version="1.1.7" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Loading…
Add table
Reference in a new issue