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