PcmInt16DataSourceCommandVersion1.cs 3.3 KB

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