Browse Source

Fix RingBuffer::getReadableDataSize, add a few methods

Signed-off-by: falkTX <falktx@falktx.com>
pull/432/head
falkTX 1 year ago
parent
commit
c11f93d5b0
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 24 additions and 2 deletions
  1. +24
    -2
      distrho/extra/RingBuffer.hpp

+ 24
- 2
distrho/extra/RingBuffer.hpp View File

@@ -200,6 +200,14 @@ public:
return (buffer->buf == nullptr || buffer->head == buffer->tail);
}

/*
* Get the full ringbuffer size.
*/
uint32_t getSize() const noexcept
{
return buffer != nullptr ? buffer->size : 0;
}

/*
* Get the size of the data available to read.
*/
@@ -207,7 +215,7 @@ public:
{
DISTRHO_SAFE_ASSERT_RETURN(buffer != nullptr, 0);

const uint32_t wrap = buffer->head > buffer->tail ? 0 : buffer->size;
const uint32_t wrap = buffer->head >= buffer->tail ? 0 : buffer->size;

return wrap + buffer->head - buffer->tail;
}
@@ -219,7 +227,7 @@ public:
{
DISTRHO_SAFE_ASSERT_RETURN(buffer != nullptr, 0);

const uint32_t wrap = (buffer->tail > buffer->wrtn) ? 0 : buffer->size;
const uint32_t wrap = buffer->tail > buffer->wrtn ? 0 : buffer->size;

return wrap + buffer->tail - buffer->wrtn;
}
@@ -243,6 +251,20 @@ public:
std::memset(buffer->buf, 0, buffer->size);
}

/*
* Reset the ring buffer read and write positions, marking the buffer as empty.
* Requires a buffer struct tied to this class.
*/
void flush() noexcept
{
DISTRHO_SAFE_ASSERT_RETURN(buffer != nullptr,);

buffer->head = buffer->tail = buffer->wrtn = 0;
buffer->invalidateCommit = false;

errorWriting = false;
}

// -------------------------------------------------------------------
// read operations



Loading…
Cancel
Save