From 41e0605f17a784e8f125b3ad10ddfe5ef63337d9 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 8 Jul 2024 15:06:43 +1000 Subject: Give PcmBuffer pairs a name, and wire them up in the audio stack --- src/drivers/include/drivers/bluetooth.hpp | 6 +++--- src/drivers/include/drivers/i2s_dac.hpp | 8 ++++---- src/drivers/include/drivers/pcm_buffer.hpp | 12 ++++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) (limited to 'src/drivers/include') diff --git a/src/drivers/include/drivers/bluetooth.hpp b/src/drivers/include/drivers/bluetooth.hpp index b3b12ffc..eaecfb2b 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 dev) -> void; auto PreferredDevice() -> std::optional; - auto SetSources(PcmBuffer*, PcmBuffer*) -> void; + auto SetSources(OutputBuffers*) -> void; auto SetVolumeFactor(float) -> void; auto SetEventHandler(std::function cb) -> void; @@ -118,8 +118,8 @@ class BluetoothState : public tinyfsm::Fsm { static auto discovery() -> bool; static auto discovery(bool) -> void; - static auto sources() -> std::pair; - static auto sources(PcmBuffer*, PcmBuffer*) -> void; + static auto sources() -> OutputBuffers*; + static auto sources(OutputBuffers*) -> void; static auto event_handler(std::function) -> void; diff --git a/src/drivers/include/drivers/i2s_dac.hpp b/src/drivers/include/drivers/i2s_dac.hpp index 0fe462b4..891acb56 100644 --- a/src/drivers/include/drivers/i2s_dac.hpp +++ b/src/drivers/include/drivers/i2s_dac.hpp @@ -40,9 +40,10 @@ constexpr size_t kI2SBufferLengthFrames = 1024; */ class I2SDac { public: - static auto create(IGpios& expander, PcmBuffer&, PcmBuffer&) -> std::optional; + static auto create(IGpios& expander, OutputBuffers&) + -> std::optional; - I2SDac(IGpios& gpio, PcmBuffer&, i2s_chan_handle_t i2s_handle); + I2SDac(IGpios& gpio, OutputBuffers&, i2s_chan_handle_t i2s_handle); ~I2SDac(); auto SetPaused(bool) -> void; @@ -77,8 +78,7 @@ class I2SDac { auto set_channel(bool) -> void; IGpios& gpio_; - PcmBuffer& buffer1_; - PcmBuffer& buffer2_; + OutputBuffers& buffers_; 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 27e9eec6..968c3398 100644 --- a/src/drivers/include/drivers/pcm_buffer.hpp +++ b/src/drivers/include/drivers/pcm_buffer.hpp @@ -74,4 +74,16 @@ class PcmBuffer { RingbufHandle_t ringbuf_; }; +/* + * Convenience type for a pair of PcmBuffers. Each audio output handles mixing + * streams together to ensure that low-latency sounds in one channel (e.g. a + * system notification bleep) aren't delayed by a large audio buffer in the + * other channel (e.g. a long-running track). + * + * By convention, the first buffer of this pair is used for tracks, whilst the + * second is reserved for 'system sounds'; usually TTS, but potentially maybe + * other informative noises. + */ +using OutputBuffers = std::pair; + } // namespace drivers -- cgit v1.2.3