IHardwareOpusDecoderManager.cs 2.2 KB

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