Ryujinx/Ryujinx.HLE/HOS/Services/Aud/IHardwareOpusDecoderManager.cs

73 lines
2.2 KiB
C#
Raw Normal View History

using Ryujinx.HLE.HOS.Ipc;
using System.Collections.Generic;
namespace Ryujinx.HLE.HOS.Services.Aud
{
class IHardwareOpusDecoderManager : IpcService
{
2018-12-01 21:01:59 +01:00
private Dictionary<int, ServiceProcessRequest> _commands;
2018-12-01 21:01:59 +01:00
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public IHardwareOpusDecoderManager()
{
2018-12-01 21:01:59 +01:00
_commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, Initialize },
{ 1, GetWorkBufferSize }
};
}
2018-12-01 21:01:59 +01:00
public long Initialize(ServiceCtx context)
{
2018-12-01 21:01:59 +01:00
int sampleRate = context.RequestData.ReadInt32();
int channelsCount = context.RequestData.ReadInt32();
2018-12-01 21:01:59 +01:00
MakeObject(context, new IHardwareOpusDecoder(sampleRate, channelsCount));
return 0;
}
2018-12-01 21:01:59 +01:00
public long GetWorkBufferSize(ServiceCtx context)
{
//Note: The sample rate is ignored because it is fixed to 48KHz.
2018-12-01 21:01:59 +01:00
int sampleRate = context.RequestData.ReadInt32();
int channelsCount = context.RequestData.ReadInt32();
2018-12-01 21:01:59 +01:00
context.ResponseData.Write(GetOpusDecoderSize(channelsCount));
return 0;
}
2018-12-01 21:01:59 +01:00
private static int GetOpusDecoderSize(int channelsCount)
{
2018-12-01 21:01:59 +01:00
const int silkDecoderSize = 0x2198;
2018-12-01 21:01:59 +01:00
if (channelsCount < 1 || channelsCount > 2)
{
return 0;
}
2018-12-01 21:01:59 +01:00
int celtDecoderSize = GetCeltDecoderSize(channelsCount);
2018-12-01 21:01:59 +01:00
int opusDecoderSize = (channelsCount * 0x800 + 0x4807) & -0x800 | 0x50;
2018-12-01 21:01:59 +01:00
return opusDecoderSize + silkDecoderSize + celtDecoderSize;
}
2018-12-01 21:01:59 +01:00
private static int GetCeltDecoderSize(int channelsCount)
{
2018-12-01 21:01:59 +01:00
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;
}
}
}