«A simple drum machine» by coreyker

on 17 Oct'14 11:13 in drumssequence

A simple drum machine, using synthetic (analog type) drum sounds. No SynthDef's were used, although this would be a good idea. The various "players" can be modified and re-evaluated while the Routine is running....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Server.default = s = Server.internal;
s.boot;

/* ----------------------
   Synthetic bass drum
   ---------------------- */


~bass = {
	arg amp=0.5;
	{
		var amp_env, phase_env, phase, freq, dur;

		freq = 50.rand + 40;
		dur = 0.25;

		amp_env   = EnvGen.ar(Env.perc(1e-6,dur), doneAction:2);
		phase_env = EnvGen.ar(Env.perc(1e-6,0.125));

		phase = SinOsc.ar(20,0,pi) * phase_env;
		SinOsc.ar([freq,1.01*freq],phase) * amp_env * amp;
	}
}

~bass.value.play;



/* ----------------------
   Synthetic snare
   ---------------------- */


~snare = {
	arg amp=0.5;
	{
		var amp_env, cut_freq, dur;

		cut_freq = 3000;
		dur = [0.0625, 0.125, 0.25].choose;

		amp_env = EnvGen.ar(Env.perc(1e-6, dur), doneAction:2);
		LPF.ar( {WhiteNoise.ar(WhiteNoise.ar)}.dup * amp_env, cut_freq ) * amp;
	}
}

~snare.value.play;



/* ----------------------
   Synthetic hi-hat
   ---------------------- */


~hat = {
	arg amp=0.5;
	{
		var amp_env, cut_freq, dur;

		cut_freq = 6000;
		dur = [0.0625, 0.125, 0.25].choose;

		amp_env = EnvGen.ar(Env.perc(1e-7, dur), doneAction:2);
		HPF.ar( {WhiteNoise.ar}.dup * amp_env, cut_freq ) * amp / 4;
	}
}

~hat.value.play;


/* ------------------------
   Simple 8-step sequencer
   ------------------------ */

~player = {
	arg beat_list, synth;
	{
		arg i;
		var amp = beat_list.wrapAt(i);
		if( amp>0, { synth.value(amp).play } );
	}
}

~bd_player = ~player.value([1, 1, 0, 0.1, 0.5, 0, 0, 1], ~bass);
~sn_player = ~player.value([1, 0.1, 0.75, 0, 0.175, 0, 1, 0.5], ~snare);
~hh_player = ~player.value([1, 0.1, 0.1, 1, 0.25, 0.1, 0.75, 0.5], ~hat);


(
c = TempoClock.new(1);
~swing = 0.3; // swing amount
~times = [1 + ~swing, 1 - ~swing, 1 + ~swing, 1 - ~swing]; // add swing
{
	inf.do{
		arg i;
		~bd_player.value(i);
		~sn_player.value(i);
		~hh_player.value(i);

		~times.wrapAt(i).wait;
	};

}.fork(c);
)

c.tempo = 6;

~bd_player = ~player.value([0], ~bass);
~sn_player = ~player.value([0], ~snare);
~hh_player = ~player.value([0], ~hat);
raw 2090 chars (focus & ctrl+a+c to copy)
reception
comments