2019-09-19 02:45:11 +02:00
|
|
|
using Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager;
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Audio
|
2018-11-17 04:36:49 +01:00
|
|
|
{
|
2019-07-10 17:59:54 +02:00
|
|
|
[Service("hwopus")]
|
2018-11-17 04:36:49 +01:00
|
|
|
class IHardwareOpusDecoderManager : IpcService
|
|
|
|
{
|
2019-07-12 03:13:43 +02:00
|
|
|
public IHardwareOpusDecoderManager(ServiceCtx context) { }
|
2018-11-17 04:36:49 +01:00
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(0)]
|
|
|
|
// Initialize(bytes<8, 4>, u32, handle<copy>) -> object<nn::codec::detail::IHardwareOpusDecoder>
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode Initialize(ServiceCtx context)
|
2018-11-17 04:36:49 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
int sampleRate = context.RequestData.ReadInt32();
|
|
|
|
int channelsCount = context.RequestData.ReadInt32();
|
2018-11-17 04:36:49 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
MakeObject(context, new IHardwareOpusDecoder(sampleRate, channelsCount));
|
2018-11-17 04:36:49 +01:00
|
|
|
|
2020-12-02 00:23:43 +01:00
|
|
|
// Close transfer memory immediately as we don't use it.
|
|
|
|
context.Device.System.KernelContext.Syscall.CloseHandle(context.Request.HandleDesc.ToCopy[0]);
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2018-11-17 04:36:49 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(1)]
|
|
|
|
// GetWorkBufferSize(bytes<8, 4>) -> u32
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode GetWorkBufferSize(ServiceCtx context)
|
2018-11-17 04:36:49 +01:00
|
|
|
{
|
2019-07-02 04:39:22 +02:00
|
|
|
// Note: The sample rate is ignored because it is fixed to 48KHz.
|
2018-12-06 12:16:24 +01:00
|
|
|
int sampleRate = context.RequestData.ReadInt32();
|
|
|
|
int channelsCount = context.RequestData.ReadInt32();
|
2018-11-17 04:36:49 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
context.ResponseData.Write(GetOpusDecoderSize(channelsCount));
|
2018-11-17 04:36:49 +01:00
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2018-11-17 04:36:49 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private static int GetOpusDecoderSize(int channelsCount)
|
2018-11-17 04:36:49 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
const int silkDecoderSize = 0x2198;
|
2018-11-17 04:36:49 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (channelsCount < 1 || channelsCount > 2)
|
2018-11-17 04:36:49 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
int celtDecoderSize = GetCeltDecoderSize(channelsCount);
|
2018-11-17 04:36:49 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
int opusDecoderSize = (channelsCount * 0x800 + 0x4807) & -0x800 | 0x50;
|
2018-11-17 04:36:49 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return opusDecoderSize + silkDecoderSize + celtDecoderSize;
|
2018-11-17 04:36:49 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private static int GetCeltDecoderSize(int channelsCount)
|
2018-11-17 04:36:49 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +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;
|
2018-11-17 04:36:49 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-12 03:13:43 +02:00
|
|
|
}
|