summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/include/drivers/pcm_buffer.hpp8
-rw-r--r--src/drivers/pcm_buffer.cpp9
2 files changed, 13 insertions, 4 deletions
diff --git a/src/drivers/include/drivers/pcm_buffer.hpp b/src/drivers/include/drivers/pcm_buffer.hpp
index 6630f720..8f53317e 100644
--- a/src/drivers/include/drivers/pcm_buffer.hpp
+++ b/src/drivers/include/drivers/pcm_buffer.hpp
@@ -28,8 +28,12 @@ class PcmBuffer {
PcmBuffer(size_t size_in_samples);
~PcmBuffer();
- /* Adds samples to the buffer. */
- auto send(std::span<const int16_t>) -> void;
+ /*
+ * Adds samples to the buffer. Returns the number of samples that were added,
+ * which may be less than the number of samples given if this PcmBuffer is
+ * close to full.
+ */
+ auto send(std::span<const int16_t>) -> size_t;
/*
* Fills the given span with samples. If enough samples are available in
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)