15 std::unique_ptr<AudioSinkTransferBuffer> sink_buffer = make_unique<AudioSinkTransferBuffer>();
17 if (!sink_buffer->allocate_buffer_(buffer_size)) {
25 std::unique_ptr<AudioSourceTransferBuffer> source_buffer = make_unique<AudioSourceTransferBuffer>();
27 if (!source_buffer->allocate_buffer_(buffer_size)) {
74 return ((this->
ring_buffer_->available() > 0) || (this->available() > 0));
97 if (new_buffer ==
nullptr) {
114 if (this->
buffer_ ==
nullptr) {
125 if (this->
buffer_ !=
nullptr) {
146 size_t bytes_read = 0;
147 if (bytes_to_read > 0) {
158 size_t bytes_written = 0;
181 return bytes_written;
191 return ((this->
ring_buffer_->available() > 0) || (this->available() > 0));
206 bytes = std::min(bytes, this->
length_);
An STL allocator that uses SPI or internal RAM.
T * reallocate(T *p, size_t n)
void deallocate(T *p, size_t n)
virtual size_t audio_sink_write(uint8_t *data, size_t length, TickType_t ticks_to_wait)=0
size_t transfer_data_to_sink(TickType_t ticks_to_wait, bool post_shift=true)
Writes any available data in the transfer buffer to the sink.
void clear_buffered_data() override
AudioSinkCallback * sink_callback_
bool has_buffered_data() const override
speaker::Speaker * speaker_
static std::unique_ptr< AudioSinkTransferBuffer > create(size_t buffer_size)
Creates a new sink transfer buffer.
size_t transfer_data_from_source(TickType_t ticks_to_wait, bool pre_shift=true)
Reads any available data from the source into the transfer buffer.
static std::unique_ptr< AudioSourceTransferBuffer > create(size_t buffer_size)
Creates a new source transfer buffer.
size_t free() const override
bool has_buffered_data() const override
size_t free() const
Returns the transfer buffer's currrently free bytes available to write.
virtual bool has_buffered_data() const
Tests if there is any data in the tranfer buffer or the source/sink.
virtual void clear_buffered_data()
Clears data in the transfer buffer and, if possible, the source/sink.
~AudioTransferBuffer()
Destructor that deallocates the transfer buffer.
uint8_t * get_buffer_end() const
Returns a pointer to the end of the transfer buffer where free() bytes of new data can be written.
void increase_buffer_length(size_t bytes)
Updates the internal state of the transfer buffer.
bool reallocate(size_t new_buffer_size)
Reallocates the transfer buffer, preserving any existing data.
bool allocate_buffer_(size_t buffer_size)
Allocates the transfer buffer in external memory, if available.
void decrease_buffer_length(size_t bytes)
Updates the internal state of the transfer buffer.
size_t available() const
Returns the transfer buffer's currently available bytes to read.
std::shared_ptr< RingBuffer > ring_buffer_
void deallocate_buffer_()
Deallocates the buffer and resets the class variables.
void set_data(const uint8_t *data, size_t length)
Sets the data pointer and length for the buffer.
const uint8_t * data_start_
const uint8_t * data() const override
void consume(size_t bytes) override
virtual size_t play(const uint8_t *data, size_t length)=0
Plays the provided audio data.
virtual bool has_buffered_data() const =0
Providing packet encoding functions for exchanging data with a remote host.