«How to tempo-sync LFOs in Patterns across multiple instances of a Synth» by defaultxr
on 12 Mar'15 05:42 inThis code shows you how to tempo-sync the various oscillator types in SuperCollider. When you play the pattern, you should be able to hear that the output will sound fairly consistent, even though the pattern's \dur is totally random. That is because the \tbeat and \tempo parameters are provided to the Synth via the pattern. It is possible to calculate what the starting phase of the oscillator should be no matter when the synth is scheduled to start if you provide these parameters and use the math examples in the SynthDef. The modulo (%) operation is required because otherwise, high values of \tbeat will cause the oscillators to take a while to actually start.
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
SynthDef(\temposync, { | gate=1 tempo=1 tbeat=0 amp=0.5 pan=0 out=0 | var env, mult, sel, tmult, output; env = Env.asr(0.05, 1, 0.05).kr(2, gate); mult = 1; sel = MouseY.kr(6, 0).round; tmult = tempo*mult; output = Select.ar(sel, [ Impulse.ar(tmult, (tbeat*mult)%1), SinOsc.ar(tmult, (tbeat*mult*2pi)%2pi), LFTri.ar(tmult, (tbeat*mult*4)%4), // 2 LFSaw.ar(tmult, (tbeat*mult*2)%2), Saw.ar(tmult), // 4. LFPulse.ar(tmult, (tbeat*mult)%1)*2-1, Pulse.ar(tmult), // 6. ]); // NOTE: Saw and Pulse are not syncable because they have no phase inputs... output = LPF.ar(BrownNoise.ar, output.exprange(20,20000)); Out.ar(out, Pan2.ar(output, pan, env * amp)); }).add; Pdef(\lfo_demo, Pbind(\instrument, \temposync, \dur, Pwhite(0.1, 1.0, inf), \legato, 1, \tbeat, Pfunc({thisThread.clock.beats}), \tempo, Pfunc({thisThread.clock.tempo}), ));
reception
Very Cool. I'm wondering if anyone has an idea of how to do something like this but lock the LFO to an instance of a TempoClock, and allow for tempo updates. Ideally, I'd like to lock a few LFSaw synths to a TempoClock at frequencies of each power of two, and pipe the into control buses to use elsewhere.