Trying to get ungranulated playback to work

main
bombinans 2023-10-22 14:51:32 +11:00
parent e25cd1dd53
commit 5ba3416b1f
1 changed files with 50 additions and 20 deletions

View File

@ -1,18 +1,28 @@
Granulator {
var <buflen, <inb, <outb, <>posb, <triggerb, <pitchb, <rectriggerb, <modb, <buffer, <recorder, <grains, <triggersynth, <pitchsynth, server, mode, record, gain, mix, speed, trigger, size, blur, dust, slope, back, chorus, harmonics, detune, pitch, pan, track, jitter;
var <buflen, <inb, <outb, <>posb, <triggerb, <pitchb, <rectriggerb, <modb, <buffer, <recorder, <grains, <triggersynth, <pitchsynth, <loopsynth, server, mode, record, gain, mix, speed, trigger, size, blur, dust, slope, back, chorus, harmonics, depth, crate, detune, pitch, pan, track, jitter, loop, grainamp;
*init {
SynthDef(
\grain_record,
{
arg in = 2, trigger = 0, buffer = 0, mix = 0.5, record = 0.0;
var insig = record * In.ar(in, 1), trigsig = In.kr(trigger, 1);
arg in = 2, triggerb = 0, buffer = 0, mix = 0.5, record = 0.0;
var insig = record * In.ar(in, 1), trigsig = In.kr(triggerb, 1);
RecordBuf.ar(insig, buffer, 0, mix, 1 - mix, loop: 1, trigger: trigsig)
}
).add();
SynthDef(
\grain_looper,
{
arg out = 2, triggerb = 0, buffer = 0, speed = 1, amp = 0, pan = 0;
var trigsig = In.kr(triggerb, 1), playsig;
playsig = PlayBuf.ar(1, buffer, speed, trigsig, 0.0, 1.0);
Out.ar(out, Pan2.ar(playsig, pan, amp));
}
).add();
SynthDef(
\grain_play,
{
@ -30,14 +40,14 @@ Granulator {
SynthDef(
\grain_pitch,
{
arg out, posb, triggerb, track=1, dir=1, detune=0.0, chorus=0, harmonics=2, pitch=0;
arg out, posb, triggerb, track=1, dir=1, detune=0.0, chorus=0, depth=2, crate=128, harmonics=2, pitch=0;
var tracking, base, chor, det, csig, dsig;
csig = Latch.kr(WhiteNoise.kr(), In.kr(triggerb));
csig = Latch.kr(SinOsc.kr(crate), In.kr(triggerb));
dsig = Latch.kr(WhiteNoise.kr(), In.kr(triggerb));
tracking = Schmidt.kr(Slope.kr(posb), 0, 0) * 2 - 1;
base = 2.pow(pitch) * dir * (track * tracking + (1 - track));
det = detune * dsig + 1;
chor = chorus * harmonics.pow((csig * 2).round) + (1 - chorus);
chor = chorus * harmonics.pow((csig * depth).round) + (1 - chorus);
Out.kr(out, base * chor * det);
}
).add();
@ -74,12 +84,16 @@ Granulator {
slope = 0;
chorus = 0;
harmonics = 2;
depth = 2;
crate = 128;
detune = 0;
pitch = 0;
mix = 0.25;
pan = 0;
track = 0.5;
jitter = 0.25;
loop = 0.0;
grainamp = 0.75;
triggerb = Bus.control(server, 1);
pitchb = Bus.control(server, 1);
buffer = Buffer.alloc(server, server.sampleRate * buflen, 1);
@ -87,23 +101,31 @@ Granulator {
\in, inb,
\buffer, buffer,
\record, 0,
\trigger, rectriggerb
\triggerb, rectriggerb
], server, \addToTail);
triggersynth = Synth.new(\grain_trigger, [ \out, triggerb ]);
pitchsynth = Synth.new(\grain_pitch, [ \out, pitchb, \triggerb, triggerb, \posb, posb ]);
grains = Synth.new(
\grain_play,
[
\out, outb,
\buffer, buffer,
\blen, buflen,
\posb, posb,
\triggerb, triggerb,
\pitchb, pitchb,
\modb, modb,
\size, 0.1
],
server);
\grain_play,
[
\out, outb,
\buffer, buffer,
\blen, buflen,
\posb, posb,
\triggerb, triggerb,
\pitchb, pitchb,
\modb, modb,
\size, size,
\amp, grainamp
],
server);
// loopsynth = Synth.new(
// \grain_looper, [
// \out, outb, \buffer, buffer, \triggerb, triggerb,
// \speed, speed, \pan, pan, \amp, loop
// ],
// server);
}
reset { | newbuflen |
@ -124,6 +146,8 @@ Granulator {
blur { ^blur }
chorus { ^chorus }
harmonics { ^harmonics }
depth { ^depth }
crate { ^crate }
detune { ^detune }
pitch { ^pitch }
dust { ^dust }
@ -132,6 +156,8 @@ Granulator {
pan { ^pan }
track { ^track }
jitter { ^jitter }
loop { ^loop }
grainamp { ^grainamp }
mode_ { | v | mode = v; } // todo - playback mode in this class?
record_ { | v | record = v; recorder.set(\record, v);}
@ -139,6 +165,7 @@ Granulator {
gain_ { | v | gain = v; grains.set(\amp, v); }
size_ { | v | size = v; grains.set(\size, v); }
pan_ { | v | pan = v; grains.set(\pan, v); }
speed_ { | v | speed = v; loopsynth.set(\speed, v); }
track_ { | v | track = v; grains.set(\track, v); }
jitter_ { | v | jitter = v; grains.set(\jitter, v); }
blur_ { | v | blur = v; grains.set(\blur, v); }
@ -148,7 +175,10 @@ Granulator {
back_ { | v | back = v; pitchsynth.set(\dir, if( v > 0, { -1 }, { 1 })); }
chorus_ { | v | chorus = v; pitchsynth.set(\chorus, v); }
harmonics_ { | v | harmonics = v; pitchsynth.set(\harmonics, v); }
depth_ { | v | depth = v; pitchsynth.set(\depth, v); }
crate_ { | v | crate = v; pitchsynth.set(\crate, v); }
detune_ { | v | detune = v; pitchsynth.set(\detune, v); }
pitch_ { | v | pitch = v; pitchsynth.set(\pitch, v); }
loop_ { | v | loop = v; loopsynth.set(\amp, v); }
grainamp_ { | v | grainamp = v; grains.set(\amp, v); }
}