|
Gin
|
Lock-free audio FIFO buffer for single producer/consumer scenarios. More...
#include <gin_audiofifo.h>
Public Member Functions | |
| AudioFifo (int channels=2, int numSamples=128) | |
| Creates an AudioFifo with the specified number of channels and sample capacity. | |
| void | setSize (int numChannels, int numSamples) |
| Resizes the FIFO to a new capacity. | |
| int | getNumChannels () const noexcept |
| Returns the number of audio channels. | |
| int | getFreeSpace () const noexcept |
| Returns the number of samples that can be written before the FIFO is full. | |
| int | getNumReady () const noexcept |
| Returns the number of samples available to read. | |
| void | reset () noexcept |
| Resets the FIFO to an empty state. | |
| void | ensureFreeSpace (int numSamples) |
| Ensures at least the specified amount of free space by discarding oldest data if needed. | |
| bool | write (const juce::AudioSampleBuffer &src, int numSamples=-1) |
| Writes audio data from an AudioSampleBuffer to the FIFO. | |
| bool | write (const float *const *data, int numSamples) |
| Writes audio data from a multi-channel array to the FIFO. | |
| bool | writeSilence (int numSamples) |
| Writes silence (zeros) to the FIFO. | |
| bool | writeMono (const float *data, int numSamples) |
| Writes mono audio data to a single-channel FIFO. | |
| bool | peek (juce::AudioSampleBuffer &dest) |
| Peeks at (reads without consuming) audio data from the FIFO. | |
| bool | peek (juce::AudioSampleBuffer &dest, int startSampleInDestBuffer, int numSamples) |
| Peeks at (reads without consuming) audio data from the FIFO. | |
| float | peekSample (int channel, int sample) |
| Peeks at a single sample without consuming it. | |
| bool | read (juce::AudioSampleBuffer &dest) |
| Reads and removes audio data from the FIFO. | |
| bool | read (juce::AudioSampleBuffer &dest, int startSampleInDestBuffer, int numSamples) |
| Reads and removes audio data from the FIFO. | |
| bool | readMono (float *data, int numSamples) |
| Reads and removes mono audio data from a single-channel FIFO. | |
| bool | readAdding (juce::AudioSampleBuffer &dest) |
| Reads and removes audio data from the FIFO, adding it to the destination buffer. | |
| bool | readAdding (juce::AudioSampleBuffer &dest, int startSampleInDestBuffer, int numSamples) |
| Reads and removes audio data from the FIFO, adding it to the destination buffer. | |
| bool | pop (int numSamples) |
| Removes (discards) samples from the FIFO without reading them. | |
Lock-free audio FIFO buffer for single producer/consumer scenarios.
AudioFifo provides a thread-safe circular buffer for passing audio between threads, typically from an audio callback to a background processing thread or vice versa. It uses JUCE's AbstractFifo for lock-free operation with a single producer and single consumer thread.
Key Features:
Common Use Cases:
Thread Safety:
Usage:
Creates an AudioFifo with the specified number of channels and sample capacity.
| channels | Number of audio channels (default: 2) |
| numSamples | Maximum number of samples the FIFO can hold (default: 128) |
Resizes the FIFO to a new capacity.
Note: This is not thread-safe and should only be called when no other threads are accessing the FIFO.
| numChannels | New number of audio channels |
| numSamples | New maximum number of samples |
Referenced by PluginWrapper::PluginWrapper(), and PluginWrapper::processBlock().
|
noexcept |
Returns the number of audio channels.
Referenced by PluginWrapper::processBlock().
|
noexcept |
Returns the number of samples that can be written before the FIFO is full.
Referenced by ensureFreeSpace(), PluginWrapper::processBlock(), write(), writeMono(), and writeSilence().
|
noexcept |
Returns the number of samples available to read.
Referenced by ensureFreeSpace(), peek(), peekSample(), pop(), read(), readAdding(), readMono(), and ResamplingFifo::samplesReady().
|
noexcept |
Resets the FIFO to an empty state.
Note: This is not thread-safe and should only be called when no other threads are accessing the FIFO.
Ensures at least the specified amount of free space by discarding oldest data if needed.
If the requested free space is greater than currently available, this will discard the oldest samples to make room.
| numSamples | The minimum number of free samples required |
References getFreeSpace(), and getNumReady().
Writes audio data from an AudioSampleBuffer to the FIFO.
Should only be called from the producer thread.
| src | The source buffer to write from |
| numSamples | Number of samples to write (default: -1 writes all samples from src) |
References write().
Referenced by PluginWrapper::processBlock(), and write().
Writes audio data from a multi-channel array to the FIFO.
Should only be called from the producer thread.
| data | Array of channel pointers containing the audio data |
| numSamples | Number of samples to write |
References getFreeSpace().
Writes silence (zeros) to the FIFO.
Should only be called from the producer thread.
| numSamples | Number of silent samples to write |
References getFreeSpace().
Writes mono audio data to a single-channel FIFO.
Should only be called from the producer thread. The FIFO must be configured for single-channel (mono) operation.
| data | Pointer to the mono audio data |
| numSamples | Number of samples to write |
References getFreeSpace().
| bool AudioFifo::peek | ( | juce::AudioSampleBuffer & | dest | ) |
Peeks at (reads without consuming) audio data from the FIFO.
The data remains in the FIFO and can be read again. Should only be called from the consumer thread.
| dest | Destination buffer to copy the audio data into |
References peek().
Referenced by peek().
| bool AudioFifo::peek | ( | juce::AudioSampleBuffer & | dest, |
| int | startSampleInDestBuffer, | ||
| int | numSamples | ||
| ) |
Peeks at (reads without consuming) audio data from the FIFO.
The data remains in the FIFO and can be read again. Should only be called from the consumer thread.
| dest | Destination buffer to copy the audio data into |
| startSampleInDestBuffer | Starting position in the destination buffer |
| numSamples | Number of samples to peek |
References getNumReady().
Peeks at a single sample without consuming it.
Should only be called from the consumer thread.
| channel | The channel to peek from |
| sample | The sample index to peek (0 = first available sample) |
References getNumReady().
| bool AudioFifo::read | ( | juce::AudioSampleBuffer & | dest | ) |
| bool AudioFifo::read | ( | juce::AudioSampleBuffer & | dest, |
| int | startSampleInDestBuffer, | ||
| int | numSamples | ||
| ) |
Reads and removes audio data from the FIFO.
Should only be called from the consumer thread.
| dest | Destination buffer to copy the audio data into |
| startSampleInDestBuffer | Starting position in the destination buffer |
| numSamples | Number of samples to read |
References getNumReady().
Reads and removes mono audio data from a single-channel FIFO.
Should only be called from the consumer thread. The FIFO must be configured for single-channel (mono) operation.
| data | Pointer to the destination array for the audio data |
| numSamples | Number of samples to read |
References getNumReady().
| bool AudioFifo::readAdding | ( | juce::AudioSampleBuffer & | dest | ) |
Reads and removes audio data from the FIFO, adding it to the destination buffer.
Unlike read(), this adds the FIFO data to the destination rather than replacing it. Should only be called from the consumer thread.
| dest | Destination buffer to add the audio data to |
References readAdding().
Referenced by readAdding().
| bool AudioFifo::readAdding | ( | juce::AudioSampleBuffer & | dest, |
| int | startSampleInDestBuffer, | ||
| int | numSamples | ||
| ) |
Reads and removes audio data from the FIFO, adding it to the destination buffer.
Unlike read(), this adds the FIFO data to the destination rather than replacing it. Should only be called from the consumer thread.
| dest | Destination buffer to add the audio data to |
| startSampleInDestBuffer | Starting position in the destination buffer |
| numSamples | Number of samples to read |
References getNumReady().
Removes (discards) samples from the FIFO without reading them.
This is useful after peek() operations when you want to consume the peeked data. Should only be called from the consumer thread.
| numSamples | Number of samples to discard |
References getNumReady().