diff options
Diffstat (limited to 'src/drivers/include')
| -rw-r--r-- | src/drivers/include/drivers/bluetooth.hpp | 13 | ||||
| -rw-r--r-- | src/drivers/include/drivers/i2s_dac.hpp | 5 | ||||
| -rw-r--r-- | src/drivers/include/drivers/pcm_buffer.hpp | 9 |
3 files changed, 16 insertions, 11 deletions
diff --git a/src/drivers/include/drivers/bluetooth.hpp b/src/drivers/include/drivers/bluetooth.hpp index 94a85263..b3b12ffc 100644 --- a/src/drivers/include/drivers/bluetooth.hpp +++ b/src/drivers/include/drivers/bluetooth.hpp @@ -43,7 +43,7 @@ class Bluetooth { auto SetPreferredDevice(std::optional<bluetooth::MacAndName> dev) -> void; auto PreferredDevice() -> std::optional<bluetooth::MacAndName>; - auto SetSource(PcmBuffer*) -> void; + auto SetSources(PcmBuffer*, PcmBuffer*) -> void; auto SetVolumeFactor(float) -> void; auto SetEventHandler(std::function<void(bluetooth::Event)> cb) -> void; @@ -57,7 +57,7 @@ struct Disable : public tinyfsm::Event {}; struct ConnectTimedOut : public tinyfsm::Event {}; struct PreferredDeviceChanged : public tinyfsm::Event {}; -struct SourceChanged : public tinyfsm::Event {}; +struct SourcesChanged : public tinyfsm::Event {}; struct DeviceDiscovered : public tinyfsm::Event { const Device& device; }; @@ -118,8 +118,8 @@ class BluetoothState : public tinyfsm::Fsm<BluetoothState> { static auto discovery() -> bool; static auto discovery(bool) -> void; - static auto source() -> PcmBuffer*; - static auto source(PcmBuffer*) -> void; + static auto sources() -> std::pair<PcmBuffer*, PcmBuffer*>; + static auto sources(PcmBuffer*, PcmBuffer*) -> void; static auto event_handler(std::function<void(Event)>) -> void; @@ -132,7 +132,7 @@ class BluetoothState : public tinyfsm::Fsm<BluetoothState> { virtual void react(const events::Disable& ev) = 0; virtual void react(const events::ConnectTimedOut& ev){}; virtual void react(const events::PreferredDeviceChanged& ev){}; - virtual void react(const events::SourceChanged& ev){}; + virtual void react(const events::SourcesChanged& ev){}; virtual void react(const events::DeviceDiscovered&); @@ -152,7 +152,6 @@ class BluetoothState : public tinyfsm::Fsm<BluetoothState> { static std::optional<bluetooth::MacAndName> sConnectingDevice_; static int sConnectAttemptsRemaining_; - static std::atomic<PcmBuffer*> sSource_; static std::function<void(Event)> sEventHandler_; auto connect(const bluetooth::MacAndName&) -> bool; @@ -205,7 +204,7 @@ class Connected : public BluetoothState { void exit() override; void react(const events::PreferredDeviceChanged& ev) override; - void react(const events::SourceChanged& ev) override; + void react(const events::SourcesChanged& ev) override; void react(const events::Disable& ev) override; void react(events::internal::Gap ev) override; diff --git a/src/drivers/include/drivers/i2s_dac.hpp b/src/drivers/include/drivers/i2s_dac.hpp index cf9258c0..0fe462b4 100644 --- a/src/drivers/include/drivers/i2s_dac.hpp +++ b/src/drivers/include/drivers/i2s_dac.hpp @@ -40,7 +40,7 @@ constexpr size_t kI2SBufferLengthFrames = 1024; */ class I2SDac { public: - static auto create(IGpios& expander, PcmBuffer&) -> std::optional<I2SDac*>; + static auto create(IGpios& expander, PcmBuffer&, PcmBuffer&) -> std::optional<I2SDac*>; I2SDac(IGpios& gpio, PcmBuffer&, i2s_chan_handle_t i2s_handle); ~I2SDac(); @@ -77,7 +77,8 @@ class I2SDac { auto set_channel(bool) -> void; IGpios& gpio_; - PcmBuffer& buffer_; + PcmBuffer& buffer1_; + PcmBuffer& buffer2_; i2s_chan_handle_t i2s_handle_; bool i2s_active_; diff --git a/src/drivers/include/drivers/pcm_buffer.hpp b/src/drivers/include/drivers/pcm_buffer.hpp index 6630f720..27e9eec6 100644 --- a/src/drivers/include/drivers/pcm_buffer.hpp +++ b/src/drivers/include/drivers/pcm_buffer.hpp @@ -35,8 +35,13 @@ class PcmBuffer { * Fills the given span with samples. If enough samples are available in * the buffer, then the span will be filled with samples from the buffer. Any * shortfall is made up by padding the given span with zeroes. + * + * If `mix` is set to true then, instead of overwriting the destination span, + * the retrieved samples will be mixed into any existing samples contained + * within the destination. This mixing uses a naive sum approach, and so may + * introduce clipping. */ - auto receive(std::span<int16_t>, bool isr) -> BaseType_t; + auto receive(std::span<int16_t>, bool mix, bool isr) -> BaseType_t; auto clear() -> void; auto isEmpty() -> bool; @@ -58,7 +63,7 @@ class PcmBuffer { PcmBuffer& operator=(const PcmBuffer&) = delete; private: - auto readSingle(std::span<int16_t>, bool isr) + auto readSingle(std::span<int16_t>, bool mix, bool isr) -> std::pair<size_t, BaseType_t>; StaticRingbuffer_t meta_; |
