sink_context.h 2.4 KB

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