IHardwareOpusDecoderManager.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Ryujinx.HLE.HOS.Services.Audio.HardwareOpusDecoderManager;
  2. namespace Ryujinx.HLE.HOS.Services.Audio
  3. {
  4. [Service("hwopus")]
  5. class IHardwareOpusDecoderManager : IpcService
  6. {
  7. public IHardwareOpusDecoderManager(ServiceCtx context) { }
  8. [Command(0)]
  9. // Initialize(bytes<8, 4>, u32, handle<copy>) -> object<nn::codec::detail::IHardwareOpusDecoder>
  10. public ResultCode Initialize(ServiceCtx context)
  11. {
  12. int sampleRate = context.RequestData.ReadInt32();
  13. int channelsCount = context.RequestData.ReadInt32();
  14. MakeObject(context, new IHardwareOpusDecoder(sampleRate, channelsCount));
  15. return ResultCode.Success;
  16. }
  17. [Command(1)]
  18. // GetWorkBufferSize(bytes<8, 4>) -> u32
  19. public ResultCode GetWorkBufferSize(ServiceCtx context)
  20. {
  21. // Note: The sample rate is ignored because it is fixed to 48KHz.
  22. int sampleRate = context.RequestData.ReadInt32();
  23. int channelsCount = context.RequestData.ReadInt32();
  24. context.ResponseData.Write(GetOpusDecoderSize(channelsCount));
  25. return ResultCode.Success;
  26. }
  27. private static int GetOpusDecoderSize(int channelsCount)
  28. {
  29. const int silkDecoderSize = 0x2198;
  30. if (channelsCount < 1 || channelsCount > 2)
  31. {
  32. return 0;
  33. }
  34. int celtDecoderSize = GetCeltDecoderSize(channelsCount);
  35. int opusDecoderSize = (channelsCount * 0x800 + 0x4807) & -0x800 | 0x50;
  36. return opusDecoderSize + silkDecoderSize + celtDecoderSize;
  37. }
  38. private static int GetCeltDecoderSize(int channelsCount)
  39. {
  40. const int decodeBufferSize = 0x2030;
  41. const int celtDecoderSize = 0x58;
  42. const int celtSigSize = 0x4;
  43. const int overlap = 120;
  44. const int eBandsCount = 21;
  45. return (decodeBufferSize + overlap * 4) * channelsCount +
  46. eBandsCount * 16 +
  47. celtDecoderSize +
  48. celtSigSize;
  49. }
  50. }
  51. }