AuxiliaryBufferHeader.cs 3.6 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.Memory;
  18. using System.Runtime.InteropServices;
  19. namespace Ryujinx.Audio.Renderer.Dsp.State
  20. {
  21. [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x80)]
  22. public struct AuxiliaryBufferHeader
  23. {
  24. [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x40)]
  25. public struct AuxiliaryBufferInfo
  26. {
  27. private const uint ReadOffsetPosition = 0x0;
  28. private const uint WriteOffsetPosition = 0x4;
  29. private const uint LostSampleCountPosition = 0x8;
  30. private const uint TotalSampleCountPosition = 0xC;
  31. public uint ReadOffset;
  32. public uint WriteOffset;
  33. public uint LostSampleCount;
  34. public uint TotalSampleCount;
  35. private unsafe fixed uint _unknown[12];
  36. public static uint GetReadOffset(IVirtualMemoryManager manager, ulong bufferAddress)
  37. {
  38. return manager.Read<uint>(bufferAddress + ReadOffsetPosition);
  39. }
  40. public static uint GetWriteOffset(IVirtualMemoryManager manager, ulong bufferAddress)
  41. {
  42. return manager.Read<uint>(bufferAddress + WriteOffsetPosition);
  43. }
  44. public static uint GetLostSampleCount(IVirtualMemoryManager manager, ulong bufferAddress)
  45. {
  46. return manager.Read<uint>(bufferAddress + LostSampleCountPosition);
  47. }
  48. public static uint GetTotalSampleCount(IVirtualMemoryManager manager, ulong bufferAddress)
  49. {
  50. return manager.Read<uint>(bufferAddress + TotalSampleCountPosition);
  51. }
  52. public static void SetReadOffset(IVirtualMemoryManager manager, ulong bufferAddress, uint value)
  53. {
  54. manager.Write(bufferAddress + ReadOffsetPosition, value);
  55. }
  56. public static void SetWriteOffset(IVirtualMemoryManager manager, ulong bufferAddress, uint value)
  57. {
  58. manager.Write(bufferAddress + WriteOffsetPosition, value);
  59. }
  60. public static void SetLostSampleCount(IVirtualMemoryManager manager, ulong bufferAddress, uint value)
  61. {
  62. manager.Write(bufferAddress + LostSampleCountPosition, value);
  63. }
  64. public static void SetTotalSampleCount(IVirtualMemoryManager manager, ulong bufferAddress, uint value)
  65. {
  66. manager.Write(bufferAddress + TotalSampleCountPosition, value);
  67. }
  68. public static void Reset(IVirtualMemoryManager manager, ulong bufferAddress)
  69. {
  70. // NOTE: Lost sample count is never reset, since REV10.
  71. manager.Write(bufferAddress + ReadOffsetPosition, 0UL);
  72. manager.Write(bufferAddress + TotalSampleCountPosition, 0);
  73. }
  74. }
  75. public AuxiliaryBufferInfo CpuBufferInfo;
  76. public AuxiliaryBufferInfo DspBufferInfo;
  77. }
  78. }