summaryrefslogtreecommitdiff
path: root/src/drivers/pcm_buffer.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-08-27 21:17:53 +1000
committerjacqueline <me@jacqueline.id.au>2024-08-28 09:45:19 +1000
commitf253d2ee7568b61ce2fab962f7328a50e2da6adf (patch)
tree394969e7827134684493b499503d7a08918a8867 /src/drivers/pcm_buffer.cpp
parentef227f8c518f2b6cfd5e55ca052a12e70515f2ef (diff)
downloadtangara-fw-f253d2ee7568b61ce2fab962f7328a50e2da6adf.tar.gz
Timeout when writing output samples throughout the audio pipeline
This allows the audio pipeline to remain responsive even when the drain buffer has completely filled. This in turn means that you now see the track info in the 'now playing' screen change if the current track changes whilst you are paused. Since I was fucking around a lot in the audio processor anyway, I also added mono->stereo expansion so that playing mono tracks on Bluetooth no longer destroys your ears.
Diffstat (limited to 'src/drivers/pcm_buffer.cpp')
-rw-r--r--src/drivers/pcm_buffer.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/drivers/pcm_buffer.cpp b/src/drivers/pcm_buffer.cpp
index 25762c50..071f5cea 100644
--- a/src/drivers/pcm_buffer.cpp
+++ b/src/drivers/pcm_buffer.cpp
@@ -17,6 +17,7 @@
#include "freertos/FreeRTOS.h"
#include "esp_heap_caps.h"
+#include "freertos/projdefs.h"
#include "freertos/ringbuf.h"
#include "portmacro.h"
@@ -39,9 +40,13 @@ PcmBuffer::~PcmBuffer() {
heap_caps_free(buf_);
}
-auto PcmBuffer::send(std::span<const int16_t> data) -> void {
- xRingbufferSend(ringbuf_, data.data(), data.size_bytes(), portMAX_DELAY);
+auto PcmBuffer::send(std::span<const int16_t> data) -> size_t {
+ if (!xRingbufferSend(ringbuf_, data.data(), data.size_bytes(),
+ pdMS_TO_TICKS(100))) {
+ return 0;
+ }
sent_ += data.size();
+ return data.size();
}
IRAM_ATTR auto PcmBuffer::receive(std::span<int16_t> dest, bool isr)