CommandProcessingTimeEstimatorVersion1.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //
  2. // Copyright (c) 2019-2020 Ryujinx
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. //
  17. using Ryujinx.Audio.Renderer.Dsp.Command;
  18. using System.Diagnostics;
  19. namespace Ryujinx.Audio.Renderer.Server
  20. {
  21. /// <summary>
  22. /// <see cref="ICommandProcessingTimeEstimator"/> version 1.
  23. /// </summary>
  24. public class CommandProcessingTimeEstimatorVersion1 : ICommandProcessingTimeEstimator
  25. {
  26. private uint _sampleCount;
  27. private uint _bufferCount;
  28. public CommandProcessingTimeEstimatorVersion1(uint sampleCount, uint bufferCount)
  29. {
  30. _sampleCount = sampleCount;
  31. _bufferCount = bufferCount;
  32. }
  33. public uint Estimate(PerformanceCommand command)
  34. {
  35. return 1454;
  36. }
  37. public uint Estimate(ClearMixBufferCommand command)
  38. {
  39. return (uint)(_sampleCount * 0.83f * _bufferCount * 1.2f);
  40. }
  41. public uint Estimate(BiquadFilterCommand command)
  42. {
  43. return (uint)(_sampleCount * 58.0f * 1.2f);
  44. }
  45. public uint Estimate(MixRampGroupedCommand command)
  46. {
  47. int volumeCount = 0;
  48. for (int i = 0; i < command.MixBufferCount; i++)
  49. {
  50. if (command.Volume0[i] != 0.0f || command.Volume1[i] != 0.0f)
  51. {
  52. volumeCount++;
  53. }
  54. }
  55. return (uint)(_sampleCount * 14.4f * 1.2f * volumeCount);
  56. }
  57. public uint Estimate(MixRampCommand command)
  58. {
  59. return (uint)(_sampleCount * 14.4f * 1.2f);
  60. }
  61. public uint Estimate(DepopPrepareCommand command)
  62. {
  63. return 1080;
  64. }
  65. public uint Estimate(VolumeRampCommand command)
  66. {
  67. return (uint)(_sampleCount * 9.8f * 1.2f);
  68. }
  69. public uint Estimate(PcmInt16DataSourceCommandVersion1 command)
  70. {
  71. return (uint)(command.Pitch * 0.25f * 1.2f);
  72. }
  73. public uint Estimate(AdpcmDataSourceCommandVersion1 command)
  74. {
  75. return (uint)(command.Pitch * 0.46f * 1.2f);
  76. }
  77. public uint Estimate(DepopForMixBuffersCommand command)
  78. {
  79. return (uint)(_sampleCount * 8.9f * command.MixBufferCount);
  80. }
  81. public uint Estimate(CopyMixBufferCommand command)
  82. {
  83. // NOTE: Nintendo returns 0 here for some reasons even if it will generate a command like that on version 1.. maybe a mistake?
  84. return 0;
  85. }
  86. public uint Estimate(MixCommand command)
  87. {
  88. return (uint)(_sampleCount * 10.0f * 1.2f);
  89. }
  90. public uint Estimate(DelayCommand command)
  91. {
  92. return (uint)(_sampleCount * command.Parameter.ChannelCount * 202.5f);
  93. }
  94. public uint Estimate(ReverbCommand command)
  95. {
  96. Debug.Assert(command.Parameter.IsChannelCountValid());
  97. if (command.Enabled)
  98. {
  99. return (uint)(750 * _sampleCount * command.Parameter.ChannelCount * 1.2f);
  100. }
  101. return 0;
  102. }
  103. public uint Estimate(Reverb3dCommand command)
  104. {
  105. if (command.Enabled)
  106. {
  107. return (uint)(530 * _sampleCount * command.Parameter.ChannelCount * 1.2f);
  108. }
  109. return 0;
  110. }
  111. public uint Estimate(AuxiliaryBufferCommand command)
  112. {
  113. if (command.Enabled)
  114. {
  115. return 15956;
  116. }
  117. return 3765;
  118. }
  119. public uint Estimate(VolumeCommand command)
  120. {
  121. return (uint)(_sampleCount * 8.8f * 1.2f);
  122. }
  123. public uint Estimate(CircularBufferSinkCommand command)
  124. {
  125. return 55;
  126. }
  127. public uint Estimate(DownMixSurroundToStereoCommand command)
  128. {
  129. return 16108;
  130. }
  131. public uint Estimate(UpsampleCommand command)
  132. {
  133. return 357915;
  134. }
  135. public uint Estimate(DeviceSinkCommand command)
  136. {
  137. return 10042;
  138. }
  139. public uint Estimate(PcmFloatDataSourceCommandVersion1 command)
  140. {
  141. return 0;
  142. }
  143. public uint Estimate(DataSourceVersion2Command command)
  144. {
  145. return 0;
  146. }
  147. }
  148. }