2018-11-16 19:36:49 -08:00
|
|
|
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
|
|
|
|
{
|
2019-07-11 18:13:43 -07:00
|
|
|
public IHardwareOpusDecoderManager(ServiceCtx context) { }
|
2018-11-16 19:36:49 -08:00
|
|
|
|
2019-07-11 18:13:43 -07:00
|
|
|
[Command(0)]
|
|
|
|
// Initialize(bytes<8, 4>, u32, handle<copy>) -> object<nn::codec::detail::IHardwareOpusDecoder>
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode 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
|
|
|
|
2019-07-14 12:04:38 -07:00
|
|
|
return ResultCode.Success;
|
2018-11-16 19:36:49 -08:00
|
|
|
}
|
|
|
|
|
2019-07-11 18:13:43 -07:00
|
|
|
[Command(1)]
|
|
|
|
// GetWorkBufferSize(bytes<8, 4>) -> u32
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode 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
|
|
|
|
2019-07-14 12:04:38 -07:00
|
|
|
return ResultCode.Success;
|
2018-11-16 19:36:49 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2019-07-11 18:13:43 -07:00
|
|
|
}
|