CommandProcessingTimeEstimatorVersion2.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. using Ryujinx.Audio.Renderer.Dsp.Command;
  2. using System;
  3. using System.Diagnostics;
  4. namespace Ryujinx.Audio.Renderer.Server
  5. {
  6. /// <summary>
  7. /// <see cref="ICommandProcessingTimeEstimator"/> version 2. (added with REV5)
  8. /// </summary>
  9. public class CommandProcessingTimeEstimatorVersion2 : ICommandProcessingTimeEstimator
  10. {
  11. private uint _sampleCount;
  12. private uint _bufferCount;
  13. public CommandProcessingTimeEstimatorVersion2(uint sampleCount, uint bufferCount)
  14. {
  15. _sampleCount = sampleCount;
  16. _bufferCount = bufferCount;
  17. }
  18. public uint Estimate(PerformanceCommand command)
  19. {
  20. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  21. if (_sampleCount == 160)
  22. {
  23. return (uint)489.35f;
  24. }
  25. return (uint)491.18f;
  26. }
  27. public uint Estimate(ClearMixBufferCommand command)
  28. {
  29. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  30. float costPerBuffer = 668.8f;
  31. float baseCost = 193.2f;
  32. if (_sampleCount == 160)
  33. {
  34. costPerBuffer = 260.4f;
  35. baseCost = 139.65f;
  36. }
  37. return (uint)(baseCost + costPerBuffer * _bufferCount);
  38. }
  39. public uint Estimate(BiquadFilterCommand command)
  40. {
  41. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  42. if (_sampleCount == 160)
  43. {
  44. return (uint)4813.2f;
  45. }
  46. return (uint)6915.4f;
  47. }
  48. public uint Estimate(MixRampGroupedCommand command)
  49. {
  50. const float costPerSample = 7.245f;
  51. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  52. int volumeCount = 0;
  53. for (int i = 0; i < command.MixBufferCount; i++)
  54. {
  55. if (command.Volume0[i] != 0.0f || command.Volume1[i] != 0.0f)
  56. {
  57. volumeCount++;
  58. }
  59. }
  60. return (uint)(_sampleCount * costPerSample * volumeCount);
  61. }
  62. public uint Estimate(MixRampCommand command)
  63. {
  64. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  65. if (_sampleCount == 160)
  66. {
  67. return (uint)1859.0f;
  68. }
  69. return (uint)2286.1f;
  70. }
  71. public uint Estimate(DepopPrepareCommand command)
  72. {
  73. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  74. if (_sampleCount == 160)
  75. {
  76. return (uint)306.62f;
  77. }
  78. return (uint)293.22f;
  79. }
  80. public uint Estimate(VolumeRampCommand command)
  81. {
  82. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  83. if (_sampleCount == 160)
  84. {
  85. return (uint)1403.9f;
  86. }
  87. return (uint)1884.3f;
  88. }
  89. public uint Estimate(PcmInt16DataSourceCommandVersion1 command)
  90. {
  91. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  92. float costPerSample = 1195.5f;
  93. float baseCost = 7797.0f;
  94. if (_sampleCount == 160)
  95. {
  96. costPerSample = 749.27f;
  97. baseCost = 6138.9f;
  98. }
  99. return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / _sampleCount) * (command.Pitch * 0.000030518f))));
  100. }
  101. public uint Estimate(AdpcmDataSourceCommandVersion1 command)
  102. {
  103. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  104. float costPerSample = 3564.1f;
  105. float baseCost = 6225.5f;
  106. if (_sampleCount == 160)
  107. {
  108. costPerSample = 2125.6f;
  109. baseCost = 9039.5f;
  110. }
  111. return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / _sampleCount) * (command.Pitch * 0.000030518f))));
  112. }
  113. public uint Estimate(DepopForMixBuffersCommand command)
  114. {
  115. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  116. if (_sampleCount == 160)
  117. {
  118. return (uint)762.96f;
  119. }
  120. return (uint)726.96f;
  121. }
  122. public uint Estimate(CopyMixBufferCommand command)
  123. {
  124. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  125. if (_sampleCount == 160)
  126. {
  127. return (uint)836.32f;
  128. }
  129. return (uint)1000.9f;
  130. }
  131. public uint Estimate(MixCommand command)
  132. {
  133. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  134. if (_sampleCount == 160)
  135. {
  136. return (uint)1342.2f;
  137. }
  138. return (uint)1833.2f;
  139. }
  140. public uint Estimate(DelayCommand command)
  141. {
  142. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  143. if (_sampleCount == 160)
  144. {
  145. if (command.Enabled)
  146. {
  147. switch (command.Parameter.ChannelCount)
  148. {
  149. case 1:
  150. return (uint)41636.0f;
  151. case 2:
  152. return (uint)97861.0f;
  153. case 4:
  154. return (uint)192520.0f;
  155. case 6:
  156. return (uint)301760.0f;
  157. default:
  158. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  159. }
  160. }
  161. else
  162. {
  163. switch (command.Parameter.ChannelCount)
  164. {
  165. case 1:
  166. return (uint)578.53f;
  167. case 2:
  168. return (uint)663.06f;
  169. case 4:
  170. return (uint)703.98f;
  171. case 6:
  172. return (uint)760.03f;
  173. default:
  174. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  175. }
  176. }
  177. }
  178. if (command.Enabled)
  179. {
  180. switch (command.Parameter.ChannelCount)
  181. {
  182. case 1:
  183. return (uint)8770.3f;
  184. case 2:
  185. return (uint)25741.0f;
  186. case 4:
  187. return (uint)47551.0f;
  188. case 6:
  189. return (uint)81629.0f;
  190. default:
  191. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  192. }
  193. }
  194. else
  195. {
  196. switch (command.Parameter.ChannelCount)
  197. {
  198. case 1:
  199. return (uint)521.28f;
  200. case 2:
  201. return (uint)585.4f;
  202. case 4:
  203. return (uint)629.88f;
  204. case 6:
  205. return (uint)713.57f;
  206. default:
  207. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  208. }
  209. }
  210. }
  211. public uint Estimate(ReverbCommand command)
  212. {
  213. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  214. if (_sampleCount == 160)
  215. {
  216. if (command.Enabled)
  217. {
  218. switch (command.Parameter.ChannelCount)
  219. {
  220. case 1:
  221. return (uint)97192.0f;
  222. case 2:
  223. return (uint)103280.0f;
  224. case 4:
  225. return (uint)109580.0f;
  226. case 6:
  227. return (uint)115070.0f;
  228. default:
  229. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  230. }
  231. }
  232. else
  233. {
  234. switch (command.Parameter.ChannelCount)
  235. {
  236. case 1:
  237. return (uint)492.01f;
  238. case 2:
  239. return (uint)554.46f;
  240. case 4:
  241. return (uint)595.86f;
  242. case 6:
  243. return (uint)656.62f;
  244. default:
  245. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  246. }
  247. }
  248. }
  249. if (command.Enabled)
  250. {
  251. switch (command.Parameter.ChannelCount)
  252. {
  253. case 1:
  254. return (uint)136460.0f;
  255. case 2:
  256. return (uint)145750.0f;
  257. case 4:
  258. return (uint)154800.0f;
  259. case 6:
  260. return (uint)161970.0f;
  261. default:
  262. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  263. }
  264. }
  265. else
  266. {
  267. switch (command.Parameter.ChannelCount)
  268. {
  269. case 1:
  270. return (uint)495.79f;
  271. case 2:
  272. return (uint)527.16f;
  273. case 4:
  274. return (uint)598.75f;
  275. case 6:
  276. return (uint)666.03f;
  277. default:
  278. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  279. }
  280. }
  281. }
  282. public uint Estimate(Reverb3dCommand command)
  283. {
  284. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  285. if (_sampleCount == 160)
  286. {
  287. if (command.Enabled)
  288. {
  289. switch (command.Parameter.ChannelCount)
  290. {
  291. case 1:
  292. return (uint)138840.0f;
  293. case 2:
  294. return (uint)135430.0f;
  295. case 4:
  296. return (uint)199180.0f;
  297. case 6:
  298. return (uint)247350.0f;
  299. default:
  300. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  301. }
  302. }
  303. else
  304. {
  305. switch (command.Parameter.ChannelCount)
  306. {
  307. case 1:
  308. return (uint)718.7f;
  309. case 2:
  310. return (uint)751.3f;
  311. case 4:
  312. return (uint)797.46f;
  313. case 6:
  314. return (uint)867.43f;
  315. default:
  316. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  317. }
  318. }
  319. }
  320. if (command.Enabled)
  321. {
  322. switch (command.Parameter.ChannelCount)
  323. {
  324. case 1:
  325. return (uint)199950.0f;
  326. case 2:
  327. return (uint)195200.0f;
  328. case 4:
  329. return (uint)290580.0f;
  330. case 6:
  331. return (uint)363490.0f;
  332. default:
  333. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  334. }
  335. }
  336. else
  337. {
  338. switch (command.Parameter.ChannelCount)
  339. {
  340. case 1:
  341. return (uint)534.24f;
  342. case 2:
  343. return (uint)570.87f;
  344. case 4:
  345. return (uint)660.93f;
  346. case 6:
  347. return (uint)694.6f;
  348. default:
  349. throw new NotImplementedException($"{command.Parameter.ChannelCount}");
  350. }
  351. }
  352. }
  353. public uint Estimate(AuxiliaryBufferCommand command)
  354. {
  355. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  356. if (_sampleCount == 160)
  357. {
  358. if (command.Enabled)
  359. {
  360. return (uint)7177.9f;
  361. }
  362. return (uint)489.16f;
  363. }
  364. if (command.Enabled)
  365. {
  366. return (uint)9499.8f;
  367. }
  368. return (uint)485.56f;
  369. }
  370. public uint Estimate(VolumeCommand command)
  371. {
  372. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  373. if (_sampleCount == 160)
  374. {
  375. return (uint)1280.3f;
  376. }
  377. return (uint)1737.8f;
  378. }
  379. public uint Estimate(CircularBufferSinkCommand command)
  380. {
  381. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  382. float costPerBuffer = 1726.0f;
  383. float baseCost = 1369.7f;
  384. if (_sampleCount == 160)
  385. {
  386. costPerBuffer = 853.63f;
  387. baseCost = 1284.5f;
  388. }
  389. return (uint)(baseCost + costPerBuffer * command.InputCount);
  390. }
  391. public uint Estimate(DownMixSurroundToStereoCommand command)
  392. {
  393. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  394. if (_sampleCount == 160)
  395. {
  396. return (uint)10009.0f;
  397. }
  398. return (uint)14577.0f;
  399. }
  400. public uint Estimate(UpsampleCommand command)
  401. {
  402. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  403. if (_sampleCount == 160)
  404. {
  405. return (uint)292000.0f;
  406. }
  407. return (uint)0.0f;
  408. }
  409. public uint Estimate(DeviceSinkCommand command)
  410. {
  411. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  412. Debug.Assert(command.InputCount == 2 || command.InputCount == 6);
  413. if (command.InputCount == 2)
  414. {
  415. if (_sampleCount == 160)
  416. {
  417. return (uint)9261.5f;
  418. }
  419. return (uint)9336.1f;
  420. }
  421. if (_sampleCount == 160)
  422. {
  423. return (uint)9111.8f;
  424. }
  425. return (uint)9566.7f;
  426. }
  427. public uint Estimate(PcmFloatDataSourceCommandVersion1 command)
  428. {
  429. // NOTE: This was added between REV7 and REV8 and for some reasons the estimator v2 was changed...
  430. Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
  431. float costPerSample = 3490.9f;
  432. float baseCost = 10091.0f;
  433. if (_sampleCount == 160)
  434. {
  435. costPerSample = 2310.4f;
  436. baseCost = 7845.3f;
  437. }
  438. return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / _sampleCount) * (command.Pitch * 0.000030518f))));
  439. }
  440. public uint Estimate(DataSourceVersion2Command command)
  441. {
  442. return 0;
  443. }
  444. public uint Estimate(LimiterCommandVersion1 command)
  445. {
  446. return 0;
  447. }
  448. public uint Estimate(LimiterCommandVersion2 command)
  449. {
  450. return 0;
  451. }
  452. public uint Estimate(GroupedBiquadFilterCommand command)
  453. {
  454. return 0;
  455. }
  456. public uint Estimate(CaptureBufferCommand command)
  457. {
  458. return 0;
  459. }
  460. }
  461. }