Klank bank of resonators
Klank.ar(specificationsArrayRef, input, freqscale, freqoffset, decayscale)
Klank is a bank of fixed frequency resonators which can be used to simulate the resonant modes of an object. Each mode is given a ring time, which is the time for the mode to decay by 60 dB.
specificationsArrayRef - a Ref to an Array of three Arrays :
frequencies - an Array of filter frequencies.
amplitudes - an Array of filter amplitudes, or nil. If nil, then amplitudes default to 1.0
ring times - an Array of 60 dB decay times for the filters.
All subarrays, if not nil, should have the same length.
input - the excitation input to the resonant filter bank.
freqscale - a scale factor multiplied by all frequencies at initialization time.
freqoffset - an offset added to all frequencies at initialization time.
decayscale - a scale factor multiplied by all ring times at initialization time.
{ Klank.ar(`[[800, 1071, 1153, 1723], nil, [1, 1, 1, 1]], Impulse.ar(2, 0, 0.1)) }.play;
{ Klank.ar(`[[800, 1071, 1353, 1723], nil, [1, 1, 1, 1]], Dust.ar(8, 0.1)) }.play;
{ Klank.ar(`[[800, 1071, 1353, 1723], nil, [1, 1, 1, 1]], PinkNoise.ar(0.007)) }.play;
{ Klank.ar(`[[200, 671, 1153, 1723], nil, [1, 1, 1, 1]], PinkNoise.ar([0.007,0.007])) }.play;
(
play({
Klank.ar(`[
Array.rand(12, 800.0, 4000.0), // frequencies
nil, // amplitudes (default to 1.0)
Array.rand(12, 0.1, 2) // ring times
], Decay.ar(Impulse.ar(4), 0.03, ClipNoise.ar(0.01)))
})
)
// a synth def that has 4 partials
(
s = Server.local;
SynthDef("help-Control", { arg out=0,i_freq;
var klank, n, harm, amp, ring;
n = 9;
// harmonics
harm = Control.names([\harm]).ir(Array.series(4,1,1).postln);
// amplitudes
amp = Control.names([\amp]).ir(Array.fill(4,0.05));
// ring times
ring = Control.names([\ring]).ir(Array.fill(4,1));
klank = Klank.ar(`[harm,amp,ring], {ClipNoise.ar(0.003)}.dup, i_freq);
Out.ar(out, klank);
}).send(s);
)
// nothing special yet, just using the default set of harmonics.
a = Synth("help-Control",[\i_freq, 300]);
b = Synth("help-Control",[\i_freq, 400]);
c = Synth("help-Control",[\i_freq, 533.33]);
d = Synth("help-Control",[\i_freq, 711.11]);
a.free;
b.free;
c.free;
d.free;
// in order to set the harmonics amps and ring times at
// initialization time we need to use an OSC bundle.
(
s.sendBundle(nil,
["/s_new", "help-Control", 2000, 1, 0, \i_freq, 500], // start note
["/n_setn", 2000, "harm", 4, 1, 3, 5, 7] // set odd harmonics
);
)
s.sendMsg("/n_free", 2000);
(
s.sendBundle(nil,
["/s_new", "help-Control", 2000, 1, 0, \i_freq, 500], // start note
// set geometric series harmonics
["/n_setn", 2000, "harm", 4] ++ Array.geom(4,1,1.61)
);
)
s.sendMsg("/n_free", 2000);
(
// set harmonics, ring times and amplitudes
s.sendBundle(nil,
["/s_new", "help-Control", 2000, 1, 0, \i_freq, 500], // start note
["/n_setn", 2000, "harm", 4, 1, 3, 5, 7], // set odd harmonics
["/n_setn", 2000, "ring", 4] ++ Array.fill(4,0.1), // set shorter ring time
["/n_setn", 2000, "amp", 4] ++ Array.fill(4,0.2) // set louder amps
);
)
s.sendMsg(\n_trace, 2000)
(
// same effect as above, but packed into one n_setn command
s.sendBundle(nil,
["/s_new", "help-Control", 2000, 1, 0, \i_freq, 500], // start note
["/n_setn", 2000, "harm", 4, 1, 3, 5, 7,
"ring", 4] ++ Array.fill(4,0.1)
++ ["amp", 4] ++ Array.fill(4,0.2)
);
)
//(
//play({
// OverlapTexture.ar({
// Pan2.ar(
// Klank.ar(`[
// Array.rand(12, 200.0, 4000.0), // frequencies
// nil, // amplitudes (default to 1.0)
// Array.rand(12, 0.1, 2) // ring times
// ], Decay.ar(Impulse.ar(0.8+1.4.rand), 0.03, ClipNoise.ar(0.01))),
// 1.0.rand2
// )
// }, 8, 3, 4, 2)
//}))
//
//
//(
//// frequency and decay scaling
//var env, specs, mode;
//env = Env.new([1,1,0],[0.4,0.01]); // cutoff envelope
//specs = `[
// Array.series(12, 1, 1), // partials
// nil, // amplitudes (default to 1.0)
// Array.rand(12, 0.1, 2) // ring times
// ];
//mode = #[0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19, 21, 23, 24];
//play({
// Spawn.ar({ arg spawn, i;
// Pan2.ar(
// Klank.ar(specs,
// Decay.ar(Impulse.ar(0), 0.03, ClipNoise.ar(0.01)),
// (72 + (mode @@ i)).midicps, // scale to this frequency
// 0,
// MouseX.kr(0.2, 3), // scale decay times
// EnvGen.kr(env)
// ),
// 1.0.rand2
// )
// }, 2, 0.2)
//}))
//
//
//(
//play({
// OverlapTexture.ar({
// Pan2.ar(
// Klank.ar(`[
// Array.linrand(12, 80.0, 6000.0), // frequencies
// nil, // amplitudes (default to 1.0)
// Array.rand(12, 0.1, 3) // ring times
// ], BrownNoise.ar(0.0012)),
// 1.0.rand2
// )
// }, 6, 4, 5, 2)
//}))
//
//
//(
//var e;
//e = Env.new([1,1,0],[18, 3]);
//play({
// Spawn.ar({
// Pan2.ar(
// EnvGen.kr(e) *
// Klank.ar(`[
// Array.linrand(12, 80.0, 12000.0), // frequencies
// nil, // amplitudes (default to 1.0)
// Array.rand(12, 3, 10) // ring times
// ], Decay.ar(Impulse.ar(0.2+0.4.rand), 0.8, ClipNoise.ar(0.001))),
// 1.0.rand2
// )
// }, 2, 3)
//}))
//