Skip to content

Instantly share code, notes, and snippets.

@freen
Created October 18, 2017 08:52
Show Gist options
  • Save freen/39d40ae5c739f0a7a6d8bfbe301a556a to your computer and use it in GitHub Desktop.
Save freen/39d40ae5c739f0a7a6d8bfbe301a556a to your computer and use it in GitHub Desktop.
Control amplitude and release of Env using sample Buffer ?
// This doesn't work:
(
s = Server.local;
b = Buffer.read(s, "/Users/freen/Desktop/a_rook_is_placed.wav");
SynthDef("aRookIsPlaced", { arg out=0, bufnum=0, rate=1, trigger=1, startPos=0, loop=0;
var sampleBuf,
sig,
bufRate = BufRateScale.kr(bufnum) * rate,
bufStartPos = BufFrames.ir(bufnum) * startPos;
sampleBuf = PlayBuf.ar(1, bufnum, bufRate, trigger, bufStartPos, loop);
sig = Pulse.ar(90, 0.3, Amplitude.kr(sampleBuf));
Out.ar(out, sig ! 2);
}).add;
Routine({
while ({ true }, {
Synth(\aRookIsPlaced, [\out, 0, \bufnum, b.bufnum]);
rrand(0.9, 1.7).wait;
});
}).play(AppClock);
)
// Although this works:
(
s = Server.local;
b = Buffer.read(s, "/Users/freen/Desktop/a_rook_is_placed.wav");
SynthDef("aRookIsPlaced", { arg out=0, bufnum=0, rate=1, trigger=1, startPos=0, loop=0;
var sampleBuf,
env,
amp,
sig,
bufRate = BufRateScale.kr(bufnum) * rate,
bufStartPos = BufFrames.ir(bufnum) * startPos;
sampleBuf = PlayBuf.ar(1, bufnum, bufRate, trigger, bufStartPos, loop);
amp = Amplitude.kr(sampleBuf);
env = EnvGen.kr(Env.perc(0.001, 4, amp), doneAction: 2);
sig = SinOsc.ar(300, mul:env);
Out.ar(out, sig ! 2);
}).add;
Routine({
while ({ true }, {
Synth(\aRookIsPlaced, [\out, 0, \bufnum, b.bufnum]);
rrand(0.9, 1.7).wait;
});
}).play(AppClock);
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment