2 summary:: Bank of resonators
3 related:: Classes/DynKlank, Classes/Klang
4 categories:: UGens>Generators>Deterministic, UGens>Filters>Linear
9 Klank is a bank of fixed frequency resonators which can be used to
10 simulate the resonant modes of an object. Each mode is given a ring time,
11 which is the time for the mode to decay by 60 dB.
18 argument::specificationsArrayRef
19 A link::Classes/Ref:: to an link::Classes/Array:: of three Arrays:
22 ## frequencies: || An Array of filter frequencies.
23 ## amplitudes: || an Array of filter amplitudes, or nil. If nil, then amplitudes default to 1.0.
24 ## ring times: || an Array of 60 dB decay times for the filters.
26 All subarrays, if not nil, should have the same length.
29 The excitation input to the resonant filter bank.
32 A scale factor multiplied by all frequencies at initialization time.
35 An offset added to all frequencies at initialization time.
38 A scale factor multiplied by all ring times at initialization time.
41 The parameters in code::specificationsArrayRef:: can't be changed after it has been started.
42 For a modulatable but less efficient version, see link::Classes/DynKlank::.
48 { Klank.ar(`[[800, 1071, 1153, 1723], nil, [1, 1, 1, 1]], Impulse.ar(2, 0, 0.1)) }.play;
50 { Klank.ar(`[[800, 1071, 1353, 1723], nil, [1, 1, 1, 1]], Dust.ar(8, 0.1)) }.play;
52 { Klank.ar(`[[800, 1071, 1353, 1723], nil, [1, 1, 1, 1]], PinkNoise.ar(0.007)) }.play;
54 { Klank.ar(`[[200, 671, 1153, 1723], nil, [1, 1, 1, 1]], PinkNoise.ar([0.007,0.007])) }.play;
59 Array.rand(12, 800.0, 4000.0), // frequencies
60 nil, // amplitudes (default to 1.0)
61 Array.rand(12, 0.1, 2) // ring times
62 ], Decay.ar(Impulse.ar(4), 0.03, ClipNoise.ar(0.01)))
68 // a synth def that has 4 partials
71 SynthDef("help-Control", { arg out=0,i_freq;
72 var klank, n, harm, amp, ring;
75 harm = Control.names([\harm]).ir(Array.series(4,1,1).postln);
77 amp = Control.names([\amp]).ir(Array.fill(4,0.05));
79 ring = Control.names([\ring]).ir(Array.fill(4,1));
81 klank = Klank.ar(`[harm,amp,ring], {ClipNoise.ar(0.003)}.dup, i_freq);
87 // nothing special yet, just using the default set of harmonics.
88 a = Synth("help-Control",[\i_freq, 300]);
89 b = Synth("help-Control",[\i_freq, 400]);
90 c = Synth("help-Control",[\i_freq, 533.33]);
91 d = Synth("help-Control",[\i_freq, 711.11]);
98 // in order to set the harmonics amps and ring times at
99 // initialization time we need to use an OSC bundle.
102 ["/s_new", "help-Control", 2000, 1, 0, \i_freq, 500], // start note
103 ["/n_setn", 2000, "harm", 4, 1, 3, 5, 7] // set odd harmonics
107 s.sendMsg("/n_free", 2000);
111 ["/s_new", "help-Control", 2000, 1, 0, \i_freq, 500], // start note
112 // set geometric series harmonics
113 ["/n_setn", 2000, "harm", 4] ++ Array.geom(4,1,1.61)
117 s.sendMsg("/n_free", 2000);
120 // set harmonics, ring times and amplitudes
122 ["/s_new", "help-Control", 2000, 1, 0, \i_freq, 500], // start note
123 ["/n_setn", 2000, "harm", 4, 1, 3, 5, 7], // set odd harmonics
124 ["/n_setn", 2000, "ring", 4] ++ Array.fill(4,0.1), // set shorter ring time
125 ["/n_setn", 2000, "amp", 4] ++ Array.fill(4,0.2) // set louder amps
129 s.sendMsg(\n_trace, 2000);
130 s.sendMsg("/n_free", 2000);
133 // same effect as above, but packed into one n_setn command
135 ["/s_new", "help-Control", 2000, 1, 0, \i_freq, 500], // start note
136 ["/n_setn", 2000, "harm", 4, 1, 3, 5, 7,
137 "ring", 4] ++ Array.fill(4,0.1)
138 ++ ["amp", 4] ++ Array.fill(4,0.2)
142 s.sendMsg("/n_free", 2000);
147 //////////////////////////////////////////////////////////////////////
151 SynthDef("help-KlankOverlapTexture",
152 {|out = 0, freqs = #[0,0,0,0,0,0,0,0,0,0,0,0], rings = #[0,0,0,0,0,0,0,0,0,0,0,0], atk = 5, sus = 8, rel = 5, pan = 0|
153 var e = EnvGen.kr(Env.linen(atk, sus, rel, 1, 4), doneAction:2);
154 var i = Decay.ar(Impulse.ar(Rand(0.8, 2.2)), 0.03, ClipNoise.ar(0.01));
156 `[freqs, nil, rings], // specs
159 Out.ar(out, Pan2.ar(z*e, pan));
163 var sustain = 8, transition = 3, overlap = 4;
164 var period = transition*2+sustain/overlap;
165 0.5.wait; //wait for the synthdef to be sent to the server
167 Synth("help-KlankOverlapTexture", [
173 \freqs, {200.0.rrand(4000)}.dup(12),
174 \rings, {0.1.rrand(2)}.dup(12)
182 r.stop; //stop spawning new synths
186 //-- frequency and decay scaling
188 SynthDef("help-KlankScaling", {|out = 0, freq = 0, rings = #[0,0,0,0,0,0,0,0,0,0,0,0], pan = 0|
189 var e = EnvGen.kr(Env(#[1, 1, 0], #[0.4, 0.01]), doneAction:2);
190 var i = Decay.ar(Impulse.ar(0), 0.03, ClipNoise.ar(0.01));
192 `[(1..12), nil, rings], // specs (partials, amplitudes, ringtimes)
194 freq, // scale to this frequency
195 0, // frequency offset
196 MouseX.kr(0.2, 3) // scale decay times
198 Out.ar(out, Pan2.ar(z*e, pan));
202 var sustain = 8, transition = 3;
203 var mode = #[0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19, 21, 23, 24];
204 0.5.wait; //wait for the synthdef to be sent to the server
206 Synth("help-KlankScaling", [
207 \freq, (72 + (mode @@ i)).midicps
208 ]).setn(\rings, {0.1.rrand(2)}.dup(12));
218 //-- overlap texture 2
220 SynthDef("help-KlankOverlapTexture2",
221 {|out = 0, freqs = #[0,0,0,0,0,0,0,0,0,0,0,0], rings = #[0,0,0,0,0,0,0,0,0,0,0,0], atk = 5, sus = 8, rel = 5, pan = 0|
222 var e = EnvGen.kr(Env.linen(atk, sus, rel, 1, 4), doneAction:2);
223 var i = BrownNoise.ar(0.0012);
225 `[freqs, nil, rings], // specs
228 Out.ar(out, Pan2.ar(z*e, pan));
232 var sustain = 6, transition = 4, overlap = 5;
233 var period = transition*2+sustain/overlap;
234 0.5.wait; //wait for the synthdef to be sent to the server
236 Synth("help-KlankOverlapTexture2", [
242 \freqs, {6000.0.linrand+80}.dup(12),
243 \rings, {0.1.rrand(3)}.dup(12)
254 //-- overlap texture 3
256 SynthDef("help-KlankOverlapTexture3",
257 {|out = 0, freqs = #[0,0,0,0,0,0,0,0,0,0,0,0], rings = #[0,0,0,0,0,0,0,0,0,0,0,0], pan = 0|
258 var e = EnvGen.kr(Env(#[1, 1, 0], #[18, 3]), doneAction:2);
259 var i = Decay.ar(Impulse.ar(Rand(0.2, 0.6)), 0.8, ClipNoise.ar(0.001));
261 `[freqs, 2, rings], // specs
264 Out.ar(out, Pan2.ar(z*e, pan));
268 0.5.wait; //wait for the synthdef to be sent to the server
270 Synth("help-KlankOverlapTexture3", [
273 \freqs, {12000.0.linrand+80}.dup(12),
274 \rings, {3.rrand(10)}.dup(12)