Skip to content

Commit a9d3d30

Browse files
committed
noise rejection
1 parent 45e1250 commit a9d3d30

File tree

3 files changed

+131
-6
lines changed

3 files changed

+131
-6
lines changed

dev/src/dsp-definitions/45-alchemist-prototype.ts

Lines changed: 99 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,112 @@ tune2 = waveform{24,-1,-1,-1,28,-1,-1,-1};
1010
tunePlayer(tune) = tuneGate,tuneFreq
1111
with {
1212
tuneNow = tune,int(os.phasor(8,0.2)) : rdtable;
13-
tuneGate = tuneNow > 0 : ba.sAndH(tuneNow != 0) : en.adsre(0.01,2.0,0.2,1.0);
13+
tuneGate = tuneNow > 0 : ba.sAndH(tuneNow != 0) : en.adsre(0.01,1.3,0.0,1.0);
1414
tuneFreq = tuneNow : ba.sAndH(tuneNow > 0);
1515
};
1616
synth(gate) = ba.midikey2hz : os.triangle : *(gate) : *(0.2);
17-
input1 = tunePlayer(tune1) : synth;
18-
input2 = tunePlayer(tune2) : synth;
17+
gtr_synth = tunePlayer(tune1) : synth;
18+
bass_synth = tunePlayer(tune2) : synth;
19+
20+
// mosfez-alchemist.dsp
21+
//
22+
// B
23+
// A C
24+
// D
25+
26+
import("stdfaust.lib");
27+
28+
// utils
29+
30+
lerp(a, b, x) = a + (b - a) * x;
31+
32+
constantPowerPan(p, x) = x*gainLeft, x*gainRight
33+
with {
34+
theta = ma.PI*p/2.;
35+
gainLeft = cos(theta)/sqrt(2.);
36+
gainRight = sin(theta)/sqrt(2.);
37+
};
38+
39+
reject_noise(slack, move_time, x) = return with {
40+
loop(prev_out, prev_timer, x) = loop_return with {
41+
trig = abs(prev_out - x) > slack;
42+
timer = ba.if(trig, 0, prev_timer + 1);
43+
out = ba.if(trig | timer < ma.SR * move_time, x, prev_out);
44+
loop_return = out,timer;
45+
};
46+
return = x : loop ~ (_,_) : (_,!);
47+
};
48+
49+
// consts
50+
51+
voice_count = 5;
52+
spread_count = 7;
53+
54+
max_delay = ma.SR * 5.0;
55+
56+
del_table = waveform{
57+
0.,0.,0.,0.,0.,
58+
0.,0.,0.,0.,0.,
59+
0.,1.,0.,0.,0.,
60+
0.,.5,1.,0.,0.,
61+
0.,.33,.66,1.,0.,
62+
0.,.25,.5,.75,1.,
63+
0.,.23,.384,.62,1.
64+
};
65+
66+
67+
vol_table = waveform{
68+
1.,0.,0.,0.,0.,
69+
1.,0.,0.,0.,0.,
70+
1.,1.,0.,0.,0.,
71+
1.,.9,.8,0.,0.,
72+
1.,.8,.7,.6,0.,
73+
1.,.9,.7,.5,.3,
74+
1.,.8,.7,.5,.3
75+
};
76+
77+
pan_table = waveform{
78+
.5,.5,.5,.5,.5,
79+
0.,.5,.5,.5,.5,
80+
0.,1.,.5,.5,.5,
81+
.5,0.,1.,.5,.5,
82+
0.,1.,.8,.2,.5,
83+
.2,.3,.5,.75,1.,
84+
0.,1.,.2,.7,.4
85+
};
86+
87+
// input
88+
89+
lag_param = hslider("lag[OWL:A]", 0.5, 0.0, 1.0, 0.001) : reject_noise(0.05, 1.0) : si.smoo;
90+
modspeed_param = hslider("modspeed[OWL:C]", 0.5, 0.0, 1.0, 0.001) : reject_noise(0.05, 1.0) : si.smoo;
91+
moddepth_param = hslider("moddepth[OWL:C]", 0.5, 0.0, 1.0, 0.001) : reject_noise(0.05, 1.0) : si.smoo;
92+
spread_param = hslider("spread[OWL:B]", 0, 0, spread_count - 1, 1) : int;
93+
width_button = checkbox("width[OWL:B1]");
1994
2095
// fx
96+
read_table(table,i) = table,(spread_param * voice_count) + i : rdtable;
97+
98+
del_value(i) = read_table(del_table, i);
99+
vol_value(i) = read_table(vol_table, i);
100+
pan_value(i) = read_table(pan_table, i);
101+
102+
lp(v) = fi.lowpass(1, lerp(4000., 20000., v * v));
103+
hp(v) = fi.highpass(1, lerp(1000., 20., v * v));
104+
105+
del(i) = de.delay(max_delay, del_value(i) * lag_param * lag_param * max_delay);
106+
vol(i) = *(vol_value(i)) : hp(vol_value(i)) : lp(vol_value(i));
107+
pan(i) = constantPowerPan(pan_value(i));
108+
trem(i) = *(1. - (os.osc(modspeed_param * modspeed_param * (10. - i)) * .5 + .5) * moddepth_param);
109+
110+
flip(a,b) = ba.if(width_button, b, a),ba.if(width_button, a, b);
111+
bass_pan = ba.if(spread_param == 1, 0, _),_;
21112
22-
channel1 = input1 <: _,_; // : _,de.fdelay(ma.SR, ma.SR * 0.59);
23-
channel2 = input2 <: _,_;
113+
voice(i) = _ : del(i) : vol(i) : trem(i) : pan(i) : flip : _,_;
114+
gtr = _ <: par(i, voice_count, voice(i)) :> _,_;
115+
bass = _ <: bass_pan : _,_;
24116
25-
process = channel1, channel2 :> _,_;
117+
amp = *(3.0);
118+
process = gtr_synth,bass_synth : gtr,bass :> amp,amp;
26119
`;
27120

28121
const dspDefinition: DspDefinition = {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { DspDefinition } from "../types";
2+
3+
const dsp = `
4+
import("stdfaust.lib");
5+
6+
noise_amount = 0.02;
7+
noisy_knob = hslider("knob", 0.0, 0.0, 1.0, 0.01) : +((no.noise - 0.5) * noise_amount) : hbargraph("input", 0.0, 1.0);
8+
9+
reject_noise(slack, move_time, x) = return with {
10+
loop(prev_out, prev_timer, x) = loop_return with {
11+
trig = abs(prev_out - x) > slack;
12+
timer = ba.if(trig, 0, prev_timer + 1);
13+
out = ba.if(trig | timer < ma.SR * move_time, x, prev_out);
14+
loop_return = out,timer;
15+
};
16+
return = x : loop ~ (_,_);
17+
};
18+
19+
process = noisy_knob : reject_noise(0.1, 1.0) : hbargraph("output", 0.0, 1.0),hbargraph("time", 0.0, 1000.0);
20+
`;
21+
22+
const dspDefinition: DspDefinition = {
23+
id: "noise-rejection",
24+
name: "Noise rejection",
25+
description: "Rejects noise from hslider reads",
26+
dsp,
27+
type: "live",
28+
};
29+
30+
export default dspDefinition;

dev/src/dsp-definitions/all.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import multibandFilter from "./42-multiband-filter";
4545
import c4BlopsLive from "./43-c4-blops-live";
4646
import c4Blops from "./44-c4-blops";
4747
import alchemistPrototype from "./45-alchemist-prototype";
48+
import noiseRejection from "./46-noise-rejection";
4849

4950
export const all: DspDefinition[] = [
5051
sineWave,
@@ -92,4 +93,5 @@ export const all: DspDefinition[] = [
9293
c4BlopsLive,
9394
c4Blops,
9495
alchemistPrototype,
96+
noiseRejection,
9597
];

0 commit comments

Comments
 (0)