CommandBuffer.cs 25 KB

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