Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (70 sloc) 2.17 KB
// Foldback Distortion
//
// When the signal reaches the set ceiling or 0, it will be
// "folded" into the opposite direction. Which means values
// (ceiling + overshoot) will become (ceiling - overshoot).
//
// This will continue folding between ceiling and 0 until
// no more overshoot is found, so it will grow rather CPU
// demanding with increasing amounts of folds/distortion.
//
// This is not oversampled, i.e. it will create aliasing. I
// tried adding oversampling to this, and all that happened
// was that the distorted waveforms lost the new harmonics
// and with every additional oversampling step, the output
// gradually went back to its original form. So, kinda meh.
//
// But I added a DC blocker in, with all the aliasing can't
// really hurt to have that around.
//
// author: chokehold
// url: https://github.com/chkhld/jsfx/
// tags: processing distortion foldback
//
desc: Foldback Distortion
slider1:dBCeiling=0<-48, 0,0.01> Ceiling dBfs
slider2:dBBoost=0< 0,48,0.01> Boost dB
slider5:blocker=0<0,1,{Enabled,Disabled}> DC Blocker
in_pin:left input
in_pin:right input
out_pin:left output
out_pin:right output
@init
// Decibel to gain factor conversion
function dBToGain (decibels) (10.0 ^ (decibels / 20.0));
function foldback () instance (signum)
(
signum = sign(this);
while ((this > ceiling) || (this < 0))
(
this < 0 ? this = abs(this);
(this > ceiling) ? this = ceiling - (this - ceiling);
);
this *= signum;
);
// DC Blocker to remove near-static frequency content
// that would otherwise "offset" the waveform.
function dcBlocker () instance (stateIn, stateOut)
(
stateOut *= 0.99988487;
stateOut += this - stateIn;
stateIn = this;
this = stateOut;
);
@slider
ceiling = dBToGain(dBCeiling);
gain = dBToGain(dBBoost);
@sample
// Input boost
spl0 *= gain;
spl1 *= gain;
// Finally, the actual processing
spl0.foldback();
spl1.foldback();
// If DC blocking enabled
blocker == 0 ?
(
// Run the DC blocker on each sample
spl0.dcBlocker();
spl1.dcBlocker();
);
You can’t perform that action at this time.