Share your music and get feedback.
Cape Cod, Masschusetts, USA
About me
James Nicholl
jnicholl17@yahoo.com
______________________
Electronic Music patch: Reaktor Cubic Interpolator
Store Written February 22 2010 , Tags: DSP, reaktor, interpolator, math
I made an interpolator module using Reaktor Core: link

I wrote about how it was put together. The first part of the MOTIVATIONS section and the CONCLUSIONS section are the most accessible. Venture into the DERIVATION section at your own risk, though anyone that's familiar with basic calculus should have no problem understanding the derivation, it really isn't anything special.

MOTIVATIONS

I recently found the need for an interpolator module with dynamic duration. The interpolators included with Reaktor, unfortunately, do not allow the duration of the interpolation to be changed during a performance. My goal is to implement an algorithm that will create a smooth curve between two values. The curve should be continuous, and the slope of the curve should also be continuous, in order to reduce any unwanted high frequencies in the output.

The amplitude of the first value (A_i) should usually be equal to the previous destination value that the user has given, except when the user has not provided such a value, in the intialization state, in which case the user should input an initial amplitude or accept the default value of 0, and in the case that the user submits data while the algorithm is still interpolating. The amplitude of the second value provided by the user (A_f) is the value which the algorithm will interpolate towards. The slope of the curve should approach zero as the curve approaches A_f.

The algorithm should account for the scenario in which the user inputs a destination value while interpolation is taking place. In this case, then the algorithm should provide a smooth curve based on the parameters:
A_i - The output amplitude of the algorithm when the trigger is received to begin interpolation.
S_i - The slope of the output amplitude when the trigger is received to begin interpolation.
A_f - The destination amplitude provided by the user.

The choice of curve is cubic. Polynomials are fairly easy to work with, and a simple solution is preferable. A quadratic solution does not exist, because the slope of the curve required for interpolation must equal 0 in exactly two places. Then, a cubic polynomial curve is a good choice due to both its simplicity, and just sufficient complexity.

This line of reasoning also implies that a quartic solution may be preferable if it is desired that the user should also be allowed to adjust the curve shape. In this case it is not necessary.

DERIVATION

Start with a general equation for a cubic curve over time (t on the interval [0,1]):

C(t) = a*(t^3) + b*(t^2) + c*t + d

Where a, b, c, and d are arbitrary constants.

The equation for the slope of the curve is then equivalent to the derivative of C(t) with respect to t.

C'(t) = 3*a*(t^2) + 2*b*t + c

It is given, by the nature of the problem, that:
C(0) = A_i
C(1) = A_f
C'(0) = S_i
C'(1) = 0

A solution for the arbitrary constants a, b, c, d in terms of the given values A_i, A_f and S_i is desired.

Since C(0) = d and C(0) = A_i, then d = A_i.

Also, since C'(0) = c and C'(0) = S_i, then c = S_i.

We are left with two equations and two unknowns:
C(1) = A_f = a + b + c + d = a + b + S_i + A_i
C'(1) = 0 = 3*a + 2*b + c = 3*a + 2*b + S_i

Solving for a and b yields the following solutions:
a = -2*A_f + S_i + 2*A_i
b = -3*A_i - 2*S_i + 3*A_f

Finally, an equation for the general curve, which can be applied over the desired duration simply by scaling t appropriately.

C(t) = (-2*A_f + S_i + 2*A_i)*(t^3) + (-3*A_i - 2*S_i + 3*A_f)*(t^2) + S_i*t + A_i

CONCLUSIONS

The algorithm works quite well using the equation derived above. I have provided a sample output in the form of a screen capture that was produced during unit testing.

The CPU load required for this module seems low on my system. Some optimizations were implemented, especially to minimize processor usage while the algorithm is idle (not interpolating). The amount of code required for this implementation seems very small. It is a compact solution, as well as an efficient one.

While the factory module for interpolation requires less CPU usage, it is limited in its usefulness; the duration of interpolation is not dynamic. The interpolator module I have produced, however, can also be used as an n step envelope module, or as a low frequency oscillator, depending on how it is implemented.

In short, I am satisfied with this solution, and I have finally, successfully eliminated all the clicks from the output of the Resynth granular synthesis module I like so much.

Thanks for reading, I hope you've found this post useful.
Comments
wow, looks like an interesting project. You're way over my head there. I havent found myself needing something advanced like that for the purpose... I tend to just ghetto-style use a 6db lowpass filter on whatever signal to smooth it. I'm curious what exact application you're using this for?
I really appreciate that you did that. Extra-mile stuff. The hard-to-make invisible stuff that brings quality to a project.
It's just for quick fade in and fade out on a sampler. I often change the sample offset while playing, and if the playback starts from the middle of the sample, then there's a chance it'll click.

Basically, I add some latency to all the control signals going into the sampler module, and use the latency to quickly fade out the audio, then trigger the new sample, and simultaneously start to fade back in. (latency time always equals release/fade out time)

The attack and release times are adjustable depending on the program material, but the release time can't be changed during performance without generating some artifacts. It's not really an issue, it's just a non performance parameter.

It's nothing mind blowingly original, just a solution to a problem that's plagued my ensembles for literally years. I just now got around to solving it. It only took one day off to do in the end. I tried a couple of other solutions before, but they didn't work. This way works. Yay!
...before I was using the Wavelab declicker on my stems. It sounded like garbage. This sounds decent. Can't say how pleased I am that it's finally solved.

It also got me to thinking how to design a sine curve interpolator that'll sound a litte nicer, but I'm not sure if I'll spare the time for it since this way works well enough.
thats actually really handy. reaktor samplers click all the time so I'm glad i downloaded this. maybe i'll get around to implimenting it in some of my samplers. i'm really glad that the small reaktor community on this site is productive. meaning eyesnine and bagger. hopefully i"ll have something to contribute in the future.
excellent work, man. way to put the love in it.
top quality stuff. thanks for sharing this. finally i can load up my favourite ensembles and not have to hunt thru the out put for those random tiny evil square waves
wow, it seems that people are getting really sciency with their blogs lately. i like it, although i don't use reaktor. talk about music and throw in a couple of formulas and i'm sold.


Signup to comment
You must be a member to reply or post. signup or login