Granulator/classes/Granulator.sc

64 lines
1.4 KiB
Python
Raw Normal View History

2023-04-07 04:33:31 +00:00
2023-04-07 05:58:40 +00:00
Granulator {
var <buflen, <inb, <outb, <posb, <triggerb, <pitchb, <modb, <buffer, <recorder, <grains, server;
classvar server;
*init {
| s |
server = s;
"Adding some synthdefs".postln;
s.postln;
SynthDef(
\grain_record,
{
arg in = 2, buffer = 0, mix = 0.25, record = 0.0;
var insig = record * In.ar(in, 1);
RecordBuf.ar(insig, buffer, 0, mix, 1 - mix, loop: 1)
}
).add();
SynthDef(
\grain_play,
{
arg out=0, buffer, blen, pitchb, triggerb, posb, modb, size=0.1, amp=0.5, pan=0, track=0.25, jitter=0, blur=0.0;
var pitch, trigger, chor, pos, pans, grains, filtfreq;
trigger = In.kr(triggerb);
pitch = In.kr(pitchb);
pos = Wrap.kr(In.kr(posb, 1) + WhiteNoise.kr(blur), 0, 1);
pans = pan + WhiteNoise.kr(jitter) + (track * (In.kr(posb, 1) - 1));
grains = TGrains.ar(2, trigger, buffer, pitch, pos * blen, size, pans, amp);
Out.ar(out, grains);
}
).add();
}
*new { | buflen, inb, outb, posb, triggerb, pitchb |
^super.newCopyArgs(buflen, inb, outb, posb, triggerb, pitchb);
}
init {
server = Server.default;
buffer = Buffer.alloc(server, server.sampleRate * buflen, 1);
recorder = Synth.new(\grain_record, [
\in, inb,
\buffer, buffer,
\record, 0
], server, \addToTail);
grains = Synth.new(
\grain_play,
[
\out, outb,
\buffer, buffer,
\blen, buflen,
\posb, posb,
\triggerb, triggerb,
\pitchb, pitchb,
\modb, modb,
\size, 0.1
],
server);
}
}