CommandBuffer.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. //
  2. // Copyright (c) 2019-2021 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.Common;
  18. using Ryujinx.Audio.Renderer.Dsp.Command;
  19. using Ryujinx.Audio.Renderer.Dsp.State;
  20. using Ryujinx.Audio.Renderer.Parameter;
  21. using Ryujinx.Audio.Renderer.Parameter.Effect;
  22. using Ryujinx.Audio.Renderer.Server.Performance;
  23. using Ryujinx.Audio.Renderer.Server.Sink;
  24. using Ryujinx.Audio.Renderer.Server.Upsampler;
  25. using Ryujinx.Audio.Renderer.Server.Voice;
  26. using Ryujinx.Common.Memory;
  27. using System;
  28. using CpuAddress = System.UInt64;
  29. namespace Ryujinx.Audio.Renderer.Server
  30. {
  31. /// <summary>
  32. /// An API to generate commands and aggregate them into a <see cref="CommandList"/>.
  33. /// </summary>
  34. public class CommandBuffer
  35. {
  36. /// <summary>
  37. /// The command processing time estimator in use.
  38. /// </summary>
  39. private ICommandProcessingTimeEstimator _commandProcessingTimeEstimator;
  40. /// <summary>
  41. /// The estimated total processing time.
  42. /// </summary>
  43. public ulong EstimatedProcessingTime { get; set; }
  44. /// <summary>
  45. /// The command list that is populated by the <see cref="CommandBuffer"/>.
  46. /// </summary>
  47. public CommandList CommandList { get; }
  48. /// <summary>
  49. /// Create a new <see cref="CommandBuffer"/>.
  50. /// </summary>
  51. /// <param name="commandList">The command list that will store the generated commands.</param>
  52. /// <param name="commandProcessingTimeEstimator">The command processing time estimator to use.</param>
  53. public CommandBuffer(CommandList commandList, ICommandProcessingTimeEstimator commandProcessingTimeEstimator)
  54. {
  55. CommandList = commandList;
  56. EstimatedProcessingTime = 0;
  57. _commandProcessingTimeEstimator = commandProcessingTimeEstimator;
  58. }
  59. /// <summary>
  60. /// Add a new generated command to the <see cref="CommandList"/>.
  61. /// </summary>
  62. /// <param name="command">The command to add.</param>
  63. private void AddCommand(ICommand command)
  64. {
  65. EstimatedProcessingTime += command.EstimatedProcessingTime;
  66. CommandList.AddCommand(command);
  67. }
  68. /// <summary>
  69. /// Generate a new <see cref="ClearMixBufferCommand"/>.
  70. /// </summary>
  71. /// <param name="nodeId">The node id associated to this command.</param>
  72. public void GenerateClearMixBuffer(int nodeId)
  73. {
  74. ClearMixBufferCommand command = new ClearMixBufferCommand(nodeId);
  75. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  76. AddCommand(command);
  77. }
  78. /// <summary>
  79. /// Generate a new <see cref="DepopPrepareCommand"/>.
  80. /// </summary>
  81. /// <param name="state">The voice state associated.</param>
  82. /// <param name="depopBuffer">The depop buffer.</param>
  83. /// <param name="bufferCount">The buffer count.</param>
  84. /// <param name="bufferOffset">The target buffer offset.</param>
  85. /// <param name="nodeId">The node id associated to this command.</param>
  86. /// <param name="wasPlaying">Set to true if the voice was playing previously.</param>
  87. public void GenerateDepopPrepare(Memory<VoiceUpdateState> state, Memory<float> depopBuffer, uint bufferCount, uint bufferOffset, int nodeId, bool wasPlaying)
  88. {
  89. DepopPrepareCommand command = new DepopPrepareCommand(state, depopBuffer, bufferCount, bufferOffset, nodeId, wasPlaying);
  90. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  91. AddCommand(command);
  92. }
  93. /// <summary>
  94. /// Generate a new <see cref="PerformanceCommand"/>.
  95. /// </summary>
  96. /// <param name="performanceEntryAddresses">The <see cref="PerformanceEntryAddresses"/>.</param>
  97. /// <param name="type">The performance operation to perform.</param>
  98. /// <param name="nodeId">The node id associated to this command.</param>
  99. public void GeneratePerformance(ref PerformanceEntryAddresses performanceEntryAddresses, PerformanceCommand.Type type, int nodeId)
  100. {
  101. PerformanceCommand command = new PerformanceCommand(ref performanceEntryAddresses, type, nodeId);
  102. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  103. AddCommand(command);
  104. }
  105. /// <summary>
  106. /// Create a new <see cref="VolumeRampCommand"/>.
  107. /// </summary>
  108. /// <param name="previousVolume">The previous volume.</param>
  109. /// <param name="volume">The new volume.</param>
  110. /// <param name="bufferIndex">The index of the mix buffer to use.</param>
  111. /// <param name="nodeId">The node id associated to this command.</param>
  112. public void GenerateVolumeRamp(float previousVolume, float volume, uint bufferIndex, int nodeId)
  113. {
  114. VolumeRampCommand command = new VolumeRampCommand(previousVolume, volume, bufferIndex, nodeId);
  115. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  116. AddCommand(command);
  117. }
  118. /// <summary>
  119. /// Create a new <see cref="DataSourceVersion2Command"/>.
  120. /// </summary>
  121. /// <param name="voiceState">The <see cref="VoiceState"/> to generate the command from.</param>
  122. /// <param name="state">The <see cref="VoiceUpdateState"/> to generate the command from.</param>
  123. /// <param name="outputBufferIndex">The output buffer index to use.</param>
  124. /// <param name="channelIndex">The target channel index.</param>
  125. /// <param name="nodeId">The node id associated to this command.</param>
  126. public void GenerateDataSourceVersion2(ref VoiceState voiceState, Memory<VoiceUpdateState> state, ushort outputBufferIndex, ushort channelIndex, int nodeId)
  127. {
  128. DataSourceVersion2Command command = new DataSourceVersion2Command(ref voiceState, state, outputBufferIndex, channelIndex, nodeId);
  129. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  130. AddCommand(command);
  131. }
  132. /// <summary>
  133. /// Create a new <see cref="PcmInt16DataSourceCommandVersion1"/>.
  134. /// </summary>
  135. /// <param name="voiceState">The <see cref="VoiceState"/> to generate the command from.</param>
  136. /// <param name="state">The <see cref="VoiceUpdateState"/> to generate the command from.</param>
  137. /// <param name="outputBufferIndex">The output buffer index to use.</param>
  138. /// <param name="channelIndex">The target channel index.</param>
  139. /// <param name="nodeId">The node id associated to this command.</param>
  140. public void GeneratePcmInt16DataSourceVersion1(ref VoiceState voiceState, Memory<VoiceUpdateState> state, ushort outputBufferIndex, ushort channelIndex, int nodeId)
  141. {
  142. PcmInt16DataSourceCommandVersion1 command = new PcmInt16DataSourceCommandVersion1(ref voiceState, state, outputBufferIndex, channelIndex, nodeId);
  143. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  144. AddCommand(command);
  145. }
  146. /// <summary>
  147. /// Create a new <see cref="PcmFloatDataSourceCommandVersion1"/>.
  148. /// </summary>
  149. /// <param name="voiceState">The <see cref="VoiceState"/> to generate the command from.</param>
  150. /// <param name="state">The <see cref="VoiceUpdateState"/> to generate the command from.</param>
  151. /// <param name="outputBufferIndex">The output buffer index to use.</param>
  152. /// <param name="channelIndex">The target channel index.</param>
  153. /// <param name="nodeId">The node id associated to this command.</param>
  154. public void GeneratePcmFloatDataSourceVersion1(ref VoiceState voiceState, Memory<VoiceUpdateState> state, ushort outputBufferIndex, ushort channelIndex, int nodeId)
  155. {
  156. PcmFloatDataSourceCommandVersion1 command = new PcmFloatDataSourceCommandVersion1(ref voiceState, state, outputBufferIndex, channelIndex, nodeId);
  157. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  158. AddCommand(command);
  159. }
  160. /// <summary>
  161. /// Create a new <see cref="AdpcmDataSourceCommandVersion1"/>.
  162. /// </summary>
  163. /// <param name="voiceState">The <see cref="VoiceState"/> to generate the command from.</param>
  164. /// <param name="state">The <see cref="VoiceUpdateState"/> to generate the command from.</param>
  165. /// <param name="outputBufferIndex">The output buffer index to use.</param>
  166. /// <param name="nodeId">The node id associated to this command.</param>
  167. public void GenerateAdpcmDataSourceVersion1(ref VoiceState voiceState, Memory<VoiceUpdateState> state, ushort outputBufferIndex, int nodeId)
  168. {
  169. AdpcmDataSourceCommandVersion1 command = new AdpcmDataSourceCommandVersion1(ref voiceState, state, outputBufferIndex, nodeId);
  170. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  171. AddCommand(command);
  172. }
  173. /// <summary>
  174. /// Create a new <see cref="BiquadFilterCommand"/>.
  175. /// </summary>
  176. /// <param name="baseIndex">The base index of the input and output buffer.</param>
  177. /// <param name="filter">The biquad filter parameter.</param>
  178. /// <param name="biquadFilterStateMemory">The biquad state.</param>
  179. /// <param name="inputBufferOffset">The input buffer offset.</param>
  180. /// <param name="outputBufferOffset">The output buffer offset.</param>
  181. /// <param name="needInitialization">Set to true if the biquad filter state needs to be initialized.</param>
  182. /// <param name="nodeId">The node id associated to this command.</param>
  183. public void GenerateBiquadFilter(int baseIndex, ref BiquadFilterParameter filter, Memory<BiquadFilterState> biquadFilterStateMemory, int inputBufferOffset, int outputBufferOffset, bool needInitialization, int nodeId)
  184. {
  185. BiquadFilterCommand command = new BiquadFilterCommand(baseIndex, ref filter, biquadFilterStateMemory, inputBufferOffset, outputBufferOffset, needInitialization, nodeId);
  186. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  187. AddCommand(command);
  188. }
  189. /// <summary>
  190. /// Create a new <see cref="GroupedBiquadFilterCommand"/>.
  191. /// </summary>
  192. /// <param name="baseIndex">The base index of the input and output buffer.</param>
  193. /// <param name="filters">The biquad filter parameters.</param>
  194. /// <param name="biquadFilterStatesMemory">The biquad states.</param>
  195. /// <param name="inputBufferOffset">The input buffer offset.</param>
  196. /// <param name="outputBufferOffset">The output buffer offset.</param>
  197. /// <param name="isInitialized">Set to true if the biquad filter state is initialized.</param>
  198. /// <param name="nodeId">The node id associated to this command.</param>
  199. public void GenerateGroupedBiquadFilter(int baseIndex, ReadOnlySpan<BiquadFilterParameter> filters, Memory<BiquadFilterState> biquadFilterStatesMemory, int inputBufferOffset, int outputBufferOffset, ReadOnlySpan<bool> isInitialized, int nodeId)
  200. {
  201. GroupedBiquadFilterCommand command = new GroupedBiquadFilterCommand(baseIndex, filters, biquadFilterStatesMemory, inputBufferOffset, outputBufferOffset, isInitialized, nodeId);
  202. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  203. AddCommand(command);
  204. }
  205. /// <summary>
  206. /// Generate a new <see cref="MixRampGroupedCommand"/>.
  207. /// </summary>
  208. /// <param name="mixBufferCount">The mix buffer count.</param>
  209. /// <param name="inputBufferIndex">The base input index.</param>
  210. /// <param name="outputBufferIndex">The base output index.</param>
  211. /// <param name="previousVolume">The previous volume.</param>
  212. /// <param name="volume">The new volume.</param>
  213. /// <param name="state">The <see cref="VoiceUpdateState"/> to generate the command from.</param>
  214. /// <param name="nodeId">The node id associated to this command.</param>
  215. public void GenerateMixRampGrouped(uint mixBufferCount, uint inputBufferIndex, uint outputBufferIndex, Span<float> previousVolume, Span<float> volume, Memory<VoiceUpdateState> state, int nodeId)
  216. {
  217. MixRampGroupedCommand command = new MixRampGroupedCommand(mixBufferCount, inputBufferIndex, outputBufferIndex, previousVolume, volume, state, nodeId);
  218. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  219. AddCommand(command);
  220. }
  221. /// <summary>
  222. /// Generate a new <see cref="MixRampCommand"/>.
  223. /// </summary>
  224. /// <param name="previousVolume">The previous volume.</param>
  225. /// <param name="volume">The new volume.</param>
  226. /// <param name="inputBufferIndex">The input buffer index.</param>
  227. /// <param name="outputBufferIndex">The output buffer index.</param>
  228. /// <param name="lastSampleIndex">The index in the <see cref="VoiceUpdateState.LastSamples"/> array to store the ramped sample.</param>
  229. /// <param name="state">The <see cref="VoiceUpdateState"/> to generate the command from.</param>
  230. /// <param name="nodeId">The node id associated to this command.</param>
  231. public void GenerateMixRamp(float previousVolume, float volume, uint inputBufferIndex, uint outputBufferIndex, int lastSampleIndex, Memory<VoiceUpdateState> state, int nodeId)
  232. {
  233. MixRampCommand command = new MixRampCommand(previousVolume, volume, inputBufferIndex, outputBufferIndex, lastSampleIndex, state, nodeId);
  234. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  235. AddCommand(command);
  236. }
  237. /// <summary>
  238. /// Generate a new <see cref="DepopForMixBuffersCommand"/>.
  239. /// </summary>
  240. /// <param name="depopBuffer">The depop buffer.</param>
  241. /// <param name="bufferOffset">The target buffer offset.</param>
  242. /// <param name="bufferCount">The buffer count.</param>
  243. /// <param name="nodeId">The node id associated to this command.</param>
  244. /// <param name="sampleRate">The target sample rate in use.</param>
  245. public void GenerateDepopForMixBuffersCommand(Memory<float> depopBuffer, uint bufferOffset, uint bufferCount, int nodeId, uint sampleRate)
  246. {
  247. DepopForMixBuffersCommand command = new DepopForMixBuffersCommand(depopBuffer, bufferOffset, bufferCount, nodeId, sampleRate);
  248. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  249. AddCommand(command);
  250. }
  251. /// <summary>
  252. /// Generate a new <see cref="CopyMixBufferCommand"/>.
  253. /// </summary>
  254. /// <param name="inputBufferIndex">The input buffer index.</param>
  255. /// <param name="outputBufferIndex">The output buffer index.</param>
  256. /// <param name="nodeId">The node id associated to this command.</param>
  257. public void GenerateCopyMixBuffer(uint inputBufferIndex, uint outputBufferIndex, int nodeId)
  258. {
  259. CopyMixBufferCommand command = new CopyMixBufferCommand(inputBufferIndex, outputBufferIndex, nodeId);
  260. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  261. AddCommand(command);
  262. }
  263. /// <summary>
  264. /// Generate a new <see cref="MixCommand"/>.
  265. /// </summary>
  266. /// <param name="inputBufferIndex">The input buffer index.</param>
  267. /// <param name="outputBufferIndex">The output buffer index.</param>
  268. /// <param name="nodeId">The node id associated to this command.</param>
  269. /// <param name="volume">The mix volume.</param>
  270. public void GenerateMix(uint inputBufferIndex, uint outputBufferIndex, int nodeId, float volume)
  271. {
  272. MixCommand command = new MixCommand(inputBufferIndex, outputBufferIndex, nodeId, volume);
  273. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  274. AddCommand(command);
  275. }
  276. /// <summary>
  277. /// Generate a new <see cref="ReverbCommand"/>.
  278. /// </summary>
  279. /// <param name="bufferOffset">The target buffer offset.</param>
  280. /// <param name="parameter">The reverb parameter.</param>
  281. /// <param name="state">The reverb state.</param>
  282. /// <param name="isEnabled">Set to true if the effect should be active.</param>
  283. /// <param name="workBuffer">The work buffer to use for processing.</param>
  284. /// <param name="nodeId">The node id associated to this command.</param>
  285. /// <param name="isLongSizePreDelaySupported">If set to true, the long size pre-delay is supported.</param>
  286. public void GenerateReverbEffect(uint bufferOffset, ReverbParameter parameter, Memory<ReverbState> state, bool isEnabled, CpuAddress workBuffer, int nodeId, bool isLongSizePreDelaySupported)
  287. {
  288. if (parameter.IsChannelCountValid())
  289. {
  290. ReverbCommand command = new ReverbCommand(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId, isLongSizePreDelaySupported);
  291. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  292. AddCommand(command);
  293. }
  294. }
  295. /// <summary>
  296. /// Generate a new <see cref="Reverb3dCommand"/>.
  297. /// </summary>
  298. /// <param name="bufferOffset">The target buffer offset.</param>
  299. /// <param name="parameter">The reverb 3d parameter.</param>
  300. /// <param name="state">The reverb 3d state.</param>
  301. /// <param name="isEnabled">Set to true if the effect should be active.</param>
  302. /// <param name="workBuffer">The work buffer to use for processing.</param>
  303. /// <param name="nodeId">The node id associated to this command.</param>
  304. public void GenerateReverb3dEffect(uint bufferOffset, Reverb3dParameter parameter, Memory<Reverb3dState> state, bool isEnabled, CpuAddress workBuffer, int nodeId)
  305. {
  306. if (parameter.IsChannelCountValid())
  307. {
  308. Reverb3dCommand command = new Reverb3dCommand(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId);
  309. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  310. AddCommand(command);
  311. }
  312. }
  313. /// <summary>
  314. /// Generate a new <see cref="DelayCommand"/>.
  315. /// </summary>
  316. /// <param name="bufferOffset">The target buffer offset.</param>
  317. /// <param name="parameter">The delay parameter.</param>
  318. /// <param name="state">The delay state.</param>
  319. /// <param name="isEnabled">Set to true if the effect should be active.</param>
  320. /// <param name="workBuffer">The work buffer to use for processing.</param>
  321. /// <param name="nodeId">The node id associated to this command.</param>
  322. public void GenerateDelayEffect(uint bufferOffset, DelayParameter parameter, Memory<DelayState> state, bool isEnabled, CpuAddress workBuffer, int nodeId)
  323. {
  324. if (parameter.IsChannelCountValid())
  325. {
  326. DelayCommand command = new DelayCommand(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId);
  327. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  328. AddCommand(command);
  329. }
  330. }
  331. /// <summary>
  332. /// Generate a new <see cref="LimiterCommandVersion1"/>.
  333. /// </summary>
  334. /// <param name="bufferOffset">The target buffer offset.</param>
  335. /// <param name="parameter">The limiter parameter.</param>
  336. /// <param name="state">The limiter state.</param>
  337. /// <param name="isEnabled">Set to true if the effect should be active.</param>
  338. /// <param name="workBuffer">The work buffer to use for processing.</param>
  339. /// <param name="nodeId">The node id associated to this command.</param>
  340. public void GenerateLimiterEffectVersion1(uint bufferOffset, LimiterParameter parameter, Memory<LimiterState> state, bool isEnabled, ulong workBuffer, int nodeId)
  341. {
  342. if (parameter.IsChannelCountValid())
  343. {
  344. LimiterCommandVersion1 command = new LimiterCommandVersion1(bufferOffset, parameter, state, isEnabled, workBuffer, nodeId);
  345. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  346. AddCommand(command);
  347. }
  348. }
  349. /// <summary>
  350. /// Generate a new <see cref="LimiterCommandVersion2"/>.
  351. /// </summary>
  352. /// <param name="bufferOffset">The target buffer offset.</param>
  353. /// <param name="parameter">The limiter parameter.</param>
  354. /// <param name="state">The limiter state.</param>
  355. /// <param name="effectResultState">The DSP effect result state.</param>
  356. /// <param name="isEnabled">Set to true if the effect should be active.</param>
  357. /// <param name="workBuffer">The work buffer to use for processing.</param>
  358. /// <param name="nodeId">The node id associated to this command.</param>
  359. public void GenerateLimiterEffectVersion2(uint bufferOffset, LimiterParameter parameter, Memory<LimiterState> state, Memory<EffectResultState> effectResultState, bool isEnabled, ulong workBuffer, int nodeId)
  360. {
  361. if (parameter.IsChannelCountValid())
  362. {
  363. LimiterCommandVersion2 command = new LimiterCommandVersion2(bufferOffset, parameter, state, effectResultState, isEnabled, workBuffer, nodeId);
  364. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  365. AddCommand(command);
  366. }
  367. }
  368. /// <summary>
  369. /// Generate a new <see cref="AuxiliaryBufferCommand"/>.
  370. /// </summary>
  371. /// <param name="bufferOffset">The target buffer offset.</param>
  372. /// <param name="inputBufferOffset">The input buffer offset.</param>
  373. /// <param name="outputBufferOffset">The output buffer offset.</param>
  374. /// <param name="state">The aux state.</param>
  375. /// <param name="isEnabled">Set to true if the effect should be active.</param>
  376. /// <param name="countMax">The limit of the circular buffer.</param>
  377. /// <param name="outputBuffer">The guest address of the output buffer.</param>
  378. /// <param name="inputBuffer">The guest address of the input buffer.</param>
  379. /// <param name="updateCount">The count to add on the offset after write/read operations.</param>
  380. /// <param name="writeOffset">The write offset.</param>
  381. /// <param name="nodeId">The node id associated to this command.</param>
  382. public void GenerateAuxEffect(uint bufferOffset, byte inputBufferOffset, byte outputBufferOffset, ref AuxiliaryBufferAddresses state, bool isEnabled, uint countMax, CpuAddress outputBuffer, CpuAddress inputBuffer, uint updateCount, uint writeOffset, int nodeId)
  383. {
  384. if (state.SendBufferInfoBase != 0 && state.ReturnBufferInfoBase != 0)
  385. {
  386. AuxiliaryBufferCommand command = new AuxiliaryBufferCommand(bufferOffset, inputBufferOffset, outputBufferOffset, ref state, isEnabled, countMax, outputBuffer, inputBuffer, updateCount, writeOffset, nodeId);
  387. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  388. AddCommand(command);
  389. }
  390. }
  391. /// <summary>
  392. /// Generate a new <see cref="CaptureBufferCommand"/>.
  393. /// </summary>
  394. /// <param name="bufferOffset">The target buffer offset.</param>
  395. /// <param name="inputBufferOffset">The input buffer offset.</param>
  396. /// <param name="sendBufferInfo">The capture state.</param>
  397. /// <param name="isEnabled">Set to true if the effect should be active.</param>
  398. /// <param name="countMax">The limit of the circular buffer.</param>
  399. /// <param name="outputBuffer">The guest address of the output buffer.</param>
  400. /// <param name="updateCount">The count to add on the offset after write operations.</param>
  401. /// <param name="writeOffset">The write offset.</param>
  402. /// <param name="nodeId">The node id associated to this command.</param>
  403. public void GenerateCaptureEffect(uint bufferOffset, byte inputBufferOffset, ulong sendBufferInfo, bool isEnabled, uint countMax, CpuAddress outputBuffer, uint updateCount, uint writeOffset, int nodeId)
  404. {
  405. if (sendBufferInfo != 0)
  406. {
  407. CaptureBufferCommand command = new CaptureBufferCommand(bufferOffset, inputBufferOffset, sendBufferInfo, isEnabled, countMax, outputBuffer, updateCount, writeOffset, nodeId);
  408. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  409. AddCommand(command);
  410. }
  411. }
  412. /// <summary>
  413. /// Generate a new <see cref="VolumeCommand"/>.
  414. /// </summary>
  415. /// <param name="volume">The target volume to apply.</param>
  416. /// <param name="bufferOffset">The offset of the mix buffer.</param>
  417. /// <param name="nodeId">The node id associated to this command.</param>
  418. public void GenerateVolume(float volume, uint bufferOffset, int nodeId)
  419. {
  420. VolumeCommand command = new VolumeCommand(volume, bufferOffset, nodeId);
  421. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  422. AddCommand(command);
  423. }
  424. /// <summary>
  425. /// Create a new <see cref="CircularBufferSinkCommand"/>.
  426. /// </summary>
  427. /// <param name="bufferOffset">The offset of the mix buffer.</param>
  428. /// <param name="sink">The <see cref="BaseSink"/> of the circular buffer.</param>
  429. /// <param name="nodeId">The node id associated to this command.</param>
  430. public void GenerateCircularBuffer(uint bufferOffset, CircularBufferSink sink, int nodeId)
  431. {
  432. CircularBufferSinkCommand command = new CircularBufferSinkCommand(bufferOffset, ref sink.Parameter, ref sink.CircularBufferAddressInfo, sink.CurrentWriteOffset, nodeId);
  433. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  434. AddCommand(command);
  435. }
  436. /// <summary>
  437. /// Create a new <see cref="DownMixSurroundToStereoCommand"/>.
  438. /// </summary>
  439. /// <param name="bufferOffset">The offset of the mix buffer.</param>
  440. /// <param name="inputBufferOffset">The input buffer offset.</param>
  441. /// <param name="outputBufferOffset">The output buffer offset.</param>
  442. /// <param name="downMixParameter">The downmixer parameters to use.</param>
  443. /// <param name="nodeId">The node id associated to this command.</param>
  444. public void GenerateDownMixSurroundToStereo(uint bufferOffset, Span<byte> inputBufferOffset, Span<byte> outputBufferOffset, float[] downMixParameter, int nodeId)
  445. {
  446. DownMixSurroundToStereoCommand command = new DownMixSurroundToStereoCommand(bufferOffset, inputBufferOffset, outputBufferOffset, downMixParameter, nodeId);
  447. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  448. AddCommand(command);
  449. }
  450. /// <summary>
  451. /// Create a new <see cref="UpsampleCommand"/>.
  452. /// </summary>
  453. /// <param name="bufferOffset">The offset of the mix buffer.</param>
  454. /// <param name="upsampler">The <see cref="UpsamplerState"/> associated.</param>
  455. /// <param name="inputCount">The total input count.</param>
  456. /// <param name="inputBufferOffset">The input buffer mix offset.</param>
  457. /// <param name="bufferCountPerSample">The buffer count per sample.</param>
  458. /// <param name="sampleCount">The source sample count.</param>
  459. /// <param name="sampleRate">The source sample rate.</param>
  460. /// <param name="nodeId">The node id associated to this command.</param>
  461. public void GenerateUpsample(uint bufferOffset, UpsamplerState upsampler, uint inputCount, Span<byte> inputBufferOffset, uint bufferCountPerSample, uint sampleCount, uint sampleRate, int nodeId)
  462. {
  463. UpsampleCommand command = new UpsampleCommand(bufferOffset, upsampler, inputCount, inputBufferOffset, bufferCountPerSample, sampleCount, sampleRate, nodeId);
  464. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  465. AddCommand(command);
  466. }
  467. /// <summary>
  468. /// Create a new <see cref="DeviceSinkCommand"/>.
  469. /// </summary>
  470. /// <param name="bufferOffset">The offset of the mix buffer.</param>
  471. /// <param name="sink">The <see cref="BaseSink"/> of the device sink.</param>
  472. /// <param name="sessionId">The current audio renderer session id.</param>
  473. /// <param name="buffer">The mix buffer in use.</param>
  474. /// <param name="nodeId">The node id associated to this command.</param>
  475. public void GenerateDeviceSink(uint bufferOffset, DeviceSink sink, int sessionId, Memory<float> buffer, int nodeId)
  476. {
  477. DeviceSinkCommand command = new DeviceSinkCommand(bufferOffset, sink, sessionId, buffer, nodeId);
  478. command.EstimatedProcessingTime = _commandProcessingTimeEstimator.Estimate(command);
  479. AddCommand(command);
  480. }
  481. }
  482. }