1
0

feat: load synthef on startup

This commit is contained in:
2025-06-14 16:41:54 +02:00
parent fddbf09d99
commit 6f90b4d1cf
26 changed files with 214 additions and 152 deletions

9
amplitude_regulation.scd Normal file
View File

@ -0,0 +1,9 @@
(
// analyse amplitude
compressor = Amplitude.kr(sig, 2, 5);
regulation = Select.kr(compressor > thresh, [
1.0,
\ratio.kr(0.8) * (thresh / compressor)
]).lag(\lagTime.kr(0.1));
)

32
examples/bandoo.scd Normal file
View File

@ -0,0 +1,32 @@
(
SynthDef(\bandoo, {
var sig;
// base osc
sig = Pulse.ar(
\freq.kr(120) * [1.05, 1.1, 0.8, 1.5],
LFNoise1.ar(0.04).linlin(-1, 1, 0.3, 1)
);
sig = Splay.ar(sig);
// low pass filter with random range and resonance
sig = RLPF.ar(
sig,
LFNoise2.ar(0.08).linlin(-1, 1, 450, 1600),
LFNoise2.ar(0.1).linlin(-1, 1, 0.25, 0.6)
);
// random pitch shifting and amplitude for each voices
sig = [
sig * LFNoise2.ar(0.02).linlin(-1, 1, 0.1, 1),
PitchShift.ar(sig, 0.05, LFNoise2.ar(0.14).linlin(-1, 1, 0.5, 2), 0.4) * LFNoise2.ar(0.01).linlin(-1, 1, 0.1, 1),
PitchShift.ar(sig, 0.02, LFNoise2.ar(0.09).linlin(-1, 1, 0.25, 1.1), 0.1) * LFNoise2.ar(0.04).linlin(-1, 1, 0.1, 1)
];
sig = LPF.ar(sig, 490 * LFNoise2.ar(0.19).linlin(-1, 1, 0.25, 3), 0.3);
sig = Splay.ar(sig, 0.1);
sig = sig * \amp.kr(1);
sig = Limiter.ar(sig);
Out.ar(\out.kr(0), sig);
}).add;
)
Synth(\bandoo, [freq: 220]);

14
examples/bpf_brown.scd Normal file
View File

@ -0,0 +1,14 @@
(
SynthDef(\bpf_brown, {
var sig, env, rq = 0.005;
env = Env([0, 1, 0], [\attack.kr(0.02), \release.kr(2)], [1, -2]).kr(2);
sig = BrownNoise.ar(0.8);
sig = BPF.ar(sig, \freq.kr(800), rq, 1 / rq.sqrt);
sig = Pan2.ar(sig, \pan.kr(0), \amp.kr(1)) * env;
sig = Limiter.ar(sig);
Out.ar(\out.kr(0), sig);
}).add;
)
(instrument: \bpf_brown, freq: [430, 500, 625].choose, attack: 0, release: 3, amp: 0.6).play;

34
examples/choir.scd Normal file
View File

@ -0,0 +1,34 @@
// create a choir from two formants
(
// https://en.wikipedia.org/wiki/Formant#cite_note-7
var formants = [
[360, 640], // o
[235, 2100], // y
[390, 2300], // e
[585, 1710], // æ
[850, 1610], // a
[750, 940], // ɑ
[820, 1530], // ɶ
[600, 1170], // ʌ
[250, 595], // u
[240, 2400], // i
];
r {
[38 + 3, 38 +5, 38 + 12].do{
|freq|
Synth(\formoo,
[
amp: 0.15,
attack: 2,
decay: 5,
freq: freq.midicps,
formants: [850, 1610],
ff: rrand(550, 2660),
qr: 0.5
]
);
}
}.play;
)

26
examples/pad_chords.scd Normal file
View File

@ -0,0 +1,26 @@
(
var rel = 2;
// degrees, whatever
var chords = [
[0, 3, 5],
[0, 3, 5] + 3,
[0, 2, 5] + 5,
[0, 3, 5] + 2,
];
r {
loop {
chords.do({
|deg|
SynthUtils.playChordGated(
\padoo,
rel,
(40 + deg).midicps,
[ff: 2200, attack: rel, decay: 1, release: rel, vibrato: 0.2, amp: 0.3, gate: 1]
);
(rrand(0.25, 1) + rel).wait;
});
}.play;
}.play;
)

View File

@ -0,0 +1,11 @@
SynthUtils {
*playChordGated {
|synth, time, freqs=#[], args=#[]|
r{
var synths = Array.fill(127, nil);
freqs.do({|freq, i| synths[i] = Synth(synth, args ++ [freq: freq] ++ [release: time])});
time.wait;
synths.do({|item, i| synths[i].set(\gate, 0)});
}.play;
}
}

View File

@ -1,15 +0,0 @@
(
SynthDef(\hat, {
var sig;
sig = Pulse.ar(Array.fill(6, {|index| 120 * (index + {Rand(1.05, 1.15)})}));
sig = Splay.ar(sig, 0.1);
sig = BPF.ar(sig, 10000, 0.1);
sig = RHPF.ar(sig, 7000, 0.1);
sig = HPF.ar(sig, 5000) * 10.dbamp;
sig = Fold.ar(sig);
sig = sig * Env.perc(0.001, \decay.kr(0.1), curve: -8).ar(Done.freeSelf);
sig = sig * \amp.kr(0.8);
sig = Limiter.ar(sig);
Out.ar(0, sig);
}).add;
)

View File

@ -1,8 +0,0 @@
r{
loop {
s.bind {
// synth goes here
}
}
exprand(0.1, 1).wait;
};

View File

@ -1,3 +1,4 @@
// connect all midi devices
( (
MIDIClient.init; MIDIClient.init;
MIDIIn.connectAll; MIDIIn.connectAll;
@ -5,23 +6,31 @@ MIDIIn.connectAll;
MIDIFunc.trace(true); MIDIFunc.trace(true);
) )
// on and off notes are tracked using an array
// the synth need to be using a gated envelope.
( (
~synths = Array.fill(127, nil); ~synths = Array.fill(127, nil);
MIDIdef.noteOn(\on, { MIDIdef.noteOn(\on, {
arg val, num, chan,src; arg val, num, chan,src;
if(~synths[num] == nil, { // To be absolutely save // To be absolutely safe
~synths[num] = Synth(\supersaw, [ if(~synths[num] == nil, {
~synths[num] = Synth(\pad, [
\amp, 0.1, \amp, 0.1,
\freq, num.midicps, \freq, num.midicps,
\harm, exprand(4,20)]); \harm, exprand(4,20),
\gate, 1]);
}); });
}); });
MIDIdef.noteOff(\off, { MIDIdef.noteOff(\off, {
arg val, num, chan,src; arg val, num, chan,src;
if(~synths[num] != nil, { // To be absolutely safe // To be absolutely safe
if(~synths[num] != nil, {
~synths[num].set(\gate, 0); ~synths[num].set(\gate, 0);
~synths[num] = nil; // Remove the reference // Remove the reference
~synths[num] = nil;
}); });
}); });
) )
Synth(\pad)

48
pad.scd
View File

@ -1,48 +0,0 @@
2.midiratio
(
SynthDef(\pad, {
arg freq = 440, gate = 1;
var env, rel, sig, sig2, detuner1, detuner2;
rel = \rel.kr(1);
env = EnvGen.ar(Env.asr(1.2, 0.5, 3), gate, doneAction: Done.freeSelf);
// this is the key part: several oscillators in UNISON, here using a noise ugen
sig = LFSaw.ar((-5..5).collect({|i| freq + i}), LFTri.kr(0.05).range(1, 2));
sig = Splay.ar(sig, 0.1);
sig = RLPF.ar(sig, [3000, 2000, 1250, 600] * LFNoise2.kr(1).range(0.5, 1.2), 0.4);
sig = Splay.ar(sig, 0.1);
sig = HPF.ar(sig, 150);
sig = sig * env;
sig = sig * \amp.kr(1);
Out.ar(\out.kr(0), Limiter.ar(sig));
}).add;
)
(
MIDIClient.init;
MIDIIn.connectAll;
MIDIFunc.trace(true);
)
(
~synths = Array.fill(127, nil);
MIDIdef.noteOn(\on, {
arg val, num, chan,src;
if(~synths[num] == nil, { // To be absolutely save
~synths[num] = Synth(\pad, [
\amp, 0.5,
\freq, num.midicps,
\harm, exprand(4,20)]);
});
});
MIDIdef.noteOff(\off, {
arg val, num, chan,src;
if(~synths[num] != nil, { // To be absolutely safe
~synths[num].set(\gate, 0);
~synths[num] = nil; // Remove the reference
});
});
)
(-10..10)

14
startup.scd Normal file
View File

@ -0,0 +1,14 @@
s.options.numWireBufs = (8192*12000);
s.options.memSize = 1048576;
thisProcess.platform.recordingsDir = "~/Production/SuperCollider/recordings".standardizePath;
// load common synthdefs
~synths = PathName(
Platform.userHomeDir ++ "/Production/SuperCollider/scoobidules/synthdefs"
).entries;
~synths.do({|item| item.fullPath.load});
"giddy up, bucko".postln;
s.boot;

View File

@ -1,20 +1,3 @@
// create a choir from two formants
(
// https://en.wikipedia.org/wiki/Formant#cite_note-7
var formants = [
[360, 640], // o
[235, 2100], // y
[390, 2300], // e
[585, 1710], // æ
[850, 1610], // a
[750, 940], // ɑ
[820, 1530], // ɶ
[600, 1170], // ʌ
[250, 595], // u
[240, 2400], // i
];
SynthDef(\formoo, { SynthDef(\formoo, {
arg formants = #[850, 1610]; arg formants = #[850, 1610];
var sig, env; var sig, env;
@ -27,7 +10,7 @@ SynthDef(\formoo, {
// formant * detuning; very high resonance // formant * detuning; very high resonance
voice = RLPF.ar( voice = RLPF.ar(
voice, voice,
formants * formants *
formants.size.collect{ formants.size.collect{
LFNoise2.kr(3).linlin(-1, 1, 0.98, 1.05) LFNoise2.kr(3).linlin(-1, 1, 0.98, 1.05)
}, 0.05).sum; }, 0.05).sum;
@ -39,34 +22,13 @@ SynthDef(\formoo, {
sig = Splay.ar(sig); sig = Splay.ar(sig);
// narrowing the spectrum a little more // narrowing the spectrum a little more
sig = RLPF.ar( sig = RLPF.ar(
sig, sig,
\ff.kr(4700) * \ff.kr(4700) *
LFNoise2.kr(1).linlin(-1, 1, 0.95, 1.05), LFNoise2.kr(1).linlin(-1, 1, 0.95, 1.05),
\qr.kr(0.9) \qr.kr(0.9)
); );
sig = sig * env; sig = sig * env;
sig = sig * \amp.kr(0.25); sig = sig * \amp.kr(0.25);
sig = Limiter.ar(sig); sig = Limiter.ar(sig);
Out.ar(\out.kr(0), sig); Out.ar(\out.kr(0), sig);
}).add; }).add;
)
// example
(
r {
[38 + 3, 38 +5, 38 + 12].do{
|freq|
Synth(\formoo,
[
amp: 0.15,
attack: 2,
decay: 5,
freq: freq.midicps,
formants: [850, 1610],
ff: rrand(550, 2660),
qr: 0.5
]
);
}
}.play;
)

View File

@ -1,10 +1,9 @@
/* Generic modulable buffer granulator */ /* Generic modulable buffer granulator */
(
SynthDef(\grainoo, { SynthDef(\grainoo, {
|buf| |buf|
var sig; var sig;
sig = GrainBuf.ar( sig = GrainBuf.ar(
numChannels: 2, numChannels: 2,
trigger: Impulse.ar(\trig_rate.kr(20)), trigger: Impulse.ar(\trig_rate.kr(20)),
dur: \gdur.kr(0.5), dur: \gdur.kr(0.5),
sndbuf: buf, sndbuf: buf,
@ -16,5 +15,4 @@ SynthDef(\grainoo, {
sig = sig * \amp.kr(1); sig = sig * \amp.kr(1);
sig = Limiter.ar(sig); sig = Limiter.ar(sig);
Out.ar(\out.kr(0), sig); Out.ar(\out.kr(0), sig);
}).add; }).add;
)

View File

@ -1,4 +1,3 @@
(
SynthDef(\hhgen, { SynthDef(\hhgen, {
var sig; var sig;
sig = Pulse.ar(Array.fill(6, {arg i; \freq.kr(20) * (i + {Rand(1.02, 1.03)})})); sig = Pulse.ar(Array.fill(6, {arg i; \freq.kr(20) * (i + {Rand(1.02, 1.03)})}));
@ -10,7 +9,4 @@ SynthDef(\hhgen, {
sig = sig * Env.perc(0.001, \decay.kr(0.1), curve: \curve.kr(-4)).ar(Done.freeSelf); sig = sig * Env.perc(0.001, \decay.kr(0.1), curve: \curve.kr(-4)).ar(Done.freeSelf);
sig = Pan2.ar(sig, \pan.kr(0)); sig = Pan2.ar(sig, \pan.kr(0));
Out.ar(\out.kr(0), sig!2); Out.ar(\out.kr(0), sig!2);
}).add; }).add;
)
// Synth(\hhgen, [freq: 60, decay: 0.1, ff: 6000]);

View File

@ -1,5 +1,4 @@
( SynthDef(\kickgen, {
SynthDef(\kickgen, {
var curve, sig, envAmp, envPitch, noise, decay; var curve, sig, envAmp, envPitch, noise, decay;
decay = \decay.kr(0.3); decay = \decay.kr(0.3);
curve = \curve.kr(-8); curve = \curve.kr(-8);
@ -16,7 +15,4 @@ SynthDef(\kickgen, {
sig = Pan2.ar(sig, \pan.kr(0)); sig = Pan2.ar(sig, \pan.kr(0));
Out.ar(\out.kr(0), sig); Out.ar(\out.kr(0), sig);
} }
).add; ).add;
)
// Synth(\kickgen, [freq: 50, decay: 4, curve:-8, ff: 9800, envmul: 8, amp:1]);

31
synthdefs/padoo.scd Normal file
View File

@ -0,0 +1,31 @@
SynthDef(\padoo,
{
|gate=0|
var sig, env,freq;
freq = \freq.kr(120);
// three notes. root note, 7th, octave. vibrato
sig = Saw.ar(
[freq, (freq.cpsmidi + 7).midicps, (freq.cpsmidi + 12).midicps] +
SinOsc.ar(\vibrato.kr(6)).linlin(-1, 0.5, 0, Rand(3, 5))
);
// sig = Saw.ar(freq + SinOsc.ar(\vibrato.kr(6)).linlin(-1, 1, 0, Rand(3, 5)));
// detuning through slight pitch shifting
sig = 6.collect({|item| PitchShift.ar(sig, 0.05, Rand(0.98, 1.02))}).sum / 6;
sig = Splay.ar(sig, 0.2);
sig = 8.collect({
var mod = LFTri.kr(ExpRand(0.2, 0.3), Rand(0.0, 2.0)).range(0.001, 0.02);
DelayL.ar(sig, 0.02, mod);
});
sig = Splay.ar(sig, 0.2);
// env = Env.perc(\attack.kr(1), \decay.kr(3)).ar(Done.freeSelf);
env = EnvGen.ar(Env.asr(\attack.kr(1), \decay.kr(3), \release.kr(1)), gate, doneAction: Done.freeSelf);
sig = sig * env;
sig = RLPF.ar(sig, Env([500, 700, \ff.kr(1500)], [0.5, 1, 0.5]).ar, 0.9);
sig = sig * \amp.kr(0.2);
sig = Limiter.ar(sig);
Out.ar(\out.kr(0), sig);
}
).add;

View File

@ -1,12 +1,10 @@
(
SynthDef(\randlfo, { SynthDef(\randlfo, {
var sig; var sig;
sig = LFNoise0.ar(\rate.kr(1)).linlin( sig = LFNoise0.ar(\rate.kr(1)).linlin(
-1, -1,
1, 1,
\min.kr(0), \min.kr(0),
\max.kr(1), \max.kr(1),
); );
Out.ar(\out.kr(0), sig); Out.ar(\out.kr(0), sig);
}).add; }).add;
)

12
synthdefs/rangz.scd Normal file
View File

@ -0,0 +1,12 @@
SynthDef(\rangz, {
var exc, amps, freqs, rqs, sig, envPitch, cond, pitchoo, nb = 20;
freqs = Array.fill(nb, {ExpRand(65, \freq.kr(1000)) * ExpRand(0.5, 1.5)});
rqs = Array.fill(nb, {LFNoise2.kr(2).linexp(-1, 1, 0.001, 0.009)});
amps = rqs.collect({|item, i| 0.05 + (1 / item.sqrt) * ExpRand(0.05, 1.2)});
exc = BrownNoise.ar(1); // risky
sig = Resonz.ar(exc, freqs, rqs) * amps;
sig = Splay.ar(sig);
sig = (sig) * \amp.kr(1);
sig = Limiter.ar(sig);
Out.ar(\out.kr(0), sig);
}).add;

View File

@ -1,6 +1,4 @@
// https://bzoennchen.github.io/supercollider-book/chapters/sounddesign/physical-modeling.html // https://bzoennchen.github.io/supercollider-book/chapters/sounddesign/physical-modeling.html
(
SynthDef(\snare, { SynthDef(\snare, {
var sig, exciter, local; var sig, exciter, local;
local = LocalIn.ar(2); local = LocalIn.ar(2);
@ -18,5 +16,4 @@ SynthDef(\snare, {
DetectSilence.ar(sig, doneAction: Done.freeSelf); DetectSilence.ar(sig, doneAction: Done.freeSelf);
sig = Limiter.ar(sig); sig = Limiter.ar(sig);
Out.ar(0, sig); Out.ar(0, sig);
}).add; }).add;
)

View File

@ -1,4 +1,3 @@
(
SynthDef(\supersaw, { SynthDef(\supersaw, {
arg gate = 0; arg gate = 0;
var sig, env, freq, sub, noise, saw, rel; var sig, env, freq, sub, noise, saw, rel;
@ -14,5 +13,4 @@ SynthDef(\supersaw, {
sig = sig * \amp.kr(0.3); sig = sig * \amp.kr(0.3);
sig = sig * env; sig = sig * env;
Out.ar(\out.kr(0), Limiter.ar(sig)); Out.ar(\out.kr(0), Limiter.ar(sig));
}).add; }).add;
)

View File

@ -1,4 +1,3 @@
(
SynthDef(\tom, { SynthDef(\tom, {
var freq, decay, mod, sig, base, noise, vibrato, pitchEnv, ampEnv, filterEnv; var freq, decay, mod, sig, base, noise, vibrato, pitchEnv, ampEnv, filterEnv;
freq = \freq.kr(120); freq = \freq.kr(120);
@ -13,7 +12,4 @@ SynthDef(\tom, {
// sig = Fold.ar(sig, -0.6, 0.8); // sig = Fold.ar(sig, -0.6, 0.8);
sig = sig + GVerb.ar(sig, 22, 1, 0.8) * -16.dbamp; sig = sig + GVerb.ar(sig, 22, 1, 0.8) * -16.dbamp;
Out.ar(\out.kr(0), sig * \amp.kr(1)); Out.ar(\out.kr(0), sig * \amp.kr(1));
}).add; }).add;
)
Synth(\tom, [freq: 90, decay: 2]);