Forums > Dev

Accelerate.framework example ?

April 11, 2010 | 4:02 pm

Hello maxers,

is anybody know a link to an external C code example using Accelerate.framework ?


April 12, 2010 | 6:53 pm

Add the framework to your Xcode project (and relevant targets), and include headers like this:


That’s all you need to do to get it working. How to code for the framework can be figured out by reading the docs – depends what you want to do with it really.



April 13, 2010 | 3:16 am

"username phidjee(sp?) turned me onto Accelerate"

Still there ;-)

The thread was:
Then, you get a code that looks like that:

// calculate the MIDI note for each frequency (plus 0.5 integer floor margin)
// MIDI note = 69.5 + 12 * log2(freq / A440)
vDSP_vsdivD(frequencies, 1, &a440, x->mFloatBuffer, 1, size);
vvlog(x->mFloatBuffer2, x->mFloatBuffer, &size);
vDSP_vsmulD(x->mFloatBuffer2, 1, &x->mTwelveILog2, x->mFloatBuffer, 1, size);
vDSP_vsaddD(x->mFloatBuffer, 1, &x->mSixtyNineHalf, x->mFloatBuffer2, 1, size);

April 13, 2010 | 6:03 am

Hello maxers,

i was curious more about vBasicOps.h and vfp.h ; i read docs from Apple, and few others : still some things i don’t understand well ; f.e. how to allocate/free dynamic aligned data with max SDK, the best way to connect t_atom to vFloat etc … Fair enough, will try … Sure, but a good-looking small example code would avoid me a dozen of crash ?

says that : "Pointers returned by Mac OS X’s malloc are aligned to multiples of 16 bytes", is sysmem_newptr ( ) do the same ?

April 13, 2010 | 7:32 am

I’ve personally never bothered to use vector ops for anything purely max based. I would only really consider doing this in a scenario where I was processing quite a lot of data in one go.

To deal with t_atoms you would probably need to copy everything out of an array of t_atoms to an aligned set of vFloats and then copy back into t_atoms when you are done (if necessary). The copying will not be that fast, because of having to deal with the union structure – another reason not to bother unless you are doing something pretty expensive in the first place (otherwise the overhead will kill any speed gain).

Where it is really worth it is in msp externals, where you can get some good speedups, and you are dealing with simple data types in the form of signals, which you can now (as of 5.1.3) assume to be aligned already.

In addition, I’d be really surprised if calling a number of functions to perform one operation each (as the above code) is really going to be that fast, because it’s always better to do more with your data once you’ve pulled it out of memory into the registers. As such, I always write my own loops using SSE or Altivec intrinsics. I use macros and #ifdefs to allow me to write one set of code that will compile for both platforms, although the PPC side of things is becoming less and less relevant.


April 13, 2010 | 8:25 am

Hello AlexHarker,

That’s right, it seems not very useful to use "vector ops for anything purely max based" in my external ; but i try to understand, (and i understand now), in case of !

To be honest i started with that as i was thinking about speeding up a math function who was very long to compute, and as usual : just change the algorithm divide by ten the time process, so bye bye Accelerate !

Maybe i’ll be back when i’ll have concrete task,
Thanks for reply.

PS : as a newbie i am still afraid with #ifdefs and co ;-)

Viewing 6 posts - 1 through 6 (of 6 total)