13 std::unique_ptr<AudioSinkTransferBuffer> sink_buffer = make_unique<AudioSinkTransferBuffer>();
15 if (!sink_buffer->allocate_buffer_(buffer_size)) {
23 std::unique_ptr<AudioSourceTransferBuffer> source_buffer = make_unique<AudioSourceTransferBuffer>();
25 if (!source_buffer->allocate_buffer_(buffer_size)) {
59 if (this->speaker_ !=
nullptr) {
60 this->speaker_->stop();
116 size_t bytes_to_read = this->
free();
117 size_t bytes_read = 0;
118 if (bytes_to_read > 0) {
129 size_t bytes_written = 0;
132 if (this->speaker_ !=
nullptr) {
147 return bytes_written;
152 if (this->speaker_ !=
nullptr) {
153 return (this->speaker_->has_buffered_data() || (this->
available() > 0));
void clear_buffered_data() override
void deallocate_buffer_()
Deallocates the buffer and resets the class variables.
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...
static std::unique_ptr< AudioSinkTransferBuffer > create(size_t buffer_size)
Creates a new sink transfer buffer.
virtual bool has_buffered_data() const
Tests if there is any data in the tranfer buffer or the source/sink.
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 transfer_data_to_sink(TickType_t ticks_to_wait)
Writes any available data in the transfer buffer to the sink.
size_t available() const
Returns the transfer buffer's currently available bytes to read.
bool has_buffered_data() const override
static std::unique_ptr< AudioSourceTransferBuffer > create(size_t buffer_size)
Creates a new source transfer buffer.
size_t free() const
Returns the transfer buffer's currrently free bytes available to write.
bool reallocate(size_t new_buffer_size)
void deallocate(T *p, size_t n)
void increase_buffer_length(size_t bytes)
Updates the internal state of the transfer buffer.
~AudioTransferBuffer()
Destructor that deallocates the transfer buffer.
Implementation of SPI Controller mode.
std::vector< uint8_t > bytes
size_t transfer_data_from_source(TickType_t ticks_to_wait)
Reads any available data from the sink into the transfer buffer.
virtual void clear_buffered_data()
Clears data in the transfer buffer and, if possible, the source/sink.
std::shared_ptr< RingBuffer > ring_buffer_