WaveBuffer.cs 3.4 KB

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