File: expander.dsp

package info (click to toggle)
faust 2.79.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 397,496 kB
  • sloc: cpp: 278,433; ansic: 116,164; javascript: 18,529; vhdl: 14,052; sh: 13,884; java: 5,900; objc: 3,852; python: 3,222; makefile: 2,655; cs: 1,672; lisp: 1,146; ruby: 954; yacc: 586; xml: 471; lex: 247; awk: 110; tcl: 26
file content (51 lines) | stat: -rw-r--r-- 1,340 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

/* Expander unit. */

/* This is pretty much the same as compressor.dsp, but here the given ratio is
   applied to *attenuate* levels *below* the threshold. */

declare name "expander -- expander/noise gate unit";
declare author "Albert Graef";
declare version "1.0";

import("music.lib");

/* Controls. */

exp_group(x)	= hgroup("1-expander", x);
env_group(x)	= vgroup("2-envelop", x);
gain_group(x)	= vgroup("3-gain", x);

ratio		= exp_group(nentry("ratio", 2, 1, 20, 0.1));
threshold	= exp_group(nentry("threshold", -40, -96, 10, 0.1));
knee		= exp_group(nentry("knee", 3, 0, 20, 0.1));

attack		= env_group(hslider("attack", 0.001, 0, 1, 0.001)) : max(1/SR);
release		= env_group(hslider("release", 0.1, 0, 10, 0.01)) : max(1/SR);

gain(x)		= attach(x, x : gain_group(hbargraph("gain", -96, 0)));

t		= 0.1;
g		= exp(-1/(SR*t));
env		= abs : *(1-g) : + ~ *(g);
rms		= sqr : *(1-g) : + ~ *(g) : sqrt;
sqr(x)		= x*x;

env2(x,y)	= max(env(x),env(y));

expand(env)	= level*(1-r)
with {
	level	= env : h ~ _ : linear2db : (threshold+knee-_) : max(0)
	with {
		h(x,y)	= f*x+(1-f)*y with { f = (x<y)*ga+(x>=y)*gr; };
		ga	= exp(-1/(SR*attack));
		gr	= exp(-1/(SR*release));
	};
	p	= level/(knee+eps) : max(0) : min(1) with { eps = 0.001; };
	r	= 1-p+p*ratio;
};

process(x,y)	= (g*x,g*y)
with {
	g	= env2(x,y) : expand : gain : db2linear;
};