Buffer Regulators
Different tasks often require AudioBuffers
with specified parameters to function. For example, if you want to stream audio data across a network channel it's better to collect and send bigger chunks of audio data together. Small and frequent messages can cause unwanted heavy network load.
Buffer Size Regulator
BufferSizeRegulator
takes a variable sized input buffer and provides your callback function with a fixed amount of samples. This regulator works with mono audio.
- targetNumberOfFrames: the desired amount of frames
- userPointer: to pass custom data along the audio stream
- callback: callbackFunction which provides the regulated AudioBuffer and the userPointer for your process
- C++
void BufferSizeRegulatorCallback(float* buffer, void* userPointer) {
// Your code comes here
};
BufferSizeRegulator sizeRegulator(24000, SizeRegulatorCallback, userPointer);
sizeRegulator.process(inputBuffer, inputBuffer.numberOfSamples())
Buffer Duration Regulator
This BufferDurationRegulator
class can be used to turn a variable sized audio buffer stream into a stabilized constant length audio buffer stream. This regulator manages your audio properties and adapts to changes so your callback function always gets the desired amount of audio duration.
To initialize a BufferDurationRegulator
you have to set the desired duration with outputBufferMs
and your process function with audioCallback
.
In this case the process
function takes the following arguments:
- buffer: I/O buffer
- inputChannels: number of channels
- numberOfFrames: number of input frames
- sampleRate: sample rate of the input stream
- userPointer: custom data pointer
- C++
void BufferDurationRegulatorCallback(
float** buffers,
const uint inputChannels,
const uint numberOfFrames,
const uint sampleRate,
void* userPointer
) {
// Your code comes here
};
BufferDurationRegulator durationRegulator(10, DurationRegulatorCallback)
durationRegulator.process(buffer, inputChannels, numberOfFrames, sampleRate, userPointer);
Sample Rate Regulator
SampleRateRegulator
converts an audio stream with variable sample rate to a fixed sample rate buffer stream. This regulator works with mono audio.
- targetSampleRate: sample rate of the regulated stream
- userPointer: to pass custom data along the audio stream
- callback: callbackFunction which provides the regulated AudioBuffer and the userPointer along the number of samples of the provided stream
- C++
void SampleRateRegulatorCallback(float* buffer, uint numberOfSamples, void* userPointer) {
// Your code comes here
};
SampleRateRegulator sampleRateRegulator(48000, SampleRateRegulatorCallback, userPointer);
sampleRateRegulator.process(inputBuffer, inputBuffer.getNumberOfFrames(), inputBuffer.getSampleRate())