//Spawn 98/11/24 Spawn.ar(newEventFunc, numChannels, nextTime, maxRepeats, mul, add) ////////////////////////////////////////////////////////////////////////// ( // random sine waves var n, env; n = 50; // number of simultaneous events env = Env.linen(2, 5, 2); { Spawn.ar({ FSinOsc.ar(3000.0.rand, EnvGen.kr(env, 1, 0, 0.02)) }, 2, 9/n) }.scope ) ( // random sine waves var n, env; n = 12; // number of simultaneous events env = Env.linen(2, 5, 2); play({ Spawn.ar({ Pan2.ar( FSinOsc.ar(2000.0.rand, EnvGen.kr(env, 1, 0, 0.02)), 1.0.rand2) }, 2, 9/n) })) ////////////////////////////////////////////////////////////////////////// ( // random pulsations var n, env; n = 8; // number of simultaneous events env = Env.linen(2, 5, 2); play({ Spawn.ar({ Pan2.ar( EnvGen.ar(env, FSinOsc.ar(2000.0.rand).amclip(SinOsc.ar(8+80.0.rand)), 0, 0.02), SinOsc.ar(0.3+0.5.rand, 2pi.rand, 0.7)) }, 2, 9/n) })) ////////////////////////////////////////////////////////////////////////// // narrow band filtered Crackle noise var e; e = Env.linen(2, 5, 2); play({ Spawn.ar({ var rf, rf2; rf = 2000.0.rand + 80; rf2 = rf + (0.2.rand2 * rf); Pan2.ar(EnvGen.ar(e, Resonz.ar(Crackle.ar(1.97 + 0.03.rand,0.15), XLine.kr(rf,rf2,9), 0.2) ), 1.0.rand2) }, 2, 1) })) ////////////////////////////////////////////////////////////////////////// ( // resonant dust e = Env.linen(2, 5, 2); play({ Spawn.ar({ var rf, rf2; rf = 2000.0.rand + 80; rf2 = rf + (0.5.rand2 * rf); Pan2.ar(EnvGen.ar(e, Resonz.ar(Dust.ar(50 + 800.rand, 0.3), XLine.kr(rf,rf2,9), 0.1) ), 1.0.rand2) }, 2, 1) })) ////////////////////////////////////////////////////////////////////////// Examples ( // Spawn example 1 var env; env = Env.linen(2,5,2); // 9 second trapezoid envelope specification Synth.play({ Spawn.ar({ // newEventFunc Pan2.ar( EnvGen.ar( env, Resonz.ar(WhiteNoise.ar(0.05), 2000.0.rand + 80, 0.05) ), 1.0.rand2 ) }, 2, // two channels 1) // new event every second })) ( // Spawn example 2 var env; env = Env.linen(2,5,2); // 9 second trapezoid envelope specification Synth.play({ Spawn.ar({ Pan2.ar( FSinOsc.ar(2000.0.rand, EnvGen.kr(env)), 1.0.rand2) }, 2, 0.5, nil, 0.02) })) ( // Spawn example 3 var env; env = Env.linen(2,5,2); // 9 second trapezoid envelope specification Synth.play({ Spawn.ar({ Pan2.ar( EnvGen.ar(env, TwoPole.ar(Dust.ar(10, 0.3), 2000.0.rand+100, 0.9995),0,0.02 ), 1.0.rand2) }, 2, 1) })) ( // Spawn example 4 // This example illustrates both nested spawning and spawning a set of // simultaneous voices Synth.play({ // spawn a new voice every second: Spawn.ar({ if ( 1.0.rand < 0.2, { // 20 percent chance of nil // returning nil, meaning rest this time. },{ // else return the following : // spawns four 'voices' in parallel: Spawn.ar({ FSinOsc.ar( // each voice is one sine oscillator 400 + 1000.rand, // random frequency Line.kr( // the simplest of envelopes 0.02, // begin at 0.02 0, // ramp to zero 1.0.rand // in some random amount of time ) ) }, 1, 0, 4) // 1 channel, nextTime is 0 seconds, stop after 4 events }) }, 1, 0.3) // 1 channel, nextTime in 0.3 second })) ( // Spawn example 5 // use channel offset to select either right or left channel only var env; env = Env.new(#[0,1,0],#[0.01, 0.5]); Synth.play({ Spawn.ar({ arg spawn, i, synth; synth.channelOffset = 2.rand; // channel zero or one at random EnvGen.ar(env, // phase modulation oscillator pair in EnvGen's mul input PMOsc.ar(3000.0.rand, 3000.0.rand, 3.0.rand), 0, 0.04 ) // envelope }, 2, // two channels 0.25 // repeat every 1/4 second ) })) ( // Spawn example 6 // This example illustrates spawning synths with different block sizes // and on different channels Synth.plot({ Spawn.ar({ arg spawn, i, synth; // arguments are the spawner and the event count synth.channelOffset = i; // put each synth on a separate channel synth.blockSize = (4**i); // bigger block sizes each time (1,4,16,64) K2A.ar(WhiteNoise.kr) // K2A converts control rate to audio rate }, 4, 0, 4) // 4 channels, simultaneous, stop spawning after 4 events })) ( // Spawn example 7 // demonstrates changing the Spawn object's nextTime variable Synth.play({ var duration = 0.01; // starting duration value Spawn.ar({ arg spawn, i, synth; // make each duration 5% longer than previous : spawn.nextTime = duration = duration * 1.05; FSinOsc.ar( // each voice is one sine oscillator 400 + 1000.rand, // random frequency Line.kr( // the simplest of envelopes 0.02, // begin at 0.02 0, // ramp to zero 0.2 // in 0.2 seconds ) ) }, 1) // 1 channel })) ( // Spawn example 8 // This time speed up via the nextTime variable // except stop when the time gets smaller than a threshold value Synth.play({ var duration = 1.0; Spawn.ar({ arg spawn, i, synth; // make each duration 5% shorter than previous : spawn.nextTime = duration = duration * 0.95; if (duration < 0.01, { // less than threshold value spawn.stop; }); FSinOsc.ar( // each voice is one sine oscillator 600 + 1000.rand, // random frequency Line.kr( // the simplest of envelopes 0.02, // begin at 0.02 0, // ramp to zero 0.2 // in 0.2 seconds ) ) }, 1) // 1 channel })) ( // Spawn example 9 // demonstration of using a controller in an outer Synth to // control a parameter in sub-Synths. var env; env = Env.new(#[0, 0.04, 0],#[1, 1]); Synth.play({ // the outer LFO goes from 200 to 1800 in 5 seconds (0.2 Hz) // all spawned voices share a single copy of the outer LFO f = LFSaw.kr(0.2, 800, 1000); Spawn.ar( // spawn Synths { g = LFPulse.kr(12.0.rand, 0.3, 400.rand, 800.rand); // inner LFO SinOsc.ar( f + g, // add the outer and inner LFOs together 0, EnvGen.kr(env) // amplitude envelope ) }, 1, // one channel 0.3, // nextTime every 0.3 seconds nil // repeat forever ) })) ( // Spawn example 10 // demonstration of polling a controller in an outer Synth to // use as a scalar value in sub-Synths. var env; env = Env.new(#[0,0.04,0.04,0],#[0.1,0.4,0.1]); Synth.play({ // the outer LFO goes from 200 to 1800 in 5 seconds (0.2 Hz) f = LFSaw.kr(0.53, 800, 1000); Spawn.ar( // spawn Synths { SinOsc.ar( f.poll, // poll the value of the outer LFO as the frequency 0, // phase EnvGen.kr(env) // amplitude envelope ) }, 1, // one channel 0.2, // nextTime every 0.2 seconds nil // repeat forever ) }))