Skip to content

Instantly share code, notes, and snippets.

@SpotlightKid
Last active February 26, 2023 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpotlightKid/9fe3b2638b8a1fa8b1a1d007716a45cb to your computer and use it in GitHub Desktop.
Save SpotlightKid/9fe3b2638b8a1fa8b1a1d007716a45cb to your computer and use it in GitHub Desktop.
FAUST versatile stereo chorus effect
declare name "CChorus";
declare version "0.5";
declare author "Christopher Arndt";
declare license "MIT License";
declare description "Versatile stereo chorus effect";
import("stdfaust.lib");
PI = ma.PI;
TWOPI = 2.0 * ma.PI;
MAX_DELAY_MS = 20;
// Parameters
// Delay section
del_group(x) = hgroup("Delay", x);
delay_ms = del_group(hslider("[1] Delay [unit:ms] [style:knob]", 3.5, 0, MAX_DELAY_MS, 0.001) : si.smoo);
delay_mod = del_group(hslider("[2] Mod Amount [style:knob]", 0.35, 0, 1, 0.001) : si.smoo);
lpf_cutoff = del_group(hslider("[3] LPF Cutoff [unit:Hz] [scale:log] [style:knob]", 5000, 20, 10000, 0.1)): si.smoo;
hpf_cutoff = del_group(hslider("[4] HPF Cutoff [unit:Hz] [scale:log] [style:knob]", 20, 20, 5000, 0.1)): si.smoo;
// LFO section
lfo_group(x) = hgroup("LFO", x);
lfo_switch = lfo_group(hslider("[1] Waveform [style:radio{'Sine':0;'Triangle':1}]", 1, 0, 1, 1));
lfo_freq_l = lfo_group(hslider("[2] Freq L [unit:Hz] [style:knob]", 0.8, 0.001, 10, 0.01));
lfo_freq_r = lfo_group(hslider("[3] Freq R Ratio [style:knob]", 1.0, 0.01, 2, 0.01)) * lfo_freq_l;
lfo_phase_r = lfo_group(hslider("[4] L/R Phase Offset [unit:°] [style:knob]", 90, -180, 180, 1) / TWOPI : si.smoo);
// Output section
out_group(x) = hgroup("Output", x);
dry = out_group(hslider("[1] Dry [unit:dB] [style:knob]", -3.5, -60, 10, 0.1) : ba.db2linear);
wet = out_group(hslider("[2] Wet [unit:dB] [style:knob]", -3.5, -60, 10, 0.1) : ba.db2linear);
bypass_switch = out_group(checkbox("[3] Bypass"));
// Modulation LFOs
// Oscillator with run-time controllable phase
// by Dr Dario Sanfilippo
phasor(freq, phase) = ma.frac((loop ~ _) + phase / TWOPI)
with {
loop(y) = ma.frac(freq / ma.SR + y);
};
tri(ph) = abs(ma.frac(ph - .25) * 4.0 - 2.0) - 1.0;
lfo_l = select2(lfo_switch, sin(phasor(lfo_freq_l, 0) * TWOPI), tri(phasor(lfo_freq_l, 0)));
lfo_r = select2(lfo_switch, sin(phasor(lfo_freq_r, lfo_phase_r) * TWOPI), tri(phasor(lfo_freq_r, lfo_phase_r)));
// L/R delay lines
delay_l = delay_ms + delay_ms * delay_mod * lfo_l;
delay_r = delay_ms + delay_ms * delay_mod * lfo_r;
// Delay filters
lpf = fi.lowpass(2, lpf_cutoff);
hpf = fi.highpass(2, hpf_cutoff);
// Chorus
chorus_mono(curdel, filter, dry, wet) = _ <: _ * dry + wet_signal * wet
with {
dmax = ma.SR * 0.001 * MAX_DELAY_MS * 2; // Mod Amount = 1 => double max delay time
wet_signal = de.fdelay(dmax, curdel * 0.001 * ma.SR) : filter;
};
// L/R FX chains
chorus_l = chorus_mono(delay_l, lpf : hpf, dry, wet);
chorus_r = chorus_mono(delay_r, lpf : hpf, dry, wet);
process = _, _ <: select2(bypass_switch, chorus_l), select2(bypass_switch, chorus_r);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment