A multi-channel buffer of floating point audio samples. More...
#include <juce_AudioSampleBuffer.h>
Public Member Functions | |
AudioBuffer () noexcept | |
Creates an empty buffer with 0 channels and 0 length. More... | |
AudioBuffer (int numChannelsToAllocate, int numSamplesToAllocate) | |
Creates a buffer with a specified number of channels and samples. More... | |
AudioBuffer (Type *const *dataToReferTo, int numChannelsToUse, int numSamples) | |
Creates a buffer using a pre-allocated block of memory. More... | |
AudioBuffer (Type *const *dataToReferTo, int numChannelsToUse, int startSample, int numSamples) | |
Creates a buffer using a pre-allocated block of memory. More... | |
AudioBuffer (const AudioBuffer &other) | |
Copies another buffer. More... | |
AudioBuffer (AudioBuffer &&other) noexcept | |
Move constructor. More... | |
~AudioBuffer () noexcept | |
Destructor. More... | |
void | addFrom (int destChannel, int destStartSample, const AudioBuffer &source, int sourceChannel, int sourceStartSample, int numSamples, Type gainToApplyToSource=(Type) 1) noexcept |
Adds samples from another buffer to this one. More... | |
void | addFrom (int destChannel, int destStartSample, const Type *source, int numSamples, Type gainToApplyToSource=(Type) 1) noexcept |
Adds samples from an array of floats to one of the channels. More... | |
void | addFromWithRamp (int destChannel, int destStartSample, const Type *source, int numSamples, Type startGain, Type endGain) noexcept |
Adds samples from an array of floats, applying a gain ramp to them. More... | |
void | addSample (int destChannel, int destSample, Type valueToAdd) noexcept |
Adds a value to a sample in the buffer. More... | |
void | applyGain (int channel, int startSample, int numSamples, Type gain) noexcept |
Applies a gain multiple to a region of one channel. More... | |
void | applyGain (int startSample, int numSamples, Type gain) noexcept |
Applies a gain multiple to a region of all the channels. More... | |
void | applyGain (Type gain) noexcept |
Applies a gain multiple to all the audio data. More... | |
void | applyGainRamp (int channel, int startSample, int numSamples, Type startGain, Type endGain) noexcept |
Applies a range of gains to a region of a channel. More... | |
void | applyGainRamp (int startSample, int numSamples, Type startGain, Type endGain) noexcept |
Applies a range of gains to a region of all channels. More... | |
void | clear () noexcept |
Clears all the samples in all channels. More... | |
void | clear (int startSample, int numSamples) noexcept |
Clears a specified region of all the channels. More... | |
void | clear (int channel, int startSample, int numSamples) noexcept |
Clears a specified region of just one channel. More... | |
void | copyFrom (int destChannel, int destStartSample, const AudioBuffer &source, int sourceChannel, int sourceStartSample, int numSamples) noexcept |
Copies samples from another buffer to this one. More... | |
void | copyFrom (int destChannel, int destStartSample, const Type *source, int numSamples) noexcept |
Copies samples from an array of floats into one of the channels. More... | |
void | copyFrom (int destChannel, int destStartSample, const Type *source, int numSamples, Type gain) noexcept |
Copies samples from an array of floats into one of the channels, applying a gain to it. More... | |
void | copyFromWithRamp (int destChannel, int destStartSample, const Type *source, int numSamples, Type startGain, Type endGain) noexcept |
Copies samples from an array of floats into one of the channels, applying a gain ramp. More... | |
Range< Type > | findMinMax (int channel, int startSample, int numSamples) const noexcept |
Returns a Range indicating the lowest and highest sample values in a given section. More... | |
const Type ** | getArrayOfReadPointers () const noexcept |
Returns an array of pointers to the channels in the buffer. More... | |
Type ** | getArrayOfWritePointers () noexcept |
Returns an array of pointers to the channels in the buffer. More... | |
Type | getMagnitude (int channel, int startSample, int numSamples) const noexcept |
Finds the highest absolute sample value within a region of a channel. More... | |
Type | getMagnitude (int startSample, int numSamples) const noexcept |
Finds the highest absolute sample value within a region on all channels. More... | |
int | getNumChannels () const noexcept |
Returns the number of channels of audio data that this buffer contains. More... | |
int | getNumSamples () const noexcept |
Returns the number of samples allocated in each of the buffer's channels. More... | |
const Type * | getReadPointer (int channelNumber) const noexcept |
Returns a pointer to an array of read-only samples in one of the buffer's channels. More... | |
const Type * | getReadPointer (int channelNumber, int sampleIndex) const noexcept |
Returns a pointer to an array of read-only samples in one of the buffer's channels. More... | |
Type | getRMSLevel (int channel, int startSample, int numSamples) const noexcept |
Returns the root mean squared level for a region of a channel. More... | |
Type | getSample (int channel, int sampleIndex) const noexcept |
Returns a sample from the buffer. More... | |
Type * | getWritePointer (int channelNumber) noexcept |
Returns a writeable pointer to one of the buffer's channels. More... | |
Type * | getWritePointer (int channelNumber, int sampleIndex) noexcept |
Returns a writeable pointer to one of the buffer's channels. More... | |
bool | hasBeenCleared () const noexcept |
Returns true if the buffer has been entirely cleared. More... | |
template<typename OtherType > | |
void | makeCopyOf (const AudioBuffer< OtherType > &other, bool avoidReallocating=false) |
Resizes this buffer to match the given one, and copies all of its content across. More... | |
AudioBuffer & | operator= (const AudioBuffer &other) |
Copies another buffer onto this one. More... | |
AudioBuffer & | operator= (AudioBuffer &&other) noexcept |
Move assignment. More... | |
void | reverse (int channel, int startSample, int numSamples) const noexcept |
Reverses a part of a channel. More... | |
void | reverse (int startSample, int numSamples) const noexcept |
Reverses a part of the buffer. More... | |
void | setDataToReferTo (Type **dataToReferTo, int newNumChannels, int newStartSample, int newNumSamples) |
Makes this buffer point to a pre-allocated set of channel data arrays. More... | |
void | setDataToReferTo (Type **dataToReferTo, int newNumChannels, int newNumSamples) |
Makes this buffer point to a pre-allocated set of channel data arrays. More... | |
void | setSample (int destChannel, int destSample, Type newValue) noexcept |
Sets a sample in the buffer. More... | |
void | setSize (int newNumChannels, int newNumSamples, bool keepExistingContent=false, bool clearExtraSpace=false, bool avoidReallocating=false) |
Changes the buffer's size or number of channels. More... | |
Private Member Functions | |
void | allocateChannels (Type *const *dataToReferTo, int offset) |
void | allocateData () |
Private Attributes | |
size_t | allocatedBytes |
HeapBlock< char, true > | allocatedData |
Type ** | channels |
bool | isClear |
int | numChannels |
Type * | preallocatedChannelSpace [32] |
int | size |
A multi-channel buffer of floating point audio samples.
|
inlinenoexcept |
Creates an empty buffer with 0 channels and 0 length.
|
inline |
Creates a buffer with a specified number of channels and samples.
The contents of the buffer will initially be undefined, so use clear() to set all the samples to zero.
The buffer will allocate its memory internally, and this will be released when the buffer is deleted. If the memory can't be allocated, this will throw a std::bad_alloc exception.
|
inline |
Creates a buffer using a pre-allocated block of memory.
Note that if the buffer is resized or its number of channels is changed, it will re-allocate memory internally and copy the existing data to this new area, so it will then stop directly addressing this memory.
dataToReferTo | a pre-allocated array containing pointers to the data for each channel that should be used by this buffer. The buffer will only refer to this memory, it won't try to delete it when the buffer is deleted or resized. |
numChannelsToUse | the number of channels to use - this must correspond to the number of elements in the array passed in |
numSamples | the number of samples to use - this must correspond to the size of the arrays passed in |
|
inline |
Creates a buffer using a pre-allocated block of memory.
Note that if the buffer is resized or its number of channels is changed, it will re-allocate memory internally and copy the existing data to this new area, so it will then stop directly addressing this memory.
dataToReferTo | a pre-allocated array containing pointers to the data for each channel that should be used by this buffer. The buffer will only refer to this memory, it won't try to delete it when the buffer is deleted or resized. |
numChannelsToUse | the number of channels to use - this must correspond to the number of elements in the array passed in |
startSample | the offset within the arrays at which the data begins |
numSamples | the number of samples to use - this must correspond to the size of the arrays passed in |
|
inline |
Copies another buffer.
This buffer will make its own copy of the other's data, unless the buffer was created using an external data buffer, in which case boths buffers will just point to the same shared block of data.
|
inlinenoexcept |
Destructor.
This will free any memory allocated by the buffer.
|
inlinenoexcept |
Move constructor.
|
inlinenoexcept |
Adds samples from another buffer to this one.
destChannel | the channel within this buffer to add the samples to |
destStartSample | the start sample within this buffer's channel |
source | the source buffer to add from |
sourceChannel | the channel within the source buffer to read from |
sourceStartSample | the offset within the source buffer's channel to start reading samples from |
numSamples | the number of samples to process |
gainToApplyToSource | an optional gain to apply to the source samples before they are added to this buffer's samples |
Referenced by AudioBuffer< double >::addFromWithRamp().
|
inlinenoexcept |
Adds samples from an array of floats to one of the channels.
destChannel | the channel within this buffer to add the samples to |
destStartSample | the start sample within this buffer's channel |
source | the source data to use |
numSamples | the number of samples to process |
gainToApplyToSource | an optional gain to apply to the source samples before they are added to this buffer's samples |
|
inlinenoexcept |
Adds samples from an array of floats, applying a gain ramp to them.
destChannel | the channel within this buffer to add the samples to |
destStartSample | the start sample within this buffer's channel |
source | the source data to use |
numSamples | the number of samples to process |
startGain | the gain to apply to the first sample (this is multiplied with the source samples before they are added to this buffer) |
endGain | the gain to apply to the final sample. The gain is linearly interpolated between the first and last samples. |
|
inlinenoexcept |
Adds a value to a sample in the buffer.
The channel and index are not checked - they are expected to be in-range. If not, an assertion will be thrown, but in a release build, you're into 'undefined behaviour' territory.
|
inlineprivate |
Referenced by AudioBuffer< double >::AudioBuffer(), and AudioBuffer< double >::setDataToReferTo().
|
inlineprivate |
Referenced by AudioBuffer< double >::AudioBuffer().
|
inlinenoexcept |
Applies a gain multiple to a region of one channel.
For speed, this doesn't check whether the channel and sample number are in-range, so be careful!
Referenced by AudioBuffer< double >::applyGain(), and AudioBuffer< double >::applyGainRamp().
|
inlinenoexcept |
Applies a gain multiple to a region of all the channels.
For speed, this doesn't check whether the sample numbers are in-range, so be careful!
|
inlinenoexcept |
Applies a gain multiple to all the audio data.
|
inlinenoexcept |
Applies a range of gains to a region of a channel.
The gain that is applied to each sample will vary from startGain on the first sample to endGain on the last Sample, so it can be used to do basic fades.
For speed, this doesn't check whether the sample numbers are in-range, so be careful!
Referenced by AudioBuffer< double >::applyGainRamp().
|
inlinenoexcept |
Applies a range of gains to a region of all channels.
The gain that is applied to each sample will vary from startGain on the first sample to endGain on the last Sample, so it can be used to do basic fades.
For speed, this doesn't check whether the sample numbers are in-range, so be careful!
|
inlinenoexcept |
Clears all the samples in all channels.
Referenced by AudioBuffer< double >::AudioBuffer(), StandalonePluginHolder::audioDeviceAboutToStart(), StandalonePluginHolder::audioDeviceIOCallback(), AudioSourceChannelInfo::clearActiveBufferRegion(), AudioBuffer< double >::makeCopyOf(), and AudioBuffer< double >::operator=().
|
inlinenoexcept |
Clears a specified region of all the channels.
For speed, this doesn't check whether the channel and sample number are in-range, so be careful!
|
inlinenoexcept |
Clears a specified region of just one channel.
For speed, this doesn't check whether the channel and sample number are in-range, so be careful!
|
inlinenoexcept |
Copies samples from another buffer to this one.
destChannel | the channel within this buffer to copy the samples to |
destStartSample | the start sample within this buffer's channel |
source | the source buffer to read from |
sourceChannel | the channel within the source buffer to read from |
sourceStartSample | the offset within the source buffer's channel to start reading samples from |
numSamples | the number of samples to process |
Referenced by AudioBuffer< double >::copyFromWithRamp().
|
inlinenoexcept |
Copies samples from an array of floats into one of the channels.
destChannel | the channel within this buffer to copy the samples to |
destStartSample | the start sample within this buffer's channel |
source | the source buffer to read from |
numSamples | the number of samples to process |
|
inlinenoexcept |
Copies samples from an array of floats into one of the channels, applying a gain to it.
destChannel | the channel within this buffer to copy the samples to |
destStartSample | the start sample within this buffer's channel |
source | the source buffer to read from |
numSamples | the number of samples to process |
gain | the gain to apply |
|
inlinenoexcept |
Copies samples from an array of floats into one of the channels, applying a gain ramp.
destChannel | the channel within this buffer to copy the samples to |
destStartSample | the start sample within this buffer's channel |
source | the source buffer to read from |
numSamples | the number of samples to process |
startGain | the gain to apply to the first sample (this is multiplied with the source samples before they are copied to this buffer) |
endGain | the gain to apply to the final sample. The gain is linearly interpolated between the first and last samples. |
|
inlinenoexcept |
Returns a Range indicating the lowest and highest sample values in a given section.
channel | the channel to read from |
startSample | the start sample within the channel |
numSamples | the number of samples to check |
Referenced by AudioBuffer< double >::getMagnitude().
|
inlinenoexcept |
Returns an array of pointers to the channels in the buffer.
Don't modify any of the pointers that are returned, and bear in mind that these will become invalid if the buffer is resized.
Referenced by StandalonePluginHolder::audioDeviceIOCallback().
|
inlinenoexcept |
Returns an array of pointers to the channels in the buffer.
Don't modify any of the pointers that are returned, and bear in mind that these will become invalid if the buffer is resized.
Referenced by AudioProcessor::getBusBuffer().
|
inlinenoexcept |
Finds the highest absolute sample value within a region of a channel.
Referenced by AudioBuffer< double >::getMagnitude().
|
inlinenoexcept |
Finds the highest absolute sample value within a region on all channels.
|
inlinenoexcept |
Returns the number of channels of audio data that this buffer contains.
Referenced by VST3BufferExchange< float >::associateBufferTo(), AudioBuffer< double >::makeCopyOf(), and AudioBuffer< double >::operator=().
|
inlinenoexcept |
Returns the number of samples allocated in each of the buffer's channels.
Referenced by AudioProcessor::getBusBuffer(), AudioBuffer< double >::makeCopyOf(), and AudioBuffer< double >::operator=().
|
inlinenoexcept |
Returns a pointer to an array of read-only samples in one of the buffer's channels.
For speed, this doesn't check whether the channel number is out of range, so be careful when using it! If you need to write to the data, do NOT call this method and const_cast the result! Instead, you must call getWritePointer so that the buffer knows you're planning on modifying the data.
Referenced by AudioBuffer< double >::makeCopyOf().
|
inlinenoexcept |
Returns a pointer to an array of read-only samples in one of the buffer's channels.
For speed, this doesn't check whether the channel number or index are out of range, so be careful when using it! If you need to write to the data, do NOT call this method and const_cast the result! Instead, you must call getWritePointer so that the buffer knows you're planning on modifying the data.
|
inlinenoexcept |
Returns the root mean squared level for a region of a channel.
|
inlinenoexcept |
Returns a sample from the buffer.
The channel and index are not checked - they are expected to be in-range. If not, an assertion will be thrown, but in a release build, you're into 'undefined behaviour' territory.
|
inlinenoexcept |
Returns a writeable pointer to one of the buffer's channels.
For speed, this doesn't check whether the channel number is out of range, so be careful when using it! Note that if you're not planning on writing to the data, you should always use getReadPointer instead.
Referenced by VST3BufferExchange< float >::associateBufferTo().
|
inlinenoexcept |
Returns a writeable pointer to one of the buffer's channels.
For speed, this doesn't check whether the channel number or index are out of range, so be careful when using it! Note that if you're not planning on writing to the data, you should use getReadPointer instead.
|
inlinenoexcept |
Returns true if the buffer has been entirely cleared.
Note that this does not actually measure the contents of the buffer - it simply returns a flag that is set when the buffer is cleared, and which is reset whenever functions like getWritePointer() are invoked. That means the method does not take any time, but it may return false negatives when in fact the buffer is still empty.
Referenced by AudioBuffer< double >::makeCopyOf().
|
inline |
Resizes this buffer to match the given one, and copies all of its content across.
The source buffer can contain a different floating point type, so this can be used to convert between 32 and 64 bit float buffer types.
|
inline |
Copies another buffer onto this one.
This buffer's size will be changed to that of the other buffer.
|
inlinenoexcept |
Move assignment.
|
inlinenoexcept |
Reverses a part of a channel.
Referenced by AudioBuffer< double >::reverse().
|
inlinenoexcept |
Reverses a part of the buffer.
|
inline |
Makes this buffer point to a pre-allocated set of channel data arrays.
There's also a constructor that lets you specify arrays like this, but this lets you change the channels dynamically.
Note that if the buffer is resized or its number of channels is changed, it will re-allocate memory internally and copy the existing data to this new area, so it will then stop directly addressing this memory.
dataToReferTo | a pre-allocated array containing pointers to the data for each channel that should be used by this buffer. The buffer will only refer to this memory, it won't try to delete it when the buffer is deleted or resized. |
newNumChannels | the number of channels to use - this must correspond to the number of elements in the array passed in |
newStartSample | the offset within the arrays at which the data begins |
newNumSamples | the number of samples to use - this must correspond to the size of the arrays passed in |
Referenced by AudioBuffer< double >::setDataToReferTo().
|
inline |
Makes this buffer point to a pre-allocated set of channel data arrays.
There's also a constructor that lets you specify arrays like this, but this lets you change the channels dynamically.
Note that if the buffer is resized or its number of channels is changed, it will re-allocate memory internally and copy the existing data to this new area, so it will then stop directly addressing this memory.
dataToReferTo | a pre-allocated array containing pointers to the data for each channel that should be used by this buffer. The buffer will only refer to this memory, it won't try to delete it when the buffer is deleted or resized. |
newNumChannels | the number of channels to use - this must correspond to the number of elements in the array passed in |
newNumSamples | the number of samples to use - this must correspond to the size of the arrays passed in |
|
inlinenoexcept |
Sets a sample in the buffer.
The channel and index are not checked - they are expected to be in-range. If not, an assertion will be thrown, but in a release build, you're into 'undefined behaviour' territory.
|
inline |
Changes the buffer's size or number of channels.
This can expand or contract the buffer's length, and add or remove channels.
If keepExistingContent is true, it will try to preserve as much of the old data as it can in the new buffer.
If clearExtraSpace is true, then any extra channels or space that is allocated will be also be cleared. If false, then this space is left uninitialised.
If avoidReallocating is true, then changing the buffer's size won't reduce the amount of memory that is currently allocated (but it will still increase it if the new size is bigger than the amount it currently has). If this is false, then a new allocation will be done so that the buffer uses takes up the minimum amount of memory that it needs.
If the required memory can't be allocated, this will throw a std::bad_alloc exception.
Referenced by StandalonePluginHolder::audioDeviceAboutToStart(), StandalonePluginHolder::audioDeviceStopped(), AudioBuffer< double >::makeCopyOf(), and AudioBuffer< double >::operator=().
|
private |
|
private |
|
private |
Referenced by AudioBuffer< double >::addFrom(), AudioBuffer< double >::addFromWithRamp(), AudioBuffer< double >::addSample(), AudioBuffer< double >::applyGain(), AudioBuffer< double >::applyGainRamp(), AudioBuffer< double >::AudioBuffer(), AudioBuffer< double >::clear(), AudioBuffer< double >::copyFrom(), AudioBuffer< double >::copyFromWithRamp(), AudioBuffer< double >::findMinMax(), AudioBuffer< double >::getArrayOfReadPointers(), AudioBuffer< double >::getArrayOfWritePointers(), AudioBuffer< double >::getReadPointer(), AudioBuffer< double >::getRMSLevel(), AudioBuffer< double >::getSample(), AudioBuffer< double >::getWritePointer(), AudioBuffer< double >::makeCopyOf(), AudioBuffer< double >::operator=(), AudioBuffer< double >::reverse(), AudioBuffer< double >::setSample(), and AudioBuffer< double >::setSize().
|
private |
Referenced by AudioBuffer< double >::addFrom(), AudioBuffer< double >::addFromWithRamp(), AudioBuffer< double >::addSample(), AudioBuffer< double >::applyGain(), AudioBuffer< double >::applyGainRamp(), AudioBuffer< double >::AudioBuffer(), AudioBuffer< double >::clear(), AudioBuffer< double >::copyFrom(), AudioBuffer< double >::copyFromWithRamp(), AudioBuffer< double >::findMinMax(), AudioBuffer< double >::getArrayOfWritePointers(), AudioBuffer< double >::getMagnitude(), AudioBuffer< double >::getRMSLevel(), AudioBuffer< double >::getWritePointer(), AudioBuffer< double >::hasBeenCleared(), AudioBuffer< double >::makeCopyOf(), AudioBuffer< double >::operator=(), AudioBuffer< double >::reverse(), AudioBuffer< double >::setDataToReferTo(), AudioBuffer< double >::setSample(), and AudioBuffer< double >::setSize().
|
private |
Referenced by AudioBuffer< double >::addFrom(), AudioBuffer< double >::addFromWithRamp(), AudioBuffer< double >::addSample(), AudioBuffer< double >::allocateChannels(), AudioBuffer< double >::allocateData(), AudioBuffer< double >::applyGain(), AudioBuffer< double >::applyGainRamp(), AudioBuffer< double >::AudioBuffer(), AudioBuffer< double >::clear(), AudioBuffer< double >::copyFrom(), AudioBuffer< double >::copyFromWithRamp(), AudioBuffer< double >::findMinMax(), AudioBuffer< double >::getMagnitude(), AudioBuffer< double >::getNumChannels(), AudioBuffer< double >::getReadPointer(), AudioBuffer< double >::getRMSLevel(), AudioBuffer< double >::getSample(), AudioBuffer< double >::getWritePointer(), AudioBuffer< double >::makeCopyOf(), AudioBuffer< double >::operator=(), AudioBuffer< double >::reverse(), AudioBuffer< double >::setDataToReferTo(), AudioBuffer< double >::setSample(), and AudioBuffer< double >::setSize().
|
private |
|
private |
Referenced by AudioBuffer< double >::addFrom(), AudioBuffer< double >::addFromWithRamp(), AudioBuffer< double >::addSample(), AudioBuffer< double >::allocateData(), AudioBuffer< double >::applyGain(), AudioBuffer< double >::applyGainRamp(), AudioBuffer< double >::AudioBuffer(), AudioBuffer< double >::clear(), AudioBuffer< double >::copyFrom(), AudioBuffer< double >::copyFromWithRamp(), AudioBuffer< double >::findMinMax(), AudioBuffer< double >::getMagnitude(), AudioBuffer< double >::getNumSamples(), AudioBuffer< double >::getReadPointer(), AudioBuffer< double >::getRMSLevel(), AudioBuffer< double >::getSample(), AudioBuffer< double >::getWritePointer(), AudioBuffer< double >::makeCopyOf(), AudioBuffer< double >::operator=(), AudioBuffer< double >::reverse(), AudioBuffer< double >::setDataToReferTo(), AudioBuffer< double >::setSample(), and AudioBuffer< double >::setSize().