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> _commands;
  8. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  9. public IHardwareOpusDecoderManager()
  10. {
  11. _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. }