Gin
Loading...
Searching...
No Matches
AudioMidiFifo Class Reference

Combined audio and MIDI buffer for synchronized processing within a single thread. More...

#include <gin_audiomidififo.h>

Public Member Functions

 AudioMidiFifo (int channels=2, int maxSize=1024)
 Creates an AudioMidiFifo with the specified capacity.
void setSize (int channels, int maxSize)
 Resizes the FIFO to a new capacity.
void clear ()
 Clears all audio and MIDI data from the FIFO, resetting it to an empty state.
int getNumSamplesAvailable ()
 Returns the number of audio samples available to read.
int getNumSamplesFree ()
 Returns the number of audio samples that can be written before the FIFO is full.
void writeSilence (int numSamples)
 Writes silence (zeros) to the audio portion of the FIFO.
void write (const juce::AudioBuffer< float > &audioSrc, const juce::MidiBuffer &midiSrc)
 Writes audio and MIDI data to the FIFO.
void read (juce::AudioBuffer< float > &audioDst, juce::MidiBuffer &midiDst)
 Reads audio and MIDI data from the FIFO.

Detailed Description

Combined audio and MIDI buffer for synchronized processing within a single thread.

AudioMidiFifo provides a circular buffer that handles both audio samples and MIDI messages together, maintaining their temporal relationship. This is NOT thread-safe and should only be used within a single thread for operations that need synchronized audio and MIDI buffering.

Key Features:

  • Synchronized audio and MIDI storage
  • Automatic time offset management for MIDI events
  • Multi-channel audio support
  • Silence writing capability
  • Uses AbstractFifo for audio portion

Thread Safety:

  • NOT thread-safe
  • Use only within a single thread
  • For multi-threaded use, consider separate synchronization

The MIDI timestamps are automatically adjusted to maintain correct timing relative to the audio samples when reading and writing.

Usage:

AudioMidiFifo fifo(2, 8192); // 2 channels, 8192 samples max
// Write audio and MIDI together (single thread)
AudioBuffer<float> audioIn(2, 512);
MidiBuffer midiIn;
// ... fill buffers ...
fifo.write(audioIn, midiIn);
// Read audio and MIDI together (same thread)
if (fifo.getNumSamplesAvailable() >= 512)
{
AudioBuffer<float> audioOut(2, 512);
MidiBuffer midiOut;
fifo.read(audioOut, midiOut);
// ... process synchronized audio and MIDI
}
AudioMidiFifo(int channels=2, int maxSize=1024)
Creates an AudioMidiFifo with the specified capacity.
Definition gin_audiomidififo.h:70
See also
AudioFifo, MidiFifo

Constructor & Destructor Documentation

◆ AudioMidiFifo()

AudioMidiFifo::AudioMidiFifo ( int channels = 2,
int maxSize = 1024 )

Creates an AudioMidiFifo with the specified capacity.

Parameters
channelsNumber of audio channels (default: 2)
maxSizeMaximum number of audio samples the FIFO can hold (default: 1024)

References setSize().

Member Function Documentation

◆ setSize()

void AudioMidiFifo::setSize ( int channels,
int maxSize )

Resizes the FIFO to a new capacity.

This clears any existing data in the FIFO.

Parameters
channelsNew number of audio channels
maxSizeNew maximum number of audio samples

References clear().

Referenced by AudioMidiFifo().

◆ clear()

void AudioMidiFifo::clear ( )

Clears all audio and MIDI data from the FIFO, resetting it to an empty state.

Referenced by setSize().

◆ getNumSamplesAvailable()

int AudioMidiFifo::getNumSamplesAvailable ( )

Returns the number of audio samples available to read.

Returns
The number of samples that can be read from the FIFO

Referenced by read().

◆ getNumSamplesFree()

int AudioMidiFifo::getNumSamplesFree ( )

Returns the number of audio samples that can be written before the FIFO is full.

Returns
The number of free sample slots

Referenced by write(), and writeSilence().

◆ writeSilence()

void AudioMidiFifo::writeSilence ( int numSamples)

Writes silence (zeros) to the audio portion of the FIFO.

No MIDI events are added.

Parameters
numSamplesNumber of silent samples to write

References getNumSamplesFree().

◆ write()

void AudioMidiFifo::write ( const juce::AudioBuffer< float > & audioSrc,
const juce::MidiBuffer & midiSrc )

Writes audio and MIDI data to the FIFO.

MIDI event timestamps are automatically adjusted to maintain correct timing within the FIFO's internal timeline.

Parameters
audioSrcSource audio buffer to write
midiSrcSource MIDI buffer to write (timestamps relative to audioSrc)

References getNumSamplesFree().

◆ read()

void AudioMidiFifo::read ( juce::AudioBuffer< float > & audioDst,
juce::MidiBuffer & midiDst )

Reads audio and MIDI data from the FIFO.

MIDI event timestamps are automatically adjusted to be relative to the start of the destination audio buffer.

Parameters
audioDstDestination audio buffer to read into
midiDstDestination MIDI buffer to read into (timestamps will be relative to audioDst)

References getNumSamplesAvailable().


The documentation for this class was generated from the following file: