WaveBuffer.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.Server.MemoryPool;
  18. using System.Runtime.InteropServices;
  19. namespace Ryujinx.Audio.Renderer.Server.Voice
  20. {
  21. /// <summary>
  22. /// A wavebuffer used for server update.
  23. /// </summary>
  24. [StructLayout(LayoutKind.Sequential, Size = 0x58, Pack = 1)]
  25. public struct WaveBuffer
  26. {
  27. /// <summary>
  28. /// The <see cref="AddressInfo"/> of the sample data of the wavebuffer.
  29. /// </summary>
  30. public AddressInfo BufferAddressInfo;
  31. /// <summary>
  32. /// The <see cref="AddressInfo"/> of the context of the wavebuffer.
  33. /// </summary>
  34. /// <remarks>Only used by <see cref="Common.SampleFormat.Adpcm"/>.</remarks>
  35. public AddressInfo ContextAddressInfo;
  36. /// <summary>
  37. /// First sample to play of the wavebuffer.
  38. /// </summary>
  39. public uint StartSampleOffset;
  40. /// <summary>
  41. /// Last sample to play of the wavebuffer.
  42. /// </summary>
  43. public uint EndSampleOffset;
  44. /// <summary>
  45. /// Set to true if the wavebuffer is looping.
  46. /// </summary>
  47. [MarshalAs(UnmanagedType.I1)]
  48. public bool ShouldLoop;
  49. /// <summary>
  50. /// Set to true if the wavebuffer is the end of stream.
  51. /// </summary>
  52. [MarshalAs(UnmanagedType.I1)]
  53. public bool IsEndOfStream;
  54. /// <summary>
  55. /// Set to true if the wavebuffer wasn't sent to the <see cref="Dsp.AudioProcessor"/>.
  56. /// </summary>
  57. [MarshalAs(UnmanagedType.I1)]
  58. public bool IsSendToAudioProcessor;
  59. /// <summary>
  60. /// First sample to play when looping the wavebuffer.
  61. /// </summary>
  62. public uint LoopStartSampleOffset;
  63. /// <summary>
  64. /// Last sample to play when looping the wavebuffer.
  65. /// </summary>
  66. public uint LoopEndSampleOffset;
  67. /// <summary>
  68. /// The max loop count.
  69. /// </summary>
  70. public int LoopCount;
  71. /// <summary>
  72. /// Create a new <see cref="Common.WaveBuffer"/> for use by the <see cref="Dsp.AudioProcessor"/>.
  73. /// </summary>
  74. /// <param name="version">The target version of the wavebuffer.</param>
  75. /// <returns>A new <see cref="Common.WaveBuffer"/> for use by the <see cref="Dsp.AudioProcessor"/>.</returns>
  76. public Common.WaveBuffer ToCommon(int version)
  77. {
  78. Common.WaveBuffer waveBuffer = new Common.WaveBuffer();
  79. waveBuffer.Buffer = BufferAddressInfo.GetReference(true);
  80. waveBuffer.BufferSize = (uint)BufferAddressInfo.Size;
  81. if (ContextAddressInfo.CpuAddress != 0)
  82. {
  83. waveBuffer.Context = ContextAddressInfo.GetReference(true);
  84. waveBuffer.ContextSize = (uint)ContextAddressInfo.Size;
  85. }
  86. waveBuffer.StartSampleOffset = StartSampleOffset;
  87. waveBuffer.EndSampleOffset = EndSampleOffset;
  88. waveBuffer.Looping = ShouldLoop;
  89. waveBuffer.IsEndOfStream = IsEndOfStream;
  90. if (version == 2)
  91. {
  92. waveBuffer.LoopCount = LoopCount;
  93. waveBuffer.LoopStartSampleOffset = LoopStartSampleOffset;
  94. waveBuffer.LoopEndSampleOffset = LoopEndSampleOffset;
  95. }
  96. else
  97. {
  98. waveBuffer.LoopCount = -1;
  99. }
  100. return waveBuffer;
  101. }
  102. }
  103. }