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