Construct AudioBuffer from another AudioBuffer

I’m trying to create a single channel audio buffer which refers to one channel of a multi-channel audio buffer. Pseudocode being:

    const int size = 1024;
    AudioBuffer<float> multiChannel(4, size);
    AudioBuffer<float> singleChannel(multiChannel.getReadPointer(0), 1, size);

The issue I’m having is that getReaderPointer() returns const float* but the constructor wants a float* const*. How do this correctly?

Note: I only intend to be using the singleChannel buffer for reading

AudioBuffer<float> multiChannel (4, size);

int channelNumber = 0;  // the channel number within "multiChannel" that you want to refer to

AudioBuffer<float> singleChannel (multiChannel.getArrayOfWritePointers() + channelNumber,  
                                  1,  // the number of channels
                                  0,  // the start sample of "multiChannel" to take
                                  size); // the number of samples

The added benefit of this constructor of AudioBuffer is that it doesn’t allocate anything, so this is safe to do in the realtime thread. (but ONLY the getArrayOfWritePointers() constructor!!!)

2 Likes