2020-07-12 04:59:14 -07:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "audio_core/common.h"
|
|
|
|
#include "common/common_funcs.h"
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/swap.h"
|
|
|
|
|
|
|
|
namespace AudioCore {
|
|
|
|
|
2020-11-16 20:40:19 -08:00
|
|
|
using DownmixCoefficients = std::array<float_le, 4>;
|
|
|
|
|
2020-07-12 04:59:14 -07:00
|
|
|
enum class SinkTypes : u8 {
|
|
|
|
Invalid = 0,
|
|
|
|
Device = 1,
|
|
|
|
Circular = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class SinkSampleFormat : u32_le {
|
|
|
|
None = 0,
|
|
|
|
Pcm8 = 1,
|
|
|
|
Pcm16 = 2,
|
|
|
|
Pcm24 = 3,
|
|
|
|
Pcm32 = 4,
|
|
|
|
PcmFloat = 5,
|
|
|
|
Adpcm = 6,
|
|
|
|
};
|
|
|
|
|
|
|
|
class SinkInfo {
|
|
|
|
public:
|
|
|
|
struct CircularBufferIn {
|
|
|
|
u64_le address;
|
|
|
|
u32_le size;
|
|
|
|
u32_le input_count;
|
|
|
|
u32_le sample_count;
|
|
|
|
u32_le previous_position;
|
|
|
|
SinkSampleFormat sample_format;
|
|
|
|
std::array<u8, AudioCommon::MAX_CHANNEL_COUNT> input;
|
|
|
|
bool in_use;
|
|
|
|
INSERT_UNION_PADDING_BYTES(5);
|
|
|
|
};
|
2020-11-25 12:21:03 -08:00
|
|
|
static_assert(sizeof(CircularBufferIn) == 0x28,
|
2020-07-12 04:59:14 -07:00
|
|
|
"SinkInfo::CircularBufferIn is in invalid size");
|
|
|
|
|
|
|
|
struct DeviceIn {
|
|
|
|
std::array<u8, 255> device_name;
|
|
|
|
INSERT_UNION_PADDING_BYTES(1);
|
|
|
|
s32_le input_count;
|
|
|
|
std::array<u8, AudioCommon::MAX_CHANNEL_COUNT> input;
|
|
|
|
INSERT_UNION_PADDING_BYTES(1);
|
|
|
|
bool down_matrix_enabled;
|
2020-11-16 20:40:19 -08:00
|
|
|
DownmixCoefficients down_matrix_coef;
|
2020-07-12 04:59:14 -07:00
|
|
|
};
|
2020-11-25 12:21:03 -08:00
|
|
|
static_assert(sizeof(DeviceIn) == 0x11c, "SinkInfo::DeviceIn is an invalid size");
|
2020-07-12 04:59:14 -07:00
|
|
|
|
|
|
|
struct InParams {
|
|
|
|
SinkTypes type{};
|
|
|
|
bool in_use{};
|
|
|
|
INSERT_PADDING_BYTES(2);
|
|
|
|
u32_le node_id{};
|
|
|
|
INSERT_PADDING_WORDS(6);
|
|
|
|
union {
|
|
|
|
// std::array<u8, 0x120> raw{};
|
2020-11-25 12:21:03 -08:00
|
|
|
DeviceIn device;
|
|
|
|
CircularBufferIn circular_buffer;
|
2020-07-12 04:59:14 -07:00
|
|
|
};
|
|
|
|
};
|
2020-11-25 12:21:03 -08:00
|
|
|
static_assert(sizeof(InParams) == 0x140, "SinkInfo::InParams are an invalid size!");
|
2020-07-12 04:59:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class SinkContext {
|
|
|
|
public:
|
2020-11-25 12:21:03 -08:00
|
|
|
explicit SinkContext(std::size_t sink_count_);
|
2020-07-12 04:59:14 -07:00
|
|
|
~SinkContext();
|
|
|
|
|
2020-11-16 19:14:29 -08:00
|
|
|
[[nodiscard]] std::size_t GetCount() const;
|
2020-07-12 04:59:14 -07:00
|
|
|
|
2020-11-16 19:14:29 -08:00
|
|
|
void UpdateMainSink(const SinkInfo::InParams& in);
|
|
|
|
[[nodiscard]] bool InUse() const;
|
|
|
|
[[nodiscard]] std::vector<u8> OutputBuffers() const;
|
|
|
|
|
|
|
|
[[nodiscard]] bool HasDownMixingCoefficients() const;
|
2020-11-16 20:40:19 -08:00
|
|
|
[[nodiscard]] const DownmixCoefficients& GetDownmixCoefficients() const;
|
2020-07-12 04:59:14 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool in_use{false};
|
|
|
|
s32 use_count{};
|
|
|
|
std::array<u8, AudioCommon::MAX_CHANNEL_COUNT> buffers{};
|
|
|
|
std::size_t sink_count{};
|
2020-11-16 20:40:19 -08:00
|
|
|
bool has_downmix_coefs{false};
|
|
|
|
DownmixCoefficients downmix_coefficients{};
|
2020-07-12 04:59:14 -07:00
|
|
|
};
|
|
|
|
} // namespace AudioCore
|