Skip to content

Instantly share code, notes, and snippets.

@dndrks
Last active November 17, 2021 21:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dndrks/64b261a46b83ea1957b2403de8c1b94c to your computer and use it in GitHub Desktop.
a simple drum synth
engine.name = "BloopDrum"
engine.kick()
engine.snare()
engine.hihat()
Engine_BloopDrum : CroneEngine {
var pg; // pg is a "parallel group", see the alloc ~20 lines down
*new { arg context, doneCallback;
^super.new(context, doneCallback);
}
alloc {
pg = ParGroup.tail(context.xg);
// add SynthDefs
SynthDef("hihat", {arg out = 0, amp = 0.5, att = 0.01, rel = 0.2, ffreq = 6000, pan = 0;
var env, snd;
env = Env.perc(att, rel, amp).kr(doneAction: 2);
snd = WhiteNoise.ar;
snd = HPF.ar(in: snd, freq: ffreq, mul: env);
Out.ar(out, Pan2.ar(snd, pan));
}).add;
SynthDef("snare", {arg out = 0, amp = 0.1, sinfreq = 180, att = 0.01, rel = 0.2, ffreq = 2000, pan = 0;
var env, snd1, snd2, sum;
env = Env.perc(att, rel, amp).kr(doneAction: 2);
snd1 = HPF.ar(
in: WhiteNoise.ar,
freq: ffreq,
mul: env
);
snd2 = SinOsc.ar(freq: sinfreq, mul: env);
sum = snd1 + snd2;
Out.ar(out, Pan2.ar(sum, pan));
}).add;
SynthDef("kick", {arg out = 0, amp = 0.3, sinfreq = 60, glissf = 0.9, att = 0.01, rel = 0.45, pan = 0;
var env, snd, ramp;
env = Env.perc(att, rel, amp).kr(doneAction: 2);
ramp = XLine.kr(
start: sinfreq,
end: sinfreq * glissf,
dur: rel
);
snd = SinOsc.ar(freq: ramp, mul: env);
snd = Pan2.ar(snd, pan);
Out.ar(out, snd);
}).add;
context.server.sync;
this.addCommand("hihat", "", { arg msg;
Synth("hihat", [\out, context.out_b], target:pg);
});
this.addCommand("snare", "", { arg msg;
Synth("snare", [\out, context.out_b], target:pg);
});
this.addCommand("kick", "", { arg msg;
Synth("kick", [\out, context.out_b], target:pg);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment