CommandBuffer.cs 30 KB

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