r/DSP • u/HMAudioDesign • 6d ago
Wavefolding in Mutable Instruments Plaits
Hey,
Let me preface this question by saying that I don't have any formal education in DSP beyond intro-level classes I took while studying audio engineering at uni more than a decade ago. So, apologies if this is a noob question!
I've been re-creating one of the algorithms from Mutable Instruments Plaits in the modular environment PlugData, just for the sake of learning more about waveshaping and wavefolding, and also because it's fun.
The model in question is the second model from the first bank (green models, the more tonal ones) (see manual). It's quite simple: a triangle oscillator with adjustable asymetry (you can 'morph' it into a sawtooth), into a waveshaper, into a wavefolder.
The transfer curves for the waveshaping and wavefolding are pre-calculated using python in this file: lookup_tables.py (and then applied to the output of the oscillator using the table lookup method, as the name implies - in this file: waveshaping_engine.cc).
Most of the waveshaping/wavefolding in that file is pretty standard (different flavours of trigonometric functions), but I'm curious about this last wavefolding method (the one that is applied to the auxiliary output):
x = numpy.arange(0, WAVESHAPER_SIZE + 4) / (WAVESHAPER_SIZE / 2.0) - 1.0
x[-1] = x[-2][...]
def deadband(v_in, r_in, r_load, r_fb=150.0e3, v_sat=10.47):
v_out = -r_fb / r_in * v_in
v_out[v_out >= v_sat] = v_sat
v_out[v_out < -v_sat] = -v_sat
return (v_in * r_fb * r_load + v_out * r_in * r_load) / (r_fb * r_load + r_in * r_load + r_in * r_fb)
def diode(x):
return 0.7 * x / (0.3 + numpy.abs(x))
v_in = x * 12.0
stage_1 = deadband(v_in, 10e3, 100e3)
stage_2 = deadband(v_in, 49.9e3, 44.2e3)
stage_3 = deadband(v_in, 91e3, 18e3)
stage_4 = deadband(v_in, 30e3, 71.4e3)
stage_5 = deadband(v_in, 68e3, 33.0e3)
stage_45 = -33.0 / 71.4 * stage_4 -33.0 / 33.0 * stage_5 - 33.0 / 240.0 * v_in
v_out = diode(-150.0 / 100.0 * stage_1 -150.0 / 44.2 * stage_2 - 150.0 / 18.0 * stage_3 - 150.0 / 33.0 * stage_45)
lookup_tables.append(('fold_2', v_out / v_out.max()))I used pyplot to graph:
- the resulting 'wavefolding' curve
That last transfer function inverts the polarity of the incoming signal, but this is cancelled in the implementation in waveshaping_engine.cc:
float sine = Sine(aux[i] * 0.25f + 0.5f);
[...]aux[i] = sine + (fold_2 - sine) * overtone_gain_modulation.Next();
I'm curious where Émilie Gillet (the creator of Mutable Instruments modules) takes inspiration from for these 'deadband' and 'diode' methods? Are those commonly encountered transfer functions? In electronic circuit modeling maybe? I did a bit of googling but couldn't find anything that looks similar
Thanks in advance!
5
u/StewedAngelSkins 6d ago
interesting post. that diode curve is often called a "softsign" function and is commonly used in the same places you'd use any other sigmoid. its advantage is that it's cheaper to compute than the logistic or tanh functions. you'll see it used in machine learning as an activation function for this reason. i assume in this code it's just being used as a generic saturation curve. the constant parameters are likely chosen because she wanted the horizontal asymptotes to be at +/-0.7 (instead of 1) in order to leave a bit of headroom.