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