There are different ways to create subdivided ramps between 0 and 1 from a main phasor. Here are the ones i know:
1.) multiply the main phasor by a ratio and wrap it between 0 and 1
(
{
var phase, phaseDiv;
phase = (Phasor.ar(0, \rate.kr(100) * SampleDur.ir) - SampleDur.ir).wrap(0, 1);
phaseDiv = (phase * \ratio.kr(4)).wrap(0, 1);
[phase, phaseDiv]
}.plot(0.02)
)
2.) calculate the slope and a trigger from your main phasor. Then run an accumulator and reset it by the trigger, multiply it by the slope and a ratio and wrap or clip it between 0 and 1 (or both). This is what you want to do for your windowPhase (use clip) and grainPhase (use wrap).
(
var rampToSlope = { |phase|
var history = Delay1.ar(phase);
var delta = (phase - history);
delta.wrap(-0.5, 0.5);
};
var rampToTrig = { |phase|
var history = Delay1.ar(phase);
var delta = (phase - history);
var sum = (phase + history);
var trig = (delta / sum).abs > 0.5;
Trig1.ar(trig, SampleDur.ir);
};
{
var phase, slope, trigger, accumulator, phaseDiv;
phase = (Phasor.ar(0, \rate.kr(100) * SampleDur.ir) - SampleDur.ir).wrap(0, 1);
slope = rampToSlope.(phase);
trigger = rampToTrig.(phase);
accumulator = Duty.ar(SampleDur.ir, trigger, Dseries(0, 1));
phaseDiv = (slope * \ratio.kr(4) * accumulator).wrap(0, 1);
[phase, phaseDiv]
}.plot(0.02)
)
3.) calculate the slope of your main phasor. Then run an accumulator but dont reset it by a trigger and multiply it by the slope and a ratio and wrap it between 0 and 1. This is the only way of these three attempts to accumulate a new phasor which is slower then your original one. But the triggered reset is the only way of keeping them in sync.
(
var rampToSlope = { |phase|
var history = Delay1.ar(phase);
var delta = (phase - history);
delta.wrap(-0.5, 0.5);
};
{
var phase, slope, trigger, accumulator, phaseDiv;
phase = (Phasor.ar(0, \rate.kr(100) * SampleDur.ir) - SampleDur.ir).wrap(0, 1);
slope = rampToSlope.(phase);
accumulator = Duty.ar(SampleDur.ir, 0, Dseries(0, 1));
phaseDiv = (slope * \ratio.kr(0.5) * accumulator).wrap(0, 1);
[phase, phaseDiv]
}.plot(0.021)
)