# AudioBlock missing getArrayOfChannelPointers() function?

**URL:** <https://forum.juce.com/t/audioblock-missing-getarrayofchannelpointers-function/42665>\
**Category:** General JUCE discussion\
**Created:** [November 10, 2020, 10:09am UTC](https://forum.juce.com/t/audioblock-missing-getarrayofchannelpointers-function/42665 "2020-11-10T10:09:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gustav-scholda](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gustav-scholda/32/4172_2.png) [@gustav-scholda](https://forum.juce.com/u/gustav-scholda)\
**Post date:** [November 10, 2020, 10:09am UTC](https://forum.juce.com/t/audioblock-missing-getarrayofchannelpointers-function/42665/1 "2020-11-10T10:09:38Z")

</div>

Is there a specific reason for not having this kind of function? I just tried to inherit from AudioBlock to implement my own function, but the member channels is private…

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [November 11, 2020, 2:07pm UTC](https://forum.juce.com/t/audioblock-missing-getarrayofchannelpointers-function/42665/2 "2020-11-11T14:07:59Z")

</div>

If you take a close look at how it works internally, you’ll see that the `AudioBlock` stores an array of channel pointer and a sample offset. The `getChannelPointer` function is implemented like this:

```auto
/** Returns a raw pointer into one of the channels in this block. */
SampleType* getChannelPointer (size_t channel) const noexcept
{
    jassert (channel < numChannels);
    jassert (numSamples > 0);
    return channels[channel] + startSample;
}

```

This means, returning the `channels` array directly would not allow you to take that offset into account. So, if you are dealing with legacy APIs that take a 2d pointer array as argument, you’ll need to create a temporary one on the stack and pass it to that function. You could build a helper function like e.g.

```auto
template <size_t maxNumChans, typename SampleType>
std::array<SampleType*, maxNumChans> getArrayOfChannelPointers (const juce::dsp::AudioBlock<SampleType>& block)
{
    std::array<SampleType*, maxNumChans> a;
    auto numChans = block.getNumChannels();

    jassert (maxNumChannels >= numChans);

    for (size_t c = 0; c < numChans; ++c)
        a[c] = block.getChannelPointer (c);

    return a;
}

```

I personally found it most convenient to rebuild all functions taking raw pointer arrays so that they accept Audio blocks directly – you can still re-add a “legacy” overload that converts a pointer array into a block, which works straightforward in contrast to the other direction, to not break any API. But obviously, that only works in case you have control over the functions you are calling.

---

<div class="post-metadata">

**Author:** ![gustav-scholda](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/gustav-scholda/32/4172_2.png) [@gustav-scholda](https://forum.juce.com/u/gustav-scholda)\
**Post date:** [November 11, 2020, 2:33pm UTC](https://forum.juce.com/t/audioblock-missing-getarrayofchannelpointers-function/42665/3 "2020-11-11T14:33:07Z")

</div>

Thank you @PluginPenguin! That makes sense 😉
