diff --git a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h index 36aade0ffc..3175193e7e 100644 --- a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h +++ b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h @@ -405,11 +405,13 @@ public: it when the buffer is deleted or resized. @param newNumChannels the number of channels to use - this must correspond to the number of elements in the array passed in + @param newStartSample the offset within the arrays at which the data begins @param newNumSamples the number of samples to use - this must correspond to the size of the arrays passed in */ void setDataToReferTo (Type** dataToReferTo, const int newNumChannels, + const int newStartSample, const int newNumSamples) noexcept { jassert (dataToReferTo != nullptr); @@ -424,10 +426,35 @@ public: numChannels = newNumChannels; size = newNumSamples; - allocateChannels (dataToReferTo, 0); + allocateChannels (dataToReferTo, newStartSample); jassert (! isClear); } + /** 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. + + @param 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. + @param newNumChannels the number of channels to use - this must correspond to the + number of elements in the array passed in + @param newNumSamples the number of samples to use - this must correspond to the + size of the arrays passed in + */ + void setDataToReferTo (Type** dataToReferTo, + const int newNumChannels, + const int newNumSamples) noexcept + { + setDataToReferTo (dataToReferTo, newNumChannels, 0, newNumSamples); + } + /** 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.