Created
November 8, 2024 11:50
-
-
Save paniq/48ac808d24a4c3b8060eed2767e4f799 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# State Variable Filter (Double Sampled, Stable) | |
based on information from Andrew Simper, Laurent de Soras, | |
and Steffan Diedrichsen | |
svf = proc s : | |
* = fmul | |
- = fsub | |
+ = fadd | |
% = fmod | |
/ = fdiv | |
min = fmin | |
pow = fpow | |
NOTCH = 0 | |
LOW = 1 | |
HIGH = 2 | |
BAND = 3 | |
fs = var 44100.0 # sampling frequency | |
fc = var 1000.0 # cutoff frequency normally something like: 440.0*pow(2.0, (midi_note - 69.0)/12.0) | |
res = var 0.5 # resonance 0 to 1 | |
drive = var 0.0 # internal distortion 0 to 0.1 | |
mode = var HIGH # 0=notch, 1=low, 2=high, 3=band | |
freq = s.l s.r ? * 2.0 (sin (* pi (min 0.25 (/ fc (* fs 2.0))))) # the fs*2 is because it's double sampled | |
damp = s.l s.r ? min (* 2.0 (- 1.0 (pow res 0.25))) (min 2.0 (- (/ 2.0 freq) (* freq 0.5))) | |
channel = proc s : | |
V1 = var 0.0 | |
V3 = var 0.0 | |
tick = proc v_1 v_3 : | |
v_0 = - s (* damp v_3) | |
v_1 = + v_1 (* freq v_3) | |
v_2 = - v_0 v_1 | |
v_3 = - (+ (* freq v_2) v_3) (* drive (* v_3 (* v_3 v_3))) | |
(SELF) | |
t1 = tick V1 V3 | |
t2 = tick t1.v_1 t1.v_3 | |
next V1 t2.v_1 | |
next V3 t2.v_3 | |
out = or | |
(case mode NOTCH) ? + t1.v_0 t2.v_0 | |
(case mode LOW) ? + t1.v_1 t2.v_1 | |
(case mode HIGH) ? + t1.v_2 t2.v_2 | |
(case mode BAND) ? + t1.v_3 t2.v_3 | |
* 0.5 out | |
l = channel s.l | |
r = channel s.r | |
(SELF) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment