Hi there. I have these two arrays of 2 channels each. I’d like to create a new array that has the pointer of channel 1 of the first array and pointer of channel 2 of the second array.
So far there are only two input buffers, but I’d like for it to be flexible to incorporate more input buffer read pointers later on.
float* const* pArrayInputBuffer = const_cast<float *const *>(inputBuffer.getArrayOfReadPointers());
float* const* pArrayInputBuffer2 = const_cast<float *const *>(inputBuffer2.getArrayOfReadPointers());
You can’t do that with AudioBuffer.
There’s a strong guarantee in that structure that the two dimensional array is contiguous for performance.
Instead, I would create a helper struct that wraps these two AudioBuffers and creates the correct channel layout:
using Buffer = juce::AudioBuffer<float>;
struct BufferCombiner
{
BufferCombiner(Buffer& leftToUse, Buffer& rightToUse)
: left(leftToUse)
, right(rightToUse)
{
}
float* getChannel(int index) noexcept
{
if (index == 0)
return left.getWritePointer(0);
return right.getWritePointer(0);
}
//maybe other helper functions like getNumSamples(), etc
Buffer& left;
Buffer& right;
};
1 Like