Hi all & Jules in particular :)
I found recently that I had some SSE code that assumed 16-byte alignment without checking for it. Unfortunately, PluginHost doesn't enforce alignment so sometimes my code would crash and sometimes it wouldn't.
To test for 16-byte alignment I'm doing something like this:
isAligned = (reinterpret_cast<uintptr_t>(buffer.getReadPointer (ch))& 0xF) == 0
After a bit of investigation I've found that by using DirectSound and trying different buffer sizes I can usually find a case where the audio data isn't aligned. Note that the allocation is kind of random, so the same buffer size might sometimes result in aligned data.
The attached plugin code can be used to demonstrate this. It also shows how to allocate data using _mm_malloc and then use AudioSampleBuffer::dataReferTo() so we end up with an aligned AudioSampleBuffer. It's important to never call AudioSampleBuffer::setSize() as this will reallocate the memory using malloc. As you can see, that's all a bit kludgy.
Jules - can you think of a neat way to add aligned allocation as an option for AudioSampleBuffer? Seems to me it might be a bit of work to make it cater for different alignments (16 for SSE, 32 for AVX) and also make it safely portable.
PS some useful links: