DepopPrepareCommand.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Copyright (c) 2019-2020 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 System;
  19. namespace Ryujinx.Audio.Renderer.Dsp.Command
  20. {
  21. public class DepopPrepareCommand : ICommand
  22. {
  23. public bool Enabled { get; set; }
  24. public int NodeId { get; }
  25. public CommandType CommandType => CommandType.DepopPrepare;
  26. public ulong EstimatedProcessingTime { get; set; }
  27. public uint MixBufferCount { get; }
  28. public ushort[] OutputBufferIndices { get; }
  29. public Memory<VoiceUpdateState> State { get; }
  30. public Memory<float> DepopBuffer { get; }
  31. public DepopPrepareCommand(Memory<VoiceUpdateState> state, Memory<float> depopBuffer, uint mixBufferCount, uint bufferOffset, int nodeId, bool enabled)
  32. {
  33. Enabled = enabled;
  34. NodeId = nodeId;
  35. MixBufferCount = mixBufferCount;
  36. OutputBufferIndices = new ushort[RendererConstants.MixBufferCountMax];
  37. for (int i = 0; i < RendererConstants.MixBufferCountMax; i++)
  38. {
  39. OutputBufferIndices[i] = (ushort)(bufferOffset + i);
  40. }
  41. State = state;
  42. DepopBuffer = depopBuffer;
  43. }
  44. public void Process(CommandList context)
  45. {
  46. ref VoiceUpdateState state = ref State.Span[0];
  47. for (int i = 0; i < MixBufferCount; i++)
  48. {
  49. if (state.LastSamples[i] != 0)
  50. {
  51. DepopBuffer.Span[OutputBufferIndices[i]] += state.LastSamples[i];
  52. state.LastSamples[i] = 0;
  53. }
  54. }
  55. }
  56. }
  57. }