electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Supercollider
LFO and oscillator phase reset
Post new topic   Reply to topic Moderators: v-un-v
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
someone



Joined: Apr 11, 2009
Posts: 9
Location: somewhere

PostPosted: Sat Apr 11, 2009 9:34 am    Post subject: LFO and oscillator phase reset
Subject description: newbie question
Reply with quote  Mark this post and the followings unread

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.
Back to top
View user's profile Send private message
dewdrop_world



Joined: Aug 28, 2006
Posts: 858
Location: Guangzhou, China
Audio files: 4

PostPosted: Mon Apr 13, 2009 2:27 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
Back to top
View user's profile Send private message Visit poster's website AIM Address
someone



Joined: Apr 11, 2009
Posts: 9
Location: somewhere

PostPosted: Fri Apr 17, 2009 5:35 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: v-un-v
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Supercollider
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use