summaryrefslogtreecommitdiff
path: root/src/drivers/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/include')
-rw-r--r--src/drivers/include/drivers/bluetooth.hpp6
-rw-r--r--src/drivers/include/drivers/i2s_dac.hpp8
-rw-r--r--src/drivers/include/drivers/pcm_buffer.hpp12
3 files changed, 19 insertions, 7 deletions
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<bluetooth::MacAndName> dev) -> void;
auto PreferredDevice() -> std::optional<bluetooth::MacAndName>;
- auto SetSources(PcmBuffer*, PcmBuffer*) -> void;
+ auto SetSources(OutputBuffers*) -> void;
auto SetVolumeFactor(float) -> void;
auto SetEventHandler(std::function<void(bluetooth::Event)> cb) -> void;
@@ -118,8 +118,8 @@ class BluetoothState : public tinyfsm::Fsm<BluetoothState> {
static auto discovery() -> bool;
static auto discovery(bool) -> void;
- static auto sources() -> std::pair<PcmBuffer*, PcmBuffer*>;
- static auto sources(PcmBuffer*, PcmBuffer*) -> void;
+ static auto sources() -> OutputBuffers*;
+ static auto sources(OutputBuffers*) -> void;
static auto event_handler(std::function<void(Event)>) -> 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<I2SDac*>;
+ static auto create(IGpios& expander, OutputBuffers&)
+ -> std::optional<I2SDac*>;
- 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<PcmBuffer, PcmBuffer>;
+
} // namespace drivers