PcmInt16DataSourceCommandVersion1.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 System;
  19. using static Ryujinx.Audio.Renderer.Parameter.VoiceInParameter;
  20. namespace Ryujinx.Audio.Renderer.Dsp.Command
  21. {
  22. public class PcmInt16DataSourceCommandVersion1 : ICommand
  23. {
  24. public bool Enabled { get; set; }
  25. public int NodeId { get; }
  26. public CommandType CommandType => CommandType.PcmInt16DataSourceVersion1;
  27. public ulong EstimatedProcessingTime { get; set; }
  28. public ushort OutputBufferIndex { get; }
  29. public uint SampleRate { get; }
  30. public uint ChannelIndex { get; }
  31. public uint ChannelCount { get; }
  32. public float Pitch { get; }
  33. public WaveBuffer[] WaveBuffers { get; }
  34. public Memory<VoiceUpdateState> State { get; }
  35. public DecodingBehaviour DecodingBehaviour { get; }
  36. public PcmInt16DataSourceCommandVersion1(ref Server.Voice.VoiceState serverState, Memory<VoiceUpdateState> state, ushort outputBufferIndex, ushort channelIndex, int nodeId)
  37. {
  38. Enabled = true;
  39. NodeId = nodeId;
  40. OutputBufferIndex = (ushort)(channelIndex + outputBufferIndex);
  41. SampleRate = serverState.SampleRate;
  42. ChannelIndex = channelIndex;
  43. ChannelCount = serverState.ChannelsCount;
  44. Pitch = serverState.Pitch;
  45. WaveBuffers = new WaveBuffer[RendererConstants.VoiceWaveBufferCount];
  46. for (int i = 0; i < WaveBuffers.Length; i++)
  47. {
  48. ref Server.Voice.WaveBuffer voiceWaveBuffer = ref serverState.WaveBuffers[i];
  49. WaveBuffers[i] = voiceWaveBuffer.ToCommon(1);
  50. }
  51. State = state;
  52. DecodingBehaviour = serverState.DecodingBehaviour;
  53. }
  54. public void Process(CommandList context)
  55. {
  56. Span<float> outputBuffer = context.GetBuffer(OutputBufferIndex);
  57. DataSourceHelper.WaveBufferInformation info = new DataSourceHelper.WaveBufferInformation()
  58. {
  59. State = State,
  60. SourceSampleRate = SampleRate,
  61. SampleFormat = SampleFormat.PcmInt16,
  62. Pitch = Pitch,
  63. DecodingBehaviour = DecodingBehaviour,
  64. WaveBuffers = WaveBuffers,
  65. ExtraParameter = 0,
  66. ExtraParameterSize = 0,
  67. ChannelIndex = (int)ChannelIndex,
  68. ChannelCount = (int)ChannelCount,
  69. };
  70. DataSourceHelper.ProcessWaveBuffers(context.MemoryManager, outputBuffer, info, context.SampleRate, (int)context.SampleCount);
  71. }
  72. }
  73. }