AdpcmDataSourceCommandVersion1.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. using static Ryujinx.Audio.Renderer.Parameter.VoiceInParameter;
  20. namespace Ryujinx.Audio.Renderer.Dsp.Command
  21. {
  22. public class AdpcmDataSourceCommandVersion1 : ICommand
  23. {
  24. public bool Enabled { get; set; }
  25. public int NodeId { get; }
  26. public CommandType CommandType => CommandType.AdpcmDataSourceVersion1;
  27. public ulong EstimatedProcessingTime { get; set; }
  28. public ushort OutputBufferIndex { get; }
  29. public uint SampleRate { get; }
  30. public float Pitch { get; }
  31. public WaveBuffer[] WaveBuffers { get; }
  32. public Memory<VoiceUpdateState> State { get; }
  33. public ulong AdpcmParameter { get; }
  34. public ulong AdpcmParameterSize { get; }
  35. public DecodingBehaviour DecodingBehaviour { get; }
  36. public AdpcmDataSourceCommandVersion1(ref Server.Voice.VoiceState serverState, Memory<VoiceUpdateState> state, ushort outputBufferIndex, int nodeId)
  37. {
  38. Enabled = true;
  39. NodeId = nodeId;
  40. OutputBufferIndex = outputBufferIndex;
  41. SampleRate = serverState.SampleRate;
  42. Pitch = serverState.Pitch;
  43. WaveBuffers = new WaveBuffer[RendererConstants.VoiceWaveBufferCount];
  44. for (int i = 0; i < WaveBuffers.Length; i++)
  45. {
  46. ref Server.Voice.WaveBuffer voiceWaveBuffer = ref serverState.WaveBuffers[i];
  47. WaveBuffers[i] = voiceWaveBuffer.ToCommon(1);
  48. }
  49. AdpcmParameter = serverState.DataSourceStateAddressInfo.GetReference(true);
  50. AdpcmParameterSize = serverState.DataSourceStateAddressInfo.Size;
  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.Adpcm,
  62. Pitch = Pitch,
  63. DecodingBehaviour = DecodingBehaviour,
  64. WaveBuffers = WaveBuffers,
  65. ExtraParameter = AdpcmParameter,
  66. ExtraParameterSize = AdpcmParameterSize,
  67. ChannelIndex = 0,
  68. ChannelCount = 1,
  69. };
  70. DataSourceHelper.ProcessWaveBuffers(context.MemoryManager, outputBuffer, info, context.SampleRate, (int)context.SampleCount);
  71. }
  72. }
  73. }