1 2class:: Klank 3summary:: Bank of resonators 4related:: Classes/DynKlank, Classes/Klang 5categories:: UGens>Generators>Deterministic, UGens>Filters>Linear 6 7 8Description:: 9 10Klank is a bank of fixed frequency resonators which can be used to 11simulate the resonant modes of an object. Each mode is given a ring time, 12which is the time for the mode to decay by 60 dB. 13Note::for dynamic changes of parameters refer to link::Classes/DynKlank:: :: 14 15Note:: 16The amplitude of the resulting signal depends on the server's sample rate. See link::Classes/Ringz#Interaction with sample rate#Ringz: Interaction with sample rate:: for details. 17:: 18 19Klank is a bank of Ringz filters. link::Classes/Formlet:: is equivalent to code::Ringz.ar(... decay...) - Ring.ar(... attack...)::. Therefore, a more efficient way to make a bank of fixed-parameter Formlet filters is code::Klank(`decaySpecs, ...) - Klank.ar(`attackSpecs, ...):: or code::Klank.ar(`specs, ..., decayscale: decay) - Klank.ar(`specs, ..., decayscale: attack)::. 20 21classmethods:: 22 23method::ar 24 25argument::specificationsArrayRef 26A link::Classes/Ref:: to an link::Classes/Array:: of three Arrays: 27 28definitionlist:: 29## frequencies: || An Array of filter frequencies. 30## amplitudes: || an Array of filter amplitudes, or nil. If nil, then amplitudes default to 1.0. 31## ring times: || an Array of 60 dB decay times in seconds for the filters. 32:: 33All subarrays, if not nil, should have the same length. 34 35argument::input 36The excitation input to the resonant filter bank. 37 38argument::freqscale 39A scale factor multiplied by all frequencies at initialization time. 40 41argument::freqoffset 42An offset added to all frequencies at initialization time. 43 44argument::decayscale 45A scale factor multiplied by all ring times at initialization time. 46 47discussion:: 48The parameters in code::specificationsArrayRef:: can't be changed after it has been started. 49For a modulatable but less efficient version, see link::Classes/DynKlank::. 50 51 52Examples:: 53 54Four resonators each at maximum amplitude of 1.0 and ring times of 1 second, different exciters and no scaling: 55Note:: Watch the ` before the opening bracket of the parameter array! Also see link::Guides/Multichannel-Expansion:::: 56code:: 57{ Klank.ar(`[[800, 1071, 1153, 1723], nil, [1, 1, 1, 1]], Impulse.ar(2, 0, 0.1)) }.play; 58 59{ Klank.ar(`[[800, 1071, 1353, 1723], nil, [1, 1, 1, 1]], Dust.ar(8, 0.1)) }.play; 60 61{ Klank.ar(`[[800, 1071, 1353, 1723], nil, [1, 1, 1, 1]], PinkNoise.ar(0.007)) }.play; 62 63{ Klank.ar(`[[200, 671, 1153, 1723], nil, [1, 1, 1, 1]], PinkNoise.ar([0.007, 0.007])) }.play; 64 65:: 66 67Three resonators at maximum amplitude of 1.0, random frequency and ring times. 68Excited by two pulses at 2 and 2.5 Hz: 69code:: 70( 71play({ 72 Klank.ar(`[ 73 Array.rand(12, 800.0, 4000.0), // frequencies 74 nil, // amplitudes (default to 1.0) 75 Array.rand(12, 0.1, 2) // ring times 76 ], Decay.ar(Impulse.ar(4), 0.03, ClipNoise.ar(0.01))) 77}) 78) 79:: 80 81link::Guides/Multichannel-Expansion:: via an array of specs 82(note the ` before the opening bracket of the parameter array!): 83code:: 84( 85{ 86Klank.ar([ // the multichannel-expansion 87 `[[500, 1078, 1201.5, 1723], nil, [1, 1, 0.5, 0.3]], // left channel 88 `[[700, 1071, 1053, 1723], nil, [1, 1, 1, 1]] // right channel 89 ], Impulse.ar([1.5, 1.875], 0, 0.1)) 90}.play 91); 92 93// expanding specs within the parameter array 94{ Klank.ar(`[[[800, 6000], 1071, [1153, 8000], 1723], nil, [1, 1, 1, 1]], Impulse.ar([2, 3], 0, 0.1)) }.play; 95 96:: 97 98A SynthDef that generates 4 partials used in different configurations: 99code:: 100( 101SynthDef(\help_Klank, { arg out=0, i_freq; 102 var klank, n, harm, amp, ring; 103 104 // harmonics 105 harm = \harm.ir(Array.series(4, 1, 1).postln); 106 // amplitudes 107 amp = \amp.ir(Array.fill(4, 0.05)); 108 // ring times 109 ring = \ring.ir(Array.fill(4, 1)); 110 111 klank = Klank.ar(`[harm, amp, ring], {ClipNoise.ar(0.003)}.dup, i_freq); 112 113 Out.ar(out, klank); 114}).add; 115) 116 117// nothing special yet, just using the default set of harmonics. 118a = Synth(\help_Klank, [\i_freq, 300]); 119b = Synth(\help_Klank, [\i_freq, 400]); 120c = Synth(\help_Klank, [\i_freq, 533.33]); 121d = Synth(\help_Klank, [\i_freq, 711.11]); 122 123a.free; 124b.free; 125c.free; 126d.free; 127 128a = Synth(\help_Klank, [\i_freq, 500, \harm, [4, 1, 3, 5, 7]]); 129a.free; 130 131// set geometric series harmonics 132a = Synth(\help_Klank, [\i_freq, 500, \harm,Array.geom(4, 1, 1.61)]); 133a.free; 134 135// set harmonics, ring times and amplitudes 136( 137a = Synth(\help_Klank, [ 138 \i_freq, 500, 139 \harm, [4, 1, 3, 5, 7], 140 \ring, Array.fill(4, 0.1), // set shorter ring time 141 \amp, Array.fill(4, 0.2) // set louder amps 142]) 143); 144 145:: 146 147Advanced examples: 148code:: 149 150// -- overlap texture 151( 152SynthDef("help-KlankOverlapTexture", 153{|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| 154 var e = EnvGen.kr(Env.linen(atk, sus, rel, 1, 4), doneAction: Done.freeSelf); 155 var i = Decay.ar(Impulse.ar(Rand(0.8, 2.2)), 0.03, ClipNoise.ar(0.01)); 156 var z = Klank.ar( 157 `[freqs, nil, rings], // specs 158 i // input 159 ); 160 Out.ar(out, Pan2.ar(z*e, pan)); 161}).add; 162 163r = Routine{ 164 var sustain = 8, transition = 3, overlap = 4; 165 var period = transition * 2 + sustain / overlap; 166 0.5.wait; // wait for the synthdef to be sent to the server 167 inf.do{ 168 Synth("help-KlankOverlapTexture", [ 169 \atk, transition, 170 \sus, sustain, 171 \rel, transition, 172 \pan, 1.0.rand2, 173 \freqs, {200.0.rrand(4000)}.dup(12), 174 \rings, {0.1.rrand(2)}.dup(12) 175 ]); 176 period.wait; 177 } 178}; 179r.play; 180) 181 182r.stop; // stop spawning new synths 183 184 185 186// -- frequency and decay scaling 187( 188SynthDef("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: Done.freeSelf); 190 var i = Decay.ar(Impulse.ar(0), 0.03, ClipNoise.ar(0.01)); 191 var z = Klank.ar( 192 `[(1..12), nil, rings], // specs (partials, amplitudes, ringtimes) 193 i, // input 194 freq, // scale to this frequency 195 0, // frequency offset 196 MouseX.kr(0.2, 3) // scale decay times 197 ); 198 Out.ar(out, Pan2.ar(z*e, pan)); 199}).add; 200 201r = Routine{ 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 205 inf.do{|i| 206 Synth("help-KlankScaling", [ 207 \freq, (72 + (mode @@ i)).midicps, 208 \rings, {0.1.rrand(2)}.dup(12) 209 ]); 210 0.2.wait; 211 } 212}; 213r.play; 214) 215 216r.stop; 217 218 219// -- overlap texture 2 220( 221SynthDef("help-KlankOverlapTexture2", 222{|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| 223 var e = EnvGen.kr(Env.linen(atk, sus, rel, 1, 4), doneAction: Done.freeSelf); 224 var i = BrownNoise.ar(0.0012); 225 var z = Klank.ar( 226 `[freqs, nil, rings], // specs 227 i // input 228 ); 229 Out.ar(out, Pan2.ar(z*e, pan)); 230}).add; 231 232r = Routine{ 233 var sustain = 6, transition = 4, overlap = 5; 234 var period = transition*2+sustain/overlap; 235 0.5.wait; // wait for the synthdef to be sent to the server 236 inf.do { 237 Synth("help-KlankOverlapTexture2", [ 238 \atk, transition, 239 \sus, sustain, 240 \rel, transition, 241 \pan, 1.0.rand2, 242 \freqs, {6000.0.linrand+80}.dup(12), 243 \rings, {0.1.rrand(3)}.dup(12) 244 ]); 245 period.wait; 246 } 247}; 248r.play; 249) 250 251r.stop; 252 253 254// -- overlap texture 3 255( 256SynthDef("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: Done.freeSelf); 259 var i = Decay.ar(Impulse.ar(Rand(0.2, 0.6)), 0.8, ClipNoise.ar(0.001)); 260 var z = Klank.ar( 261 `[freqs, 2, rings], // specs 262 i // input 263 ); 264 Out.ar(out, Pan2.ar(z*e, pan)); 265}).add; 266 267r = Routine{ 268 0.5.wait; // wait for the synthdef to be sent to the server 269 inf.do { 270 Synth("help-KlankOverlapTexture3", [ 271 \pan, 1.0.rand2, 272 \freqs, {12000.0.linrand+80}.dup(12), 273 \rings, {3.rrand(10)}.dup(12) 274 ]); 275 3.wait; 276 } 277}; 278r.play; 279) 280 281r.stop; 282:: 283 284 285 286