SuperCollider Forum
June 18, 2013, 09:56:02 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: The SuperCollider forum is currently experiencing a rash of spambot registrations. New user requests may not be approved quickly as a result -- and if your email address looks like spam, it might not be approved at all. We are working to improve the security of the registration process, and to provide alternate means to contact the administrators to get a new account. Thanks for your patience.
 
   Home   Help Search Calendar Login Register  
Pages: [1]
  Print  
Author Topic: Phasor: beginning at a specific frame for the first loop only?  (Read 2530 times)
0 Members and 1 Guest are viewing this topic.
bitbutter
Newbie
*

Karma: 0
Posts: 20


View Profile
« on: August 25, 2008, 08:45:25 AM »

I'm having a bit of trouble getting the behaviour i'd like.

My aim is to create a synth that includes a phasor uGen. I wanted to code it so that when the synth is instantiated, the phasor can be set to begin from a given frame, but then loop as normal (from 0 to 1000) thereafter.

I couldn't think of a way to get the phasor to start at the correct position at the moment the synth was instantiated, so i tried to send 'set' commands to it shortly after. The idea was that i would set the phasor's resetPos to the frame it should begin from, at the moment of instantiation. And shortly afterwards use a set message to tip the phasor's reset trigger. Thereby forcing the phasor to jump to the desired start position.

But i think that timing issues are preventing this approach from working. If i send the set commands one at a time, the phasor jumps to the correct position. But if i try to run them 'all at once', to get the effect that the phasor begins at the offset position, then the trigger doesn't fire (because of latency between the client and surver somehow?).

Code:
(
s = Server.local;
s.reboot;
s.waitForBoot({
b = Bus.audio(s);
SynthDef("PlayBuf", { arg bus, reset_trigger;
var ph = Phasor.kr(reset_trigger, 0.1, 0, 1000, 500);
Out.kr(bus,ph);
}).send(s);
SystemClock.sched(0.0,{
b.get({arg val; val.postln;});
0.2;
});
});
)

(
x=Synth("PlayBuf",[\bus,b]);
x.set(\reset_trigger,0);
x.set(\reset_trigger,1); // The phasor should jump to 500 at this point
)

Does anyone know of a way that i can ask the phasor to begin at a specified frame when i instantiate the synth that contains it?
Logged
dewdrop_world
AdminGroup
Full Member
*

Karma: 9
Posts: 193



View Profile WWW
« Reply #1 on: August 26, 2008, 08:36:58 PM »

Don't know offhand... but here is a trick I often use when I need to have a given value for exactly the first control cycle of a synth, and then a different value thereafter.

var   initTrig = Impulse.kr(0),
   value = Select.kr(initTrig, [laterValue, initialValue]);

Impulse.kr(0) is 1 for the first control cycle, then 0 forever. So the Select UGen returns the second item in the array right at the start, then switches to the first item.

hjh
Logged

bitbutter
Newbie
*

Karma: 0
Posts: 20


View Profile
« Reply #2 on: August 27, 2008, 04:54:39 AM »

That's perfect thanks!

For completeness, here's how I've used this technique in my SynthDef.

Code:
SynthDef("PlayBuf", { arg out=0,gate=0,start_frame=0;

var env=Env.asr(0.02, 0.5, 0.02, 1, 'linear');
var env_gen=EnvGen.kr(env, gate: gate, doneAction: 2);

                var initTrig = Impulse.kr(0);
var ph = Phasor.ar(0, BufRateScale.kr(bufnum), Select.kr(initTrig, [0, start_frame]), BufFrames.kr(bufnum), start_frame); // phasor start position is variable

var br = (BufRd.ar(1, 0, ph))*(env_gen);

Out.kr(control_bus,A2K.kr(ph)); // send phasor output to a control bus so it can be read by other objects
Out.ar(out,br);
}).send(s);

Logged
bitbutter
Newbie
*

Karma: 0
Posts: 20


View Profile
« Reply #3 on: August 27, 2008, 09:56:55 AM »

Update: It was necessary to do it differently. This time, a single impluse is being fed directly to the trigger argument of the phasor, and the desired start frame is passed as the phasors resetPos argument. THis way, the very first time the phasor runs, it will begin from the resetPos, and thereafter it will cycle from 0 to the end of the buffer.

   
Code:
SynthDef("PlayBuf", { arg out=0,bufnum,control_buf,control_bus,gate=0,start_frame=0;
var env=Env.asr(0.005, 0.5, 0.005, 1, 'linear');
var env_gen=EnvGen.kr(env, gate: gate, doneAction: 2);
var ph = Phasor.ar(Impulse.kr(0), BufRateScale.kr(bufnum), 0, BufFrames.kr(bufnum), start_frame);

var br = (BufRd.ar(1, 0, ph))*(env_gen);

Out.kr(control_bus,A2K.kr(ph));
Out.ar(out,br);
}).send(s);
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!