IHardwareOpusDecoderManager.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Ryujinx.HLE.HOS.Ipc;
  2. using System.Collections.Generic;
  3. namespace Ryujinx.HLE.HOS.Services.Aud
  4. {
  5. [Service("hwopus")]
  6. class IHardwareOpusDecoderManager : IpcService
  7. {
  8. private Dictionary<int, ServiceProcessRequest> _commands;
  9. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  10. public IHardwareOpusDecoderManager(ServiceCtx context)
  11. {
  12. _commands = new Dictionary<int, ServiceProcessRequest>
  13. {
  14. { 0, Initialize },
  15. { 1, GetWorkBufferSize }
  16. };
  17. }
  18. public long Initialize(ServiceCtx context)
  19. {
  20. int sampleRate = context.RequestData.ReadInt32();
  21. int channelsCount = context.RequestData.ReadInt32();
  22. MakeObject(context, new IHardwareOpusDecoder(sampleRate, channelsCount));
  23. return 0;
  24. }
  25. public long GetWorkBufferSize(ServiceCtx context)
  26. {
  27. // Note: The sample rate is ignored because it is fixed to 48KHz.
  28. int sampleRate = context.RequestData.ReadInt32();
  29. int channelsCount = context.RequestData.ReadInt32();
  30. context.ResponseData.Write(GetOpusDecoderSize(channelsCount));
  31. return 0;
  32. }
  33. private static int GetOpusDecoderSize(int channelsCount)
  34. {
  35. const int silkDecoderSize = 0x2198;
  36. if (channelsCount < 1 || channelsCount > 2)
  37. {
  38. return 0;
  39. }
  40. int celtDecoderSize = GetCeltDecoderSize(channelsCount);
  41. int opusDecoderSize = (channelsCount * 0x800 + 0x4807) & -0x800 | 0x50;
  42. return opusDecoderSize + silkDecoderSize + celtDecoderSize;
  43. }
  44. private static int GetCeltDecoderSize(int channelsCount)
  45. {
  46. const int decodeBufferSize = 0x2030;
  47. const int celtDecoderSize = 0x58;
  48. const int celtSigSize = 0x4;
  49. const int overlap = 120;
  50. const int eBandsCount = 21;
  51. return (decodeBufferSize + overlap * 4) * channelsCount +
  52. eBandsCount * 16 +
  53. celtDecoderSize +
  54. celtSigSize;
  55. }
  56. }
  57. }