This is the continuation of an issue that has been discussed in the Flashstorage branch topic.
Since some time (too long!) we’ve been working on implementing fast, accurate lookup-based approximations of exp
, pow
, log
and related functions. The problem has been balancing speed, size, accuracy, portability and overheads. And ease of use. And it has to work for all types of patches - C++, FAUST, Gen, Pd - and all targets: device, web, vst. Phew.
Minimising overheads means that, ideally, if your patch doesn’t use these functions it shouldn’t have to carry any extra luggage, either in code or data.
Portability here means that when we deploy a solution, new patches should still run on older firmware versions, and old patches should run on the new firmware.
I think I’ve come up with a solution that fits the bill.
The implementation is based on http://www.hxa.name/articles/content/fast-pow-adjustable_hxa7241_2007.html
It involves lookup tables where higher precision means better accuracy, and (exponentially!) bigger tables.
What we can do is generate tables of a decent size to put in the next version of the firmware. The patch will be able to request these tables, and if they’re not available it will itself supply some smaller, default tables. And if the fast math functions aren’t used, then the default tables don’t get compiled into the patch at all.
So with new patches on new firmware you get speed and accuracy. With new patches on old firmware you get speed but reduced accuracy.
I think that initially the patches should be compiled with fast math functions as an ‘optional extra’, ie they have to be explicitly called from C++ (with e.g. fast_expf(x)
instead of expf(x)
). Once most people have migrated to the new firmware version, we can make this the default, with the option of de-selecting the fast maths in the patch.
What’yall think?