Efficient algorithm for cubic interpolation

Hello,
I am working on fft analyser. And actually my analyser works great at the moment, but only when I use juce::Path::cubicTo(). And because as usual I add horizontal coordinates logarithmically calculated from my FFT bins so Paths nodes X coordinates are not spaced equally.

But now I need to draw it as bar chart. So I need points which are spaced equally. To do that I do something which is killing my CPU. The method is that I still create path with cubicTo(), but later for each equally spaced X I use: myPath[i].getClippedLine(Line<float>(x, getHeight(), x, 0.0f), false);

So to improve the efficiency I think I should create my own XY array. But then I need to interpolate Y coordinates for all equal spaced Xs by myself.
But I found out that cubic interpolation is not such simple subject so I would like to ask you if you know any good library to achieve such interpolation. I was looking at Boost Cubic B-Spline but it looks like it works only for functions with already equally spaced points, but as my FFT bins are spaced logarithmically so I think I need to find something else.

Or maybe there is anything which I missed in juce::Path But it looks like juce::Path::iterator iterates only through the nodes but not through any given X coordiates.

For any help great thanks in advance.
Best Regards.

Consider trying JUCE: PathFlatteningIterator Class Reference .

Alternatively: I haven’t used it but glancing over it, it seems the Spline class from the gin modules could solve your problem.

1 Like

I figured this is worth sharing: the Gin spline implementation is based on this Cubic Spline Interpolation blog post, if there’s interest in rolling your own portable spline algorithm.

Hello,
great thanks for your answers. After an exhaustive search I found out the best way in my case would be Centripetal Catmull–Rom spline

On some other post I also found very nice video which I advice to watch for everyone who try to understand slines little bit more:

Best Regards.

2 Likes

A close relative is the Cubic Hermite Spline (linked on your Wikipedia link).
A great read is the blog post from our friend Signalsmith:

2 Likes

The Continuity of Splines is an absolute banger when it comes to a fully fledged video about splines, but the video that actually taught me how to implement a basic spline was this one:

1 Like