Question about C++ syntax in Fundamental Noise module

Hi!

I’m looking to use the SDK’s wrapper for pffft so I went searching for an example of its use. I found one in the Fundamental Noise module, and I have a question about it. It’s not so much about the math or algorithm, but about some C++ syntax, which I’m still getting the hang of.

Why is it that the input and output buffers are initialized as they are? Particularly the alignas specifier and the empty brackets {}? (https://github.com/VCVRack/Fundamental/blob/eb41dd7cdf1112530c1a8059cfa3a99a402944ef/src/Noise.cpp#L34)

Regarding alignment, I so far am thinking this:

(From cppreference.com)

Every object type has the property called alignment requirement , which is an integer value (of type std::size_t, always a power of 2) representing the number of bytes between successive addresses at which objects of this type can be allocated.

From this, my understanding is that the code initializing the input and output buffers each as 16 aligned addresses. I would hazard a guess that this improves performance of the FFT?

The other question was about why the buffer is initialized with the empty brackets. Would it also work without the empty brackets? In another way of phrasing my question, what is the difference between the two below initializations?

int[LEN] foo;
int[LEN] bar = {};

Please let me know if I can clarify my two questions here! Thanks :slight_smile:

pffft uses SSE instructions on the input/output buffer directly, so the buffers need to be aligned to 16 bytes. I’m pretty sure pffft has a runtime check for this, so if buffer % 16 != 0 it returns an error. Or it just crashes, I don’t remember.

This initializes the buffer with default values, which is 0 for the int type. Without it, the values are undefined.

1 Like

Thanks for the quick answer!

pffft also offers this function to allocate an aligned buffer, if ever it’s relevant for you:

pffft_aligned_malloc(...)

2 Likes