Fork of Tangara with customizations
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tangara-fw/src/audio/include/i2s_audio_output.hpp

45 lines
1.0 KiB

#pragma once
#include <cstdint>
#include <memory>
#include <vector>
2 years ago
#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 {
2 years ago
public:
enum Error { DAC_CONFIG, I2S_CONFIG, STREAM_INIT };
static auto create(drivers::GpioExpander* expander)
-> cpp::result<std::shared_ptr<I2SAudioOutput>, Error>;
I2SAudioOutput(drivers::GpioExpander* expander,
std::unique_ptr<drivers::AudioDac> dac);
~I2SAudioOutput();
auto Process(std::vector<Stream>* inputs, MutableStream* output)
-> void override;
I2SAudioOutput(const I2SAudioOutput&) = delete;
I2SAudioOutput& operator=(const I2SAudioOutput&) = delete;
2 years ago
private:
auto SetVolume(uint8_t volume) -> void;
drivers::GpioExpander* expander_;
std::unique_ptr<drivers::AudioDac> dac_;
std::optional<StreamInfo::Pcm> current_config_;
auto ProcessStreamInfo(const StreamInfo& info) -> bool;
};
} // namespace audio