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