OpenShot Audio Library | OpenShotAudio 0.3.2
|
#include <juce_AbstractFifo.h>
Classes | |
class | ScopedReadWrite |
Public Types | |
using | ScopedRead = ScopedReadWrite< ReadOrWrite::read > |
using | ScopedWrite = ScopedReadWrite< ReadOrWrite::write > |
Public Member Functions | |
AbstractFifo (int capacity) noexcept | |
~AbstractFifo () | |
int | getTotalSize () const noexcept |
int | getFreeSpace () const noexcept |
int | getNumReady () const noexcept |
void | reset () noexcept |
void | setTotalSize (int newSize) noexcept |
void | prepareToWrite (int numToWrite, int &startIndex1, int &blockSize1, int &startIndex2, int &blockSize2) const noexcept |
void | finishedWrite (int numWritten) noexcept |
void | prepareToRead (int numWanted, int &startIndex1, int &blockSize1, int &startIndex2, int &blockSize2) const noexcept |
void | finishedRead (int numRead) noexcept |
ScopedRead | read (int numToRead) noexcept |
ScopedWrite | write (int numToWrite) noexcept |
Encapsulates the logic required to implement a lock-free FIFO.
This class handles the logic needed when building a single-reader, single-writer FIFO.
It doesn't actually hold any data itself, but your FIFO class can use one of these to manage its position and status when reading or writing to it.
To use it, you can call prepareToWrite() to determine the position within your own buffer that an incoming block of data should be stored, and prepareToRead() to find out when the next outgoing block should be read from.
e.g.
Definition at line 78 of file juce_AbstractFifo.h.
using juce::AbstractFifo::ScopedRead = ScopedReadWrite<ReadOrWrite::read> |
Definition at line 262 of file juce_AbstractFifo.h.
using juce::AbstractFifo::ScopedWrite = ScopedReadWrite<ReadOrWrite::write> |
Definition at line 263 of file juce_AbstractFifo.h.
|
noexcept |
Creates a FIFO to manage a buffer with the specified capacity.
Definition at line 26 of file juce_AbstractFifo.cpp.
juce::AbstractFifo::~AbstractFifo | ( | ) |
Destructor
Definition at line 31 of file juce_AbstractFifo.cpp.
Called after reading from the FIFO, to indicate that this many items have now been consumed.
Definition at line 121 of file juce_AbstractFifo.cpp.
Referenced by juce::dsp::Convolution::Pimpl::readFromFifo().
Called after writing from the FIFO, to indicate that this many items have been added.
Definition at line 83 of file juce_AbstractFifo.cpp.
Referenced by juce::dsp::Convolution::Pimpl::addToFifo(), and juce::dsp::Convolution::Pimpl::addToFifo().
|
noexcept |
Returns the number of items that can currently be added to the buffer without it overflowing.
Definition at line 34 of file juce_AbstractFifo.cpp.
|
noexcept |
Returns the number of items that can currently be read from the buffer.
Definition at line 36 of file juce_AbstractFifo.cpp.
Referenced by getFreeSpace(), and juce::dsp::Convolution::Pimpl::getNumRemainingEntries().
|
noexcept |
Returns the total size of the buffer being managed.
Definition at line 33 of file juce_AbstractFifo.cpp.
|
noexcept |
Returns the location within the buffer from which the next block of data should be read.
Because the section of data that you want to read from the buffer may overlap the end and wrap around to the start, two blocks within your buffer are returned, and you should read from both of them.
If the number of items you ask for is greater than the amount of data available, then blockSize1 + blockSize2 may add up to a lower value than numWanted. If this happens, you may decide to keep waiting and re-trying the method until there's enough data available.
After calling this method, if you choose to read the data, you must call finishedRead() to tell the FIFO how much data you have consumed.
e.g.
numWanted | indicates how many items you'd like to add to the buffer |
startIndex1 | on exit, this will contain the start index in your buffer at which your data should be written |
blockSize1 | on exit, this indicates how many items can be written to the block starting at startIndex1 |
startIndex2 | on exit, this will contain the start index in your buffer at which any data that didn't fit into the first block should be written |
blockSize2 | on exit, this indicates how many items can be written to the block starting at startIndex2 |
Definition at line 95 of file juce_AbstractFifo.cpp.
Referenced by juce::dsp::Convolution::Pimpl::readFromFifo().
|
noexcept |
Returns the location within the buffer at which an incoming block of data should be written.
Because the section of data that you want to add to the buffer may overlap the end and wrap around to the start, two blocks within your buffer are returned, and you should copy your data into the first one, with any remaining data spilling over into the second.
If the number of items you ask for is too large to fit within the buffer's free space, then blockSize1 + blockSize2 may add up to a lower value than numToWrite. If this happens, you may decide to keep waiting and re-trying the method until there's enough space available.
After calling this method, if you choose to write your data into the blocks returned, you must call finishedWrite() to tell the FIFO how much data you actually added.
e.g.
numToWrite | indicates how many items you'd like to add to the buffer |
startIndex1 | on exit, this will contain the start index in your buffer at which your data should be written |
blockSize1 | on exit, this indicates how many items can be written to the block starting at startIndex1 |
startIndex2 | on exit, this will contain the start index in your buffer at which any data that didn't fit into the first block should be written |
blockSize2 | on exit, this indicates how many items can be written to the block starting at startIndex2 |
Definition at line 57 of file juce_AbstractFifo.cpp.
Referenced by juce::dsp::Convolution::Pimpl::addToFifo(), and juce::dsp::Convolution::Pimpl::addToFifo().
|
noexcept |
Replaces prepareToRead/finishedRead with a single function. This function returns an object which contains the start indices and block sizes, and also automatically finishes the read operation when it goes out of scope.
Definition at line 165 of file juce_AbstractFifo.cpp.
|
noexcept |
Clears the buffer positions, so that it appears empty.
Definition at line 43 of file juce_AbstractFifo.cpp.
Changes the buffer's total size. Note that this isn't thread-safe, so don't call it if there's any danger that it might overlap with a call to any other method in this class!
Definition at line 49 of file juce_AbstractFifo.cpp.
|
noexcept |
Replaces prepareToWrite/finishedWrite with a single function. This function returns an object which contains the start indices and block sizes, and also automatically finishes the write operation when it goes out of scope.
Definition at line 166 of file juce_AbstractFifo.cpp.