sink_context.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "audio_core/common.h"
  6. #include "common/common_funcs.h"
  7. #include "common/common_types.h"
  8. #include "common/swap.h"
  9. namespace AudioCore {
  10. using DownmixCoefficients = std::array<float_le, 4>;
  11. enum class SinkTypes : u8 {
  12. Invalid = 0,
  13. Device = 1,
  14. Circular = 2,
  15. };
  16. enum class SinkSampleFormat : u32_le {
  17. None = 0,
  18. Pcm8 = 1,
  19. Pcm16 = 2,
  20. Pcm24 = 3,
  21. Pcm32 = 4,
  22. PcmFloat = 5,
  23. Adpcm = 6,
  24. };
  25. class SinkInfo {
  26. public:
  27. struct CircularBufferIn {
  28. u64_le address;
  29. u32_le size;
  30. u32_le input_count;
  31. u32_le sample_count;
  32. u32_le previous_position;
  33. SinkSampleFormat sample_format;
  34. std::array<u8, AudioCommon::MAX_CHANNEL_COUNT> input;
  35. bool in_use;
  36. INSERT_PADDING_BYTES_NOINIT(5);
  37. };
  38. static_assert(sizeof(CircularBufferIn) == 0x28,
  39. "SinkInfo::CircularBufferIn is in invalid size");
  40. struct DeviceIn {
  41. std::array<u8, 255> device_name;
  42. INSERT_PADDING_BYTES_NOINIT(1);
  43. s32_le input_count;
  44. std::array<u8, AudioCommon::MAX_CHANNEL_COUNT> input;
  45. INSERT_PADDING_BYTES_NOINIT(1);
  46. bool down_matrix_enabled;
  47. DownmixCoefficients down_matrix_coef;
  48. };
  49. static_assert(sizeof(DeviceIn) == 0x11c, "SinkInfo::DeviceIn is an invalid size");
  50. struct InParams {
  51. SinkTypes type{};
  52. bool in_use{};
  53. INSERT_PADDING_BYTES(2);
  54. u32_le node_id{};
  55. INSERT_PADDING_WORDS(6);
  56. union {
  57. // std::array<u8, 0x120> raw{};
  58. DeviceIn device;
  59. CircularBufferIn circular_buffer;
  60. };
  61. };
  62. static_assert(sizeof(InParams) == 0x140, "SinkInfo::InParams are an invalid size!");
  63. };
  64. class SinkContext {
  65. public:
  66. explicit SinkContext(std::size_t sink_count_);
  67. ~SinkContext();
  68. [[nodiscard]] std::size_t GetCount() const;
  69. void UpdateMainSink(const SinkInfo::InParams& in);
  70. [[nodiscard]] bool InUse() const;
  71. [[nodiscard]] std::vector<u8> OutputBuffers() const;
  72. [[nodiscard]] bool HasDownMixingCoefficients() const;
  73. [[nodiscard]] const DownmixCoefficients& GetDownmixCoefficients() const;
  74. private:
  75. bool in_use{false};
  76. s32 use_count{};
  77. std::array<u8, AudioCommon::MAX_CHANNEL_COUNT> buffers{};
  78. std::size_t sink_count{};
  79. bool has_downmix_coefs{false};
  80. DownmixCoefficients downmix_coefficients{};
  81. };
  82. } // namespace AudioCore