1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-14 18:36:40 +00:00
Ryujinx/Ryujinx.HLE/HOS/Services/Aud/IHardwareOpusDecoderManager.cs
Ac_K 4ad3936afd Refactoring result codes (#731)
* refactoring result codes

- Add a main enum who can handle some orphalin result codes and the default `ResultCode.Success` one.
- Add sub-enum by services when it's needed.
- Remove some empty line.
- Recast all service calls to ResultCode.
- Remove some unneeded static declaration.
- Delete unused `NvHelper` class.

* NvResult is back

* Fix
2019-07-14 16:04:38 -03:00

63 lines
No EOL
2.1 KiB
C#

namespace Ryujinx.HLE.HOS.Services.Aud
{
[Service("hwopus")]
class IHardwareOpusDecoderManager : IpcService
{
public IHardwareOpusDecoderManager(ServiceCtx context) { }
[Command(0)]
// Initialize(bytes<8, 4>, u32, handle<copy>) -> object<nn::codec::detail::IHardwareOpusDecoder>
public ResultCode Initialize(ServiceCtx context)
{
int sampleRate = context.RequestData.ReadInt32();
int channelsCount = context.RequestData.ReadInt32();
MakeObject(context, new IHardwareOpusDecoder(sampleRate, channelsCount));
return ResultCode.Success;
}
[Command(1)]
// GetWorkBufferSize(bytes<8, 4>) -> u32
public ResultCode GetWorkBufferSize(ServiceCtx context)
{
// Note: The sample rate is ignored because it is fixed to 48KHz.
int sampleRate = context.RequestData.ReadInt32();
int channelsCount = context.RequestData.ReadInt32();
context.ResponseData.Write(GetOpusDecoderSize(channelsCount));
return ResultCode.Success;
}
private static int GetOpusDecoderSize(int channelsCount)
{
const int silkDecoderSize = 0x2198;
if (channelsCount < 1 || channelsCount > 2)
{
return 0;
}
int celtDecoderSize = GetCeltDecoderSize(channelsCount);
int opusDecoderSize = (channelsCount * 0x800 + 0x4807) & -0x800 | 0x50;
return opusDecoderSize + silkDecoderSize + celtDecoderSize;
}
private static int GetCeltDecoderSize(int channelsCount)
{
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;
}
}
}