DepopPrepareCommand.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Ryujinx.Audio.Renderer.Common;
  2. using System;
  3. namespace Ryujinx.Audio.Renderer.Dsp.Command
  4. {
  5. public class DepopPrepareCommand : ICommand
  6. {
  7. public bool Enabled { get; set; }
  8. public int NodeId { get; }
  9. public CommandType CommandType => CommandType.DepopPrepare;
  10. public uint EstimatedProcessingTime { get; set; }
  11. public uint MixBufferCount { get; }
  12. public ushort[] OutputBufferIndices { get; }
  13. public Memory<VoiceUpdateState> State { get; }
  14. public Memory<float> DepopBuffer { get; }
  15. public DepopPrepareCommand(Memory<VoiceUpdateState> state, Memory<float> depopBuffer, uint mixBufferCount, uint bufferOffset, int nodeId, bool enabled)
  16. {
  17. Enabled = enabled;
  18. NodeId = nodeId;
  19. MixBufferCount = mixBufferCount;
  20. OutputBufferIndices = new ushort[Constants.MixBufferCountMax];
  21. for (int i = 0; i < Constants.MixBufferCountMax; i++)
  22. {
  23. OutputBufferIndices[i] = (ushort)(bufferOffset + i);
  24. }
  25. State = state;
  26. DepopBuffer = depopBuffer;
  27. }
  28. public void Process(CommandList context)
  29. {
  30. ref VoiceUpdateState state = ref State.Span[0];
  31. Span<float> depopBuffer = DepopBuffer.Span;
  32. for (int i = 0; i < MixBufferCount; i++)
  33. {
  34. if (state.LastSamples[i] != 0)
  35. {
  36. depopBuffer[OutputBufferIndices[i]] += state.LastSamples[i];
  37. state.LastSamples[i] = 0;
  38. }
  39. }
  40. }
  41. }
  42. }