Best way to trigger a sample to play

Then:

b = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");

(
c = Bus.control(s, 1);

a = { |gate = 1, amp = 0.1|
    var main_eg = EnvGen.kr(Env.asr(0.01, 1, 0.1), gate, doneAction: 2);
    var trig = NamedControl.tr(\trig, 0);
    var toggle = ToggleFF.kr(trig);
    var gates = [toggle, toggle <= 0];
    var egs = EnvGen.kr(Env.asr(0.01, 1, 0.01), gates);
    var players = PlayBuf.ar(1, b, BufRateScale.kr(b),
        gates,
        startPos: TRand.kr(0, BufFrames.kr(b) * 0.5, gates)
    );
    Out.ar(0, ((players * egs).sum * (main_eg * amp)).dup)
}.play(args: [trig: c.asMap]);

// automated trigger for testing: any kr trigger-y signal will work
// (which you already have)
t = {
    var trigFreq = SinOsc.kr(0.1).exprange(1, 12);
    Impulse.kr(trigFreq)
}.play(outbus: c);
)

hjh

1 Like