CommandBuffer.cs 30 KB

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