«20140103_1504 (pluck piece)» by nathan

on 03 Jan'14 11:30 in randomkarpusstrong

New piece arranged and performed in SuperCollider based on code from Bruno Ruviaro, "Pluck (Karpus-Strong) example" (pluck pattern - thanks Bruno) and a recording of dry leaves in a pestle.

An archive containing the SuperCollider code and audio sample can be downloaded from http://afternoondust.co.uk/blog/140103_1504-pluck-piece.

This code is released under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported license.

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
112
113
114
115
116
117
118
119
120
121
/* 140103_1504 (pluck piece)

by Nathan Thomas
http://www.afternoondust.co.uk

This piece uses code from Bruno Ruviaro (pluck pattern), published on SCCode.org: 
http://sccode.org/1-4Vn

Don't forget to update the path to the audio sample on line 26.

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License:
http://creativecommons.org/licenses/by-nc-sa/3.0/

*/

(
Server.default = s = Server.internal;
s.options.memSize = 655360;
s.options.sampleRate = 96000.000;
s.options.blockSize = 128;
)

s.boot;

c = Buffer.read(s, "insert/path/to/file/here/leaves_twigs_decode_004_edit.wav");

(
   SynthDef("playamp", { arg krBus;
       var sig, amp, trig, thresh;
       thresh = MouseX.kr((-15),(-60));
       sig = PlayBuf.ar(2,c,0.99,loop:inf);
       amp = Amplitude.kr(sig).ampdb;
       trig = amp >= thresh;
       Out.kr(krBus,trig);
    }).add;

   SynthDef("plucking", {arg amp = 1, freq = 440, decay = 5, coef = 0.1, krBus, outBus=0;
        var env, snd;
        env = EnvGen.kr(Env.linen(0, decay, 0), doneAction: 2);
        snd = Pluck.ar(
            in: Mix.new([WhiteNoise.ar(amp), SinOsc.ar(freq,0,amp)]),
            trig: Gate.ar(Impulse.ar(1),In.kr(krBus,1)),
            maxdelaytime: 0.1,
            delaytime: freq.reciprocal,
            decaytime: decay,
            coef: coef,
            mul: amp);
            Out.ar(outBus, [snd, snd]);
    }).add;

    SynthDef("playbuf", { arg outBus=0;
        var play;
        play = PlayBuf.ar(2,c,loop:inf);
        Out.ar(outBus,play);
    }).add;

    SynthDef("bass", {arg amp = 1, freq = 220, decay = 1, outBus=0;
        var env, snd, pan, env2, splay, phase;
        env = EnvGen.kr(Env.linen(1, decay, 1,1), doneAction: 2);
        phase = Array.fill(4, { do({ [0, 0.5, 0.7, 1].choose }) });
        snd = SinOsc.ar([freq, freq + phase],[0,phase],amp/4).sum * env;
        splay = Splay.ar(snd,0.4);
        Out.ar(outBus, splay);
    }).add;
)

z = Synth(\bass);

// Groups

(
    ~sources = Group.new;
    ~control = Group.after(~sources);
    ~bus1 = Bus.control(s,1);
    ~bus2 = Bus.audio(s,2);
)


x = Synth(\playamp,[\krBus,~bus1],~control); y = Synth(\playbuf);

// Pluck
(
    var dur;
    dur = Prand([0.2, 0.4, 0.8], inf);

    a = Pbind(
        \instrument, "plucking",
        \krBus, ~bus1,
        \scale, Scale.dorian,
        \degree, Prand([8, 17, 9, 7, 15, 12, 13, 1, 5, 14], inf),
        \coef, dur,
        \dur, dur,
        \amp, Pwhite(0.3, 0.6),
        \decay, 3
   ).play;
)

// bass

(
    b = Task({
    var delta, dur, note; 
    dur = Prand([10, 15], inf).asStream;
    note = Pwrand([145, 290], [0.8,0.2], inf).asStream;

    while {
            delta = dur.next;
            delta.notNil
        } {
            Synth(\bass,[freq: note.next,decay:4]);
            delta.yield;
        }
    }).play(quant:TempoClock.default.beats+1.0);
)


a.stop;
b.stop;
x.free;
y.free;
~sources.free;~effects.free;~bus1.free;
raw 3062 chars (focus & ctrl+a+c to copy)
reception
comments