-
Notifications
You must be signed in to change notification settings - Fork 0
/
colored_noise
145 lines (112 loc) · 3.11 KB
/
colored_noise
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
desc:Colored noise generator
//tags: analysis generator synthesis
//author: Tale
// Copyright (C) 2014-2019 Theo Niessink
// License: LGPL - http://www.gnu.org/licenses/lgpl.html
// This effect generates different "colors" of noise. Apart from the listed
// colors it can also generate "black" noise. To do so select white noise
// and lower the density. Note that density affects only white noise, and is
// ignored for other colors.
slider1:2<0,5,1{Brown,Pink,White,Blue,Violet,Grey}>Color
slider2:1.0<0.0,1.0,0.001>Density
slider3:0<0,1,1{Mono,Stereo}>Mode
slider4:0.0<-150.0,24.0,0.1>Dry (dB)
slider5:-24.0<-150.0,24.0,0.1>Wet (dB)
slider6:0<0,4,1{Bypass,Low-Pass,Band-Pass,High-Pass,Notch>Filter
slider7:1000.0<20.0,20000.0,1.0>Cutoff (Hz)
slider8:2.0<0.01,8.0,0.01>Q
in_pin:Left
in_pin:Right
out_pin:Left
out_pin:Right
import noise.jsfx-inc
import rc_filter.jsfx-inc
import zdf_filter.jsfx-inc
@init
function pow4(x) ( x*x*x*x );
function cache(x) ( x != this ? ( this = x; 1; ); );
function gain(db, inf)
(
db <= inf ? 0 : exp(/* log(10)/20 */ 0.11512925464970228 * db);
);
smooth.rc_set(0.0033);
function smooth()
(
smooth.lp = this.smooth;
this.smooth = smooth.rc_lp(this);
);
min_inf = -150.0;
dry.smooth = gain(slider4, min_inf);
wet.smooth = gain(slider5, min_inf);
// rms = 0;
rms[0] = 0.075;
rms[1] = 1/3;
rms[2] = 1;
rms[3] = 0.56;
rms[4] = sqrt(0.5);
rms[5] = 0.125;
ratio = 6;
ratio[3] = srate * 1/44100;
ratio[5] =
ratio[2] = sqrt(ratio[3]);
ratio[4] = ratio[2] * ratio[3];
ratio[0] = 1 / ratio[2];
ratio[1] = 1;
@slider
color = slider1|0;
gain = rms[color] * ratio[color];
rng0.lcg_density(color < 0 || color > 5 ? 0 : pow4(slider2));
rng1.lcg_density(rng0.density);
stereo.cache(slider3 >= 0.5) ? (
rng0.lcg_init(2147483646);
stereo ? rng1.lcg_init(1518500249);
);
dry = gain(slider4, min_inf);
wet = gain(slider5, min_inf);
filter = max(slider6|0, 0);
filter > 4 ? filter = 0;
filter ? (
fc = max(20, slider7);
q = max(0.01, slider8);
filter == 1 ? zdf0.zdf_lp(fc, q) :
filter == 2 ? zdf0.zdf_bp(fc, q) :
filter == 3 ? zdf0.zdf_hp(fc, q) :
/* filter == 4 ? */ zdf0.zdf_bs(fc, q);
stereo ? (
zdf1.cb = zdf0.cb; zdf1.ch = zdf0.ch; zdf1.cl = zdf0.cl;
zdf1.g = zdf0.g; zdf1.h = zdf0.h; zdf1.r2 = zdf0.r2;
);
);
@sample
color == 0 ? (
left = rng0.lcg_brown();
stereo ? right = rng1.lcg_brown();
) :
color == 1 ? (
left = rng0.lcg_pink();
stereo ? right = rng1.lcg_pink();
) :
color == 3 ? (
left = rng0.lcg_blue();
stereo ? right = rng1.lcg_blue();
) :
color == 4 ? (
left = rng0.lcg_violet();
stereo ? right = rng1.lcg_violet();
) :
color == 5 ? (
left = rng0.lcg_grey();
stereo ? right = rng1.lcg_grey();
) :
/* color == 2 ? */ (
left = rng0.lcg_black();
stereo ? right = rng1.lcg_black();
);
left *= gain;
stereo ? right *= gain : right = left;
filter ? (
left = zdf0.zdf_svf(left);
right = stereo ? zdf1.zdf_svf(right) : left;
);
spl0 = dry.smooth() * spl0 + wet.smooth() * left;
spl1 = dry.smooth * spl1 + wet.smooth * right;