2018-11-17 03:36:49 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Aud
|
|
|
|
{
|
2019-07-10 15:59:54 +00:00
|
|
|
[Service("hwopus")]
|
2018-11-17 03:36:49 +00:00
|
|
|
class IHardwareOpusDecoderManager : IpcService
|
|
|
|
{
|
2019-07-12 01:13:43 +00:00
|
|
|
public IHardwareOpusDecoderManager(ServiceCtx context) { }
|
2018-11-17 03:36:49 +00:00
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(0)]
|
|
|
|
// Initialize(bytes<8, 4>, u32, handle<copy>) -> object<nn::codec::detail::IHardwareOpusDecoder>
|
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;
|
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(1)]
|
|
|
|
// GetWorkBufferSize(bytes<8, 4>) -> u32
|
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
|
|
|
}
|
|
|
|
}
|
2019-07-12 01:13:43 +00:00
|
|
|
}
|