PcmInt16DataSourceCommandVersion1.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. SourceSampleRate = SampleRate,
  61. SampleFormat = SampleFormat.PcmInt16,
  62. Pitch = Pitch,
  63. DecodingBehaviour = DecodingBehaviour,
  64. ExtraParameter = 0,
  65. ExtraParameterSize = 0,
  66. ChannelIndex = (int)ChannelIndex,
  67. ChannelCount = (int)ChannelCount,
  68. };
  69. DataSourceHelper.ProcessWaveBuffers(context.MemoryManager, outputBuffer, ref info, WaveBuffers, ref State.Span[0], context.SampleRate, (int)context.SampleCount);
  70. }
  71. }
  72. }