Hello guys !
Today, I’m going to start a talk about the classes in the DSP module that help fast computation of functions.
So backi in July I designed the functions in the class
FastMathApproximations that are like it is said fast approximations of math functions such as sinh, tanh, cosh, exp, log(1+x) etc. They are faster than their std counterparts, but they have also a limited useful range, that is provided in the documentation. Basically, the error between the std function and the approximation is quite good in this range, and can be significant outside.
These functions have been designed mainly by using Pade approximant continued fractions, which means they are made from additions, multiplications and one division. They are useful in contexts where you need to call multiple times for every sample such functions, and that the std variants are the slowest part of the processing path, which can happen a lot in “virtual analog” audio effects for example, or when a variable needs to be updated at audio rate.
I’m looking also for some reviews from the JUCE community because I know there are tons of other ways to optimize such functions. I know developers that use all the time a large set of fast approximated functions, with accuracy depending on the context, and sometimes some embedded crude oversampling processing in the approximations. I saw also code written in full assembly. And I’m wondering also if it could be useful to provide additional versions of the functions with different levels of accuracy…
For fast computation of functions, there are also another classes called
LookupTableTransform which allow developers to create one dimensional lookup tables with linear interpolation and uniform grid size for any function, that can be specified via a lambda, with a given size and for a given range of input values. They are very neat for waveshapers, for optimizing function code as well, and even for oscillators as you might have already seen in the DSP module demo application. They have been designed by the great @zsolt Zsolt Garamvölgyi from the ROLI team, and I think that class should be used everywhere in your code when possible, look up tables are one of the essential tools a DSP engineer should use all the time in his code.
So tell me if you have already used these classes, what you think about them, if you have any suggestion, remark