Audacity 3.2.0
|
Holds streamed audio samples. More...
#include <RingBuffer.h>
Public Member Functions | |
RingBuffer (sampleFormat format, size_t size) | |
~RingBuffer () | |
size_t | AvailForPut () const |
size_t | WrittenForGet () const |
Reader may concurrently cause a decrease of what this returns. More... | |
size_t | Put (constSamplePtr buffer, sampleFormat format, size_t samples, size_t padding=0) |
Does not apply dithering. More... | |
size_t | Unput (size_t size) |
Remove an initial segment of data that has been Put but not Flushed yet. More... | |
size_t | Clear (sampleFormat format, size_t samples) |
std::pair< samplePtr, size_t > | GetUnflushed (unsigned iBlock) |
void | Flush () |
Flush after a sequence of Put (and/or Clear) calls to let consumer see. More... | |
size_t | AvailForGet () const |
size_t | Get (samplePtr buffer, sampleFormat format, size_t samples) |
Does not apply dithering. More... | |
size_t | Discard (size_t samples) |
Private Member Functions | |
size_t | Filled (size_t start, size_t end) const |
size_t | Free (size_t start, size_t end) const |
Private Attributes | |
size_t | mWritten {0} |
size_t | mLastPadding {0} |
NonInterfering< std::atomic< size_t > > | mStart { 0 } |
NonInterfering< std::atomic< size_t > > | mEnd { 0 } |
const size_t | mBufferSize |
const sampleFormat | mFormat |
const SampleBuffer | mBuffer |
Holds streamed audio samples.
Assuming that there is only one thread writing, and one thread reading, this class implements a lock-free thread-safe bounded queue of samples with atomic variables that contain the first filled and free positions.
If two threads both need to read, or both need to write, they need to lock this class from outside using their own mutex.
AvailForPut and AvailForGet may underestimate but will never overestimate.
Definition at line 17 of file RingBuffer.h.
RingBuffer::RingBuffer | ( | sampleFormat | format, |
size_t | size | ||
) |
Definition at line 32 of file RingBuffer.cpp.
RingBuffer::~RingBuffer | ( | ) |
Definition at line 39 of file RingBuffer.cpp.
size_t RingBuffer::AvailForGet | ( | ) | const |
Definition at line 226 of file RingBuffer.cpp.
References details::end(), Filled(), mEnd, and mStart.
Referenced by AudioIO::GetCommonlyAvailCapture(), and AudioIoCallback::GetCommonlyReadyPlayback().
size_t RingBuffer::AvailForPut | ( | ) | const |
Definition at line 64 of file RingBuffer.cpp.
References Free(), mStart, and mWritten.
Referenced by AudioIO::GetCommonlyFreePlayback().
size_t RingBuffer::Clear | ( | sampleFormat | format, |
size_t | samples | ||
) |
Definition at line 164 of file RingBuffer.cpp.
References ClearSamples(), details::end(), anonymous_namespace{ExportPCM.cpp}::format, Free(), mBuffer, mBufferSize, min(), mStart, mWritten, and SampleBuffer::ptr().
size_t RingBuffer::Discard | ( | size_t | samples | ) |
Definition at line 267 of file RingBuffer.cpp.
References details::end(), Filled(), mBufferSize, mEnd, min(), and mStart.
|
private |
Definition at line 46 of file RingBuffer.cpp.
References details::end(), and mBufferSize.
Referenced by AvailForGet(), Discard(), Free(), Get(), GetUnflushed(), Unput(), and WrittenForGet().
void RingBuffer::Flush | ( | ) |
Flush after a sequence of Put (and/or Clear) calls to let consumer see.
Definition at line 210 of file RingBuffer.cpp.
References mEnd, mLastPadding, and mWritten.
|
private |
Definition at line 51 of file RingBuffer.cpp.
References details::end(), Filled(), and mBufferSize.
Referenced by AvailForPut(), Clear(), and Put().
size_t RingBuffer::Get | ( | samplePtr | buffer, |
sampleFormat | format, | ||
size_t | samples | ||
) |
Does not apply dithering.
Definition at line 236 of file RingBuffer.cpp.
References CopySamples(), details::end(), Filled(), anonymous_namespace{ExportPCM.cpp}::format, mBuffer, mBufferSize, mEnd, mFormat, min(), mStart, none, SampleBuffer::ptr(), and SAMPLE_SIZE.
std::pair< samplePtr, size_t > RingBuffer::GetUnflushed | ( | unsigned | iBlock | ) |
Get access to written but unflushed data, which is in at most two blocks Excludes the padding of the most recent Put()
Definition at line 187 of file RingBuffer.cpp.
References details::end(), Filled(), mBuffer, mBufferSize, mEnd, mFormat, min(), mLastPadding, mWritten, SampleBuffer::ptr(), SAMPLE_SIZE, and size.
size_t RingBuffer::Put | ( | constSamplePtr | buffer, |
sampleFormat | format, | ||
size_t | samples, | ||
size_t | padding = 0 |
||
) |
Does not apply dithering.
Definition at line 79 of file RingBuffer.cpp.
References ClearSamples(), CopySamples(), details::end(), anonymous_namespace{ExportPCM.cpp}::format, Free(), staffpad::vo::free(), mBuffer, mBufferSize, mFormat, min(), mLastPadding, mStart, mWritten, none, SampleBuffer::ptr(), and SAMPLE_SIZE.
size_t RingBuffer::Unput | ( | size_t | size | ) |
Remove an initial segment of data that has been Put but not Flushed yet.
Definition at line 117 of file RingBuffer.cpp.
References details::end(), Filled(), mBuffer, mBufferSize, mEnd, mFormat, min(), mLastPadding, mWritten, SampleBuffer::ptr(), SAMPLE_SIZE, and size.
size_t RingBuffer::WrittenForGet | ( | ) | const |
Reader may concurrently cause a decrease of what this returns.
Definition at line 73 of file RingBuffer.cpp.
References Filled(), mStart, and mWritten.
Referenced by AudioIoCallback::GetCommonlyWrittenForPlayback().
|
private |
Definition at line 67 of file RingBuffer.h.
Referenced by Clear(), Get(), GetUnflushed(), Put(), and Unput().
|
private |
Definition at line 64 of file RingBuffer.h.
Referenced by Clear(), Discard(), Filled(), Free(), Get(), GetUnflushed(), Put(), and Unput().
|
private |
Definition at line 62 of file RingBuffer.h.
Referenced by AvailForGet(), Discard(), Flush(), Get(), GetUnflushed(), and Unput().
|
private |
Definition at line 66 of file RingBuffer.h.
Referenced by Get(), GetUnflushed(), Put(), and Unput().
|
private |
Definition at line 59 of file RingBuffer.h.
Referenced by Flush(), GetUnflushed(), Put(), and Unput().
|
private |
Definition at line 62 of file RingBuffer.h.
Referenced by AvailForGet(), AvailForPut(), Clear(), Discard(), Get(), Put(), and WrittenForGet().
|
private |
Definition at line 58 of file RingBuffer.h.
Referenced by AvailForPut(), Clear(), Flush(), GetUnflushed(), Put(), Unput(), and WrittenForGet().