aux_.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include "audio_core/common/common.h"
  6. #include "audio_core/renderer/effect/effect_info_base.h"
  7. #include "common/common_types.h"
  8. namespace AudioCore::Renderer {
  9. /**
  10. * Auxiliary Buffer used for Aux commands.
  11. * Send and return buffers are available (names from the game's perspective).
  12. * Send is read by the host, containing a buffer of samples to be used for whatever purpose.
  13. * Return is written by the host, writing a mix buffer back to the game.
  14. * This allows the game to use pre-processed samples skipping the other render processing,
  15. * and to examine or modify what the audio renderer has generated.
  16. */
  17. class AuxInfo : public EffectInfoBase {
  18. public:
  19. struct ParameterVersion1 {
  20. /* 0x00 */ std::array<s8, MaxMixBuffers> inputs;
  21. /* 0x18 */ std::array<s8, MaxMixBuffers> outputs;
  22. /* 0x30 */ u32 mix_buffer_count;
  23. /* 0x34 */ u32 sample_rate;
  24. /* 0x38 */ u32 count_max;
  25. /* 0x3C */ u32 mix_buffer_count_max;
  26. /* 0x40 */ CpuAddr send_buffer_info_address;
  27. /* 0x48 */ CpuAddr send_buffer_address;
  28. /* 0x50 */ CpuAddr return_buffer_info_address;
  29. /* 0x58 */ CpuAddr return_buffer_address;
  30. /* 0x60 */ u32 mix_buffer_sample_size;
  31. /* 0x64 */ u32 sample_count;
  32. /* 0x68 */ u32 mix_buffer_sample_count;
  33. };
  34. static_assert(sizeof(ParameterVersion1) <= sizeof(EffectInfoBase::InParameterVersion1),
  35. "AuxInfo::ParameterVersion1 has the wrong size!");
  36. struct ParameterVersion2 {
  37. /* 0x00 */ std::array<s8, MaxMixBuffers> inputs;
  38. /* 0x18 */ std::array<s8, MaxMixBuffers> outputs;
  39. /* 0x30 */ u32 mix_buffer_count;
  40. /* 0x34 */ u32 sample_rate;
  41. /* 0x38 */ u32 count_max;
  42. /* 0x3C */ u32 mix_buffer_count_max;
  43. /* 0x40 */ CpuAddr send_buffer_info_address;
  44. /* 0x48 */ CpuAddr send_buffer_address;
  45. /* 0x50 */ CpuAddr return_buffer_info_address;
  46. /* 0x58 */ CpuAddr return_buffer_address;
  47. /* 0x60 */ u32 mix_buffer_sample_size;
  48. /* 0x64 */ u32 sample_count;
  49. /* 0x68 */ u32 mix_buffer_sample_count;
  50. };
  51. static_assert(sizeof(ParameterVersion2) <= sizeof(EffectInfoBase::InParameterVersion2),
  52. "AuxInfo::ParameterVersion2 has the wrong size!");
  53. struct AuxInfoDsp {
  54. /* 0x00 */ u32 read_offset;
  55. /* 0x04 */ u32 write_offset;
  56. /* 0x08 */ u32 lost_sample_count;
  57. /* 0x0C */ u32 total_sample_count;
  58. /* 0x10 */ char unk10[0x30];
  59. };
  60. static_assert(sizeof(AuxInfoDsp) == 0x40, "AuxInfo::AuxInfoDsp has the wrong size!");
  61. struct AuxBufferInfo {
  62. /* 0x00 */ AuxInfoDsp cpu_info;
  63. /* 0x40 */ AuxInfoDsp dsp_info;
  64. };
  65. static_assert(sizeof(AuxBufferInfo) == 0x80, "AuxInfo::AuxBufferInfo has the wrong size!");
  66. /**
  67. * Update the info with new parameters, version 1.
  68. *
  69. * @param error_info - Used to write call result code.
  70. * @param in_params - New parameters to update the info with.
  71. * @param pool_mapper - Pool for mapping buffers.
  72. */
  73. void Update(BehaviorInfo::ErrorInfo& error_info, const InParameterVersion1& in_params,
  74. const PoolMapper& pool_mapper) override;
  75. /**
  76. * Update the info with new parameters, version 2.
  77. *
  78. * @param error_info - Used to write call result code.
  79. * @param in_params - New parameters to update the info with.
  80. * @param pool_mapper - Pool for mapping buffers.
  81. */
  82. void Update(BehaviorInfo::ErrorInfo& error_info, const InParameterVersion2& in_params,
  83. const PoolMapper& pool_mapper) override;
  84. /**
  85. * Update the info after command generation. Usually only changes its state.
  86. */
  87. void UpdateForCommandGeneration() override;
  88. /**
  89. * Initialize a new result state. Version 2 only, unused.
  90. *
  91. * @param result_state - Result state to initialize.
  92. */
  93. void InitializeResultState(EffectResultState& result_state) override;
  94. /**
  95. * Update the host-side state with the ADSP-side state. Version 2 only, unused.
  96. *
  97. * @param cpu_state - Host-side result state to update.
  98. * @param dsp_state - AudioRenderer-side result state to update from.
  99. */
  100. void UpdateResultState(EffectResultState& cpu_state, EffectResultState& dsp_state) override;
  101. /**
  102. * Get a workbuffer assigned to this effect with the given index.
  103. *
  104. * @param index - Workbuffer index.
  105. * @return Address of the buffer.
  106. */
  107. CpuAddr GetWorkbuffer(s32 index) override;
  108. };
  109. } // namespace AudioCore::Renderer