AudioSampleBuffer memory allocation

I’m currently trying to write an AudioSpectrumBuffer in a similar style to the AudioSampleBuffer.

Something I don’t quite understand is the memory allocation process (down at the first hurdle or what). Why exactly is the memory stored as a

first, then

later in allocateData().

I guess my question is why isn’t it float instead of char in the first place.
Obviously there is a reason for this but I don’t know what it is! :slight_smile:

I’m pretty new to this, but my understanding is that HeapBlock is used as a convenient and leak safe way of allocating memory. reinterpret_cast <float**> then changes the type of the pointer so that it handles a 2D array of floats.

First dimension is the audio channel number, second dimension is the sample index (up to buffer size). Before the reinterpret_cast you should see a bit of code which allocates the required amount of memory to satisfy these dimensions.

The memory allocation for AudioSampleBuffer has, at the beginning of the allocation, an array of float pointers, then followed by the actual sample data for each channel. The array of float pointer is what is returned from getArrayOfChannels().

Just saw this in the documentation.

Pretty much clears up the confusion I was having. I understand the rest. Thanks for the help.