#pragma once #include #include #include #include "audio_element.hpp" #include "chunk.hpp" #include "result.hpp" #include "dac.hpp" #include "gpio_expander.hpp" #include "stream_info.hpp" namespace audio { class I2SAudioOutput : public IAudioElement { public: enum Error { DAC_CONFIG, I2S_CONFIG, STREAM_INIT }; static auto create(drivers::GpioExpander* expander) -> cpp::result, Error>; I2SAudioOutput(drivers::GpioExpander* expander, std::unique_ptr dac); ~I2SAudioOutput(); auto Process(std::vector* inputs, MutableStream* output) -> void override; I2SAudioOutput(const I2SAudioOutput&) = delete; I2SAudioOutput& operator=(const I2SAudioOutput&) = delete; private: auto SetVolume(uint8_t volume) -> void; drivers::GpioExpander* expander_; std::unique_ptr dac_; std::optional current_config_; auto ProcessStreamInfo(const StreamInfo& info) -> bool; }; } // namespace audio