/
waveshapping_ringmod_drum.scd
146 lines (109 loc) · 3.25 KB
/
waveshapping_ringmod_drum.scd
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
146
// =====================================================================
// SuperCollider Workspace
// =====================================================================
s.quit;
s.boot;
b = Buffer.alloc(s, 512, 1, {arg buf; buf.chebyMsg([0.4,0.8, 1, 0.7, 0.5, 0.3, 0.2, 0.1, 0.05, 0, 0.02])});//[1,0,1,1,0,1])});
b.plot;
(
x = play({
Shaper.ar(
b,
SinOsc.ar(300, 0, Line.kr(0,1,6)),
0.5
)
});
)
x.free;
b.free;
s.boot;
s.quit;
(
SynthDef("waveshaping_ringmod_drum", { arg freq=440, amp=0.9, gate;
var osc, ampenv, ampenvctl, tfuncenv, buf, tfuncstream, f1, f2, t, f1envctl;
b = Buffer.alloc(s,1024,1);
t = Signal.fill(512, { arg i; var j = i / 511.0;
1 + (0.841 * j) - (0.707 * (j**2)) - (0.595 * (j**3)) + (0.5 * (j**4)) +( 0.42 * (j**5)) - (0.354 * (j**6)) - (0.297 * (j**7)) + (0.25 * (j**8)) + (0.21*(j**9))});
//t.plot;
b.loadCollection(t.asWavetable);
b.plot;
f1 = Env.new([1, 0, 0], [0.04, 0.16]);
f2 = Env.new([0, 0.9, 1, 0.9, 0], [0.01, 0.01, 0.01, 0.17], [-1, -3, 3, -5]);
// f1.plot;
// f2.plot;
osc = amp * SinOsc.ar(freq, 0, EnvGen.kr(f2,gate)) * Shaper.ar(b, SinOsc.ar(0.7071*freq, 0, EnvGen.kr(f1, gate, doneAction: 2)));
Out.ar(0, osc)
}).load(s);
)
a = Synth("waveshaping_ringmod_drum", [\freq, 120, \amp, 0.9, \gate, 1]);
a.set(\gate, 1);
a.set(\gate, 0);
(
var w, f, d, values, server, id, isOn = false, msg;
var b1, b2, s;
values = IdentityDictionary.new;
server = Server.local;
f = { arg name, spec = \lin, guispec;
var height = 20, v, s, n;
guispec = guispec ? spec;
spec = spec.asSpec;
guispec = guispec.asSpec;
spec.class.postln;
v = GUI.staticText.new(w, Rect(0, 0, 72, height));
v.font = GUI.font.new("Helvetica", 12);
v.stringColor = Color.black;
v.align = \right;
s = GUI.slider.new(w, Rect(0, 0, 182, height));
s.resize = 2;
s.action = {
var val, guival, step;
val = spec.map(s.value);
values.put(name, val);
// server.sendMsg("/n_set", id, name, val);
guival = guispec.map(s.value);
step = pow(10, floor(min(0, guival.abs.log10 - 2)));
v.string = guival.round(step).asString ++ guispec.units;
};
s.value = spec.unmap(spec.default);
s.action.value;
n = GUI.staticText.new(w, Rect(0, 0, 72, height)); n.string = name;
n.stringColor = Color.black;
n.font = GUI.font.new("Helvetica", 12);
n.resize = 3;
w.view.decorator.nextLine;
};
w = GUI.window.new("FM", Rect(512, 64, 360, 130));
w.view.decorator = d = FlowLayout(w.view.bounds);
server.sendMsg("/d_load", "synthdefs/FM.scsyndef");
b2 = GUI.button.new(w, Rect(0,0, 80, 24));
b2.states = [ ["Play", Color.black, Color.green] ];
b2.action = { arg view;
var id = server.nextNodeID;
msg = ["/s_new", "FM", id, 0, 0];
values.keysValuesDo({ arg key, value;
msg = msg.addAll([key, value]);
});
msg.postln;
server.performList(\sendMsg, msg);
};
b2.enabled = server.serverRunning;
d.nextLine;
f.value(\dur,[0, 50, \lin]);
f.value(\fc, [20, 500, \lin]);
f.value(\fm, [0,500, \lin]);
f.value(\amp, \amp, \db);
f.value(\imax, [0,500,\lin]);
a = SimpleController(server);
f = { arg server;
b2.enabled = server.serverRunning;
if (server.serverRunning.not, { b2.value = 0 });
};
a.put(\serverRunning, f);
w.onClose = {
a.remove;
};
w.front;
)
////////////////////////////////////////////////////////////////////////
a = Synth("FM");
a.free;o