someone
Joined: Apr 11, 2009 Posts: 9 Location: somewhere
|
Posted: Sat Apr 11, 2009 9:34 am Post subject:
LFO and oscillator phase reset Subject description: newbie question |
 |
|
When an LFO or oscillator is running, how can I trigger its phase to reset? For example, I'm trying to use an Impulse ugen as a control signal and I can't figure out how to get it to reset its phase with a trigger from a gui button. Just sending a 0 value to the initial phase parameter doesn't do it. If some kind soul would assist me in finding the simple solution to this I would greatly appreciate it. Many thanks. |
|
dewdrop_world

Joined: Aug 28, 2006 Posts: 858 Location: Guangzhou, China
Audio files: 4
|
Posted: Mon Apr 13, 2009 2:27 pm Post subject:
|
 |
|
I don't think this is possible with the normal LFO UGens. Once they start running, they keep going under their own power -- the phase is incremented automatically.
As you discovered, the phase argument doesn't control the exact phase this instant. (If it did, SinOsc.ar would be silent unless you put a Sweep or Phasor into the phase argument every time -- pretty inconvenient, that.) It's an offset that is added to the internal phase, which gets updated automatically.
I've asked on the mailing list here if there are any third-party plug-ins that would do this.
But, you can do it with standard UGens with a little trickery. Phasor outputs a signal that rises linearly, then jumps back to the beginning when it goes above the ending value. To simulate Impulse, we can watch the signal to see when it decreases (which should happen only when the Phasor resets). HPZ1 measures (half the) difference between the current value and the previous sample -- it's positive if the signal is rising and negative if falling. So...
Code: | (
a = { |t_reset = 0, lfofreq = 1|
var ph = Phasor.kr(t_reset, lfofreq / ControlRate.ir, 0.0, 1.0),
trig = HPZ1.kr(ph) < 0.0;
(SinOsc.ar * Decay2.kr(trig, 0.01, 0.1)) ! 2
}.play;
)
// this trigger resets the phase
a.set(\t_reset, 1);
a.free; |
If you want an audio-rate impulse, change to Phasor.ar(t_reset, lfofreq * SampleDur.ir, 0.0, 1.0) and HPZ1.ar.
For other LFO shapes, I would load the shape into a buffer and use Phasor in conjunction with BufRd:
Code: | (
// note, asWavetable is false b/c BufRd doesn’t use wavetable format
~sinlfobuf = Buffer.alloc(s, 1024, 1, completionMessage: { |buf|
buf.sine1Msg(#[1], asWavetable: false);
});
SynthDef(\lfobuf, { |t_reset = 0, lfobuf, lfofreq = 1, lfoamp = 0.1|
var lfosize = BufFrames.kr(lfobuf),
ph = Phasor.kr(t_reset, lfofreq / ControlRate.ir, 0.0, 1.0),
lfo = BufRd.kr(1, lfobuf, lfosize * ph, interpolation: 1);
SinOsc.ar(440 * ((lfo * lfoamp) + 1))
}).send(s);
)
a = Synth(\lfobuf, [lfobuf: ~sinlfobuf]);
a.set(\t_reset, 1);
a.free; |
(All this is just a way to make the phase explicit in the SynthDef, where it's normally hidden from view.)
James _________________ ddw online: http://www.dewdrop-world.net
sc3 online: http://supercollider.sourceforge.net |
|
someone
Joined: Apr 11, 2009 Posts: 9 Location: somewhere
|
Posted: Fri Apr 17, 2009 5:35 pm Post subject:
|
 |
|
Thank you so much for your informative reply. I finally got a chance to work with the examples you offered, and I found several lessons in them for a beginner like myself. I will keep an eye out for more of your posts. Thanks again. |
|