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

49 lines
1.3 KiB

#pragma once
#include <cstdint>
#include <memory>
2 years ago
#include "audio_element.hpp"
#include "result.hpp"
#include "dac.hpp"
#include "gpio_expander.hpp"
#include "sys/_stdint.h"
namespace audio {
class I2SAudioOutput : public IAudioElement {
2 years ago
public:
enum Error { DAC_CONFIG, I2S_CONFIG, STREAM_INIT };
static auto create(drivers::GpioExpander* expander)
2 years ago
-> cpp::result<std::unique_ptr<I2SAudioOutput>, Error>;
I2SAudioOutput(drivers::GpioExpander* expander,
std::unique_ptr<drivers::AudioDac> dac);
~I2SAudioOutput();
auto SetInputBuffer(MessageBufferHandle_t* in) -> void { input_buffer_ = in; }
auto IdleTimeout() const -> TickType_t override;
auto ProcessStreamInfo(const StreamInfo& info)
-> cpp::result<void, AudioProcessingError> override;
auto ProcessChunk(const cpp::span<std::byte>& chunk)
-> cpp::result<std::size_t, AudioProcessingError> override;
auto ProcessIdle() -> cpp::result<void, AudioProcessingError> override;
I2SAudioOutput(const I2SAudioOutput&) = delete;
I2SAudioOutput& operator=(const I2SAudioOutput&) = delete;
2 years ago
private:
auto SetVolume(uint8_t volume) -> void;
auto SetSoftMute(bool enabled) -> void;
drivers::GpioExpander* expander_;
std::unique_ptr<drivers::AudioDac> dac_;
uint8_t volume_;
bool is_soft_muted_;
};
} // namespace audio