Skip to content

Instantly share code, notes, and snippets.

@ryanlaws
Created June 15, 2021 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanlaws/60d32f4d40be5b6f9b4ec08f8a6d40ac to your computer and use it in GitHub Desktop.
Save ryanlaws/60d32f4d40be5b6f9b4ec08f8a6d40ac to your computer and use it in GitHub Desktop.
just a really janky wavetable in SuperCollider
// your keycodes may vary
~ctrl = 105;
// recording params - 12 sec for no particular reason
~bufferSeconds = 12;
// do this first and then wait
~buf = Buffer.alloc(s, s.sampleRate * ~bufferSeconds, 2);
(Ndef(\seekWt, { |offset=0,freq=55, gain=1, seekLag=5, curve=0, probability = 1, rate=1|
var trigL = Impulse.ar(freq);
var trigR = DelayL.ar(trigL, 5, freq.reciprocal / 2);
var len, divisions, env, floor, trig, index, slice, fade, levels;
trigL = trigL * (WhiteNoise.ar(0.5, 0.5) > (1 - probability));
trigR = trigR * (WhiteNoise.ar(0.5, 0.5) > (1 - probability));
len = freq.reciprocal;
offset = offset * ~bufferSeconds / (~bufferSeconds + len);
seekLag = Lag.kr(offset, seekLag);
divisions = ~bufferSeconds / len; // how many "slices" (may be float)
index = seekLag / ~bufferSeconds * divisions; // which slice (may be float)
slice = floor(index); // not float
fade = index - slice;
// seekLag = slice * divisions;
seekLag = slice / divisions * ~bufferSeconds;
levels = [1 - fade, fade];
slice.poll(2, 'slice');
divisions.poll(2, 'div');
seekLag.poll(2, 'seek');
// seekLag
(
Mix.ar(
[trigL,trigR].collect({|trig, i|
var phasorCoeff = len * s.sampleRate * rate;
var phasorBias = seekLag * len * s.sampleRate;
var phasor = EnvGen.ar(Env.perc(0, len, 1, curve), trig, phasorCoeff, phasorBias);
var env = fold(EnvGen.ar(Env.perc(0, len), trig) * 2, 0, 1);
// A2K.kr(phasor / s.sampleRate).poll(10);
BufRd.ar(2, ~buf, phasor, 0, 4) * levels[i] * env
// var phasor = LFSaw.ar(freq, 0, -1, 1);
})
)
* gain).tanh;
// EnvGen.ar(Env.perc(0, freq.reciprocal, 1, 0), trigL);
}).play;)
(Ndef(\bufRec, { |rate=1, curve=0, seconds=12, offset=0|
var trig = KeyState.kr(~ctrl, 0, 1, 0);
var env = EnvGen.ar(
Env.perc(0, seconds, s.sampleRate * seconds, curve),
trig);
// PlayBuf.ar(2, ~buf, 1, trig);
// (env / s.sampleRate).poll(2);
BufWr.ar(SoundIn.ar([0, 1]), ~buf, offset + env, 0);
}).play;)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment