sink_context.h 2.2 KB

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