s = Server.default; s.boot; /* Small piece with drum set and pentatonic synth sound, filled with similar pad by Alexander Schremmer, with rough structure from spacelab.scd Every instrument of the drum set plays a rhythm that is chosen randomly. The particular rhythm is changed every 2 or 3 bars, depending on the instrument. The notes are chosen randomly as well. This file consists of 3 sections: the synths, the patterns and the scheduler call */ // SynthDefs // ( // rather flat basedrum, no high resonance // i.e. you need very powerful speakers SynthDef(\basedrum, { | out=0, amp=1.0 | var osc, env; // 50 Hz triangular signal with low pass filter at 140 Hz osc = LPF.ar(LFTri.ar(50), 140); // short percussive envelope env = EnvGen.kr(Env.perc(0, 0.13), doneAction: 2); Out.ar(out, Pan2.ar(osc, 0, env) * amp * 2); }).memStore; // Snare drum that consists of two parts: // - white noise // - 300 Hz sinoid sound // which are both mixed and pushed through a 18 KHz low pass filter. // The latter sinoid sound ensures the knock/resonance sound // of a real snare drum. SynthDef(\snaredrum, { | out=0, amp=1.0 | var osc1, osc2, env; osc1 = WhiteNoise.ar * 1.2; osc2 = FSinOsc.ar(300); env = EnvGen.kr(Env.perc(0, 0.08), doneAction: 2); Out.ar(out, amp * Pan2.ar(LPF.ar(Mix([osc1, osc2]) * 0.6, 18000), 0, env)); }).memStore; // Hi-hat which is simply generated by percussion formed // high pass filtered whitenoise SynthDef(\hihat, { | out=0, amp=1.0 | var osc1, env; osc1 = WhiteNoise.ar; env = EnvGen.kr(Env.perc(0, 0.2), doneAction: 2); Out.ar(out, amp * Pan2.ar(HPF.ar(osc1, 400), 0, env)); }).memStore; // Primary instrument used for the crotchets SynthDef(\soundone, { | out=0, amp=2, freq=440 | var osc, saw, env; // simple envelope that peaks after 50 ms and remains active for 500 ms env = EnvGen.ar(Env.new([0, 1, 0.5], [0.05, 0.5]), doneAction:2); // saw tooth saw = Saw.ar(freq); // low pass filter at 5th upper partial osc = RLPF.ar(saw, freq * 5, 0.1); Out.ar(out, Pan2.ar(osc * amp * env)); }).memStore; // Synth padding SynthDef(\poly, { | out=0 amp=1 freq=440 | var env, env_freq, osc, flt; // Primary envelope with long attack time (2 seconds) env_freq = EnvGen.kr(Env.asr(2, 1, 0.2), levelScale: 14000, doneAction:2); // Secondary envelope which seems necessary in order to mute the instrument after 4 s env = EnvGen.ar(Env.new([1, 1], [4]), doneAction: 2); // Pulse wave with Sine-like cubic resonator which modulates the pulse width osc = Pulse.ar(freq * [1, 1.007], LFCub.kr(2, 0, 0.2, 0.7)); // Low pass filter with q=1.11 flt = RLPF.ar(osc, env_freq, 0.9) * amp * env; Out.ar(out, flt); }).memStore; ) // Patterns // ( // Pattern that uses the base drum and plays a syncopated rhythm for 2 bars, // alternating with a straight forward one Pdef(\Pbasedrum_syncop, Pbind( \instrument, \basedrum, [\amp, \dur], Pwrand([ Pseq([[1, 1], [0, 0.5], [1, 0.5], [1, 1], [0, 0.5], [1, 0.5]], 2), Pseq([[1, 1], [1, 1], [1, 1], [1, 1]], 2), ], [0.5, 0.5], inf) )); // Snare drum with two alternating patterns Pdef(\Psnaredrum, Pbind( \instrument, \snaredrum, \dur, 1, \amp, Pwrand([ Pseq([0, 1, 0, 1], 3), Pseq([1, 0, 1, 0], 3), ], [0.5, 0.5], inf) * 0.2, // less exact timings, sounds more natural \timingOffset, Prand([0.001, 0.0005, 0], inf) )); // hi-hat pattern used in the intro Pdef(\Phihat_intro, Pbind( \instrument, \hihat, \dur, 1, \amp, Pseq([1, 0.5, 0.25, 0.1 ], 2), // less exact timings, sounds more natural \timingOffset, Prand([0.001, 0.0005, 0], inf) )); // hi-hat with three different patterns Pdef(\Phihat, Pbind( \instrument, \hihat, [\amp, \dur], Pwrand([ Pseq([[0.1, 1], [0.3, 1], [0.7, 1], [0.5, 1]], 1), Pseq([[1, 1], [1, 1], [1, 1], [1, 1]], 1), Pseq([[0, 0.5], [1, 0.5], [0, 0.5], [1, 0.5], [0, 0.5], [1, 0.5], [0, 0.5], [1, 0.5]], 1), ], [1/3, 1/3, 1/3], inf) * [0.2, 1], // less exact timings, sounds more natural \timingOffset, Prand([0.001, 0.0005, 0], inf) )); // Primary sound, with pentatonic scale, notes are random Pdef(\Psoundone, Pbind( \instrument, \soundone, \dur, 1, \timingOffset, 0.5, \amp, 0.15, \midinote, Prand([1, 3, 5, 8, 10] + 60, inf) // pentatonik )); // Synth pad with same scale Pdef(\Ppad, Pbind( \instrument, \poly, \dur, 8, \amp, 0.02, \midinote, Prand([1, 3, 5, 8, 10] + 60, inf) // pentatonik )); // Song sections // // intro just plays hi-hat Pdef(\intro, Ppar([Pdef(\Phihat_intro)])); // main section plays all instruments parallely Pdef(\main, Ppar([Pdef(\Pbasedrum_syncop), Pdef(\Psnaredrum), Pdef(\Phihat), Pdef(\Psoundone), Pdef(\Ppad)])); ) // Scheduler // ( ~tc = TempoClock.default; ~tc.tempo = 120 / 60; // 120 BPM SystemClock.sched(0, { Psym( Pseq([ \intro, \main ])).play; }); ) /* XXX debug Synth(\poly).play; s.scope; PdefAllGui.new; */