Copying an AudioSampleBuffer


#1

Hi all, I am writing a reverb plugin from a Schroder/Moorer model and currently have it working successfully by processing each sample individually. However as I am using about 30 filters calling the processSingleSample() for each one creates one hell of a cpu drain.

As I need adjustable amounts of wet/dry for both the early and late reveb sections I need to somehow make a copy of the buffer twice, process them individually and then sum them back with the original.

I thought I could do this by creating a new AudioSampleBuffer from the existing one eg. AudioSampleBuffer wetBuffer(buffer); but this is not possible as the buffer contains only pointers to samples so they effectively point to the same set of samples.

Does anyone know how this is usually done? Will I have to manually loop through all the buffer’s contents copying them into a new heap array of floats, process these then loop through the buffer’s contents again adding them back on?


#2

Well, you don’t have to manually write the loops, you could use AudioSampleBuffer::copyFrom and addFrom to shift the data around.


#3

If you want optimised code you should use your own aligned buffers and as many sse calls on blocks of 4 floats as possible via _mm_xxxx_ps type intrinsics. Otherwise even straight c++ is fine if you write it in a way to allow the compiler to optimise it. There are many sites such as http://www.asdf.org/~fatphil/x86/pentopt/index.html to help.

You are always best off hand coding inner loops and only having very limited use to non intrinsic force inlined functions otherwise they won’t get inlined at all.

Andrew Simper


#4

Cheers, I used the AudioSampleBuffer in the way Jules suggested and it works well.

I’m reading up on vectorisation at the moment so hope to implement these optimisations soon.

Dave.