phasor~ question
I made this simple phasor that turns itself off.
It works fine ramping up.
But when I do any shaping, especially steep attack, I am getting a second attack at the end of the phase.
Can't figure out how to prevent that from happening.
Any help would be helpful.
Turning phasor off is too late, so it jumps up.
if you want one shot ramp, why use phasor ?

P.S.
if you insist on phasor, then maybe try this , it offsets phasor reset for vector size.
@Source Audio. Thanks that will work for now.
didn't see the second example. that works as well.
May I suggest this instead
"Can't figure out how to prevent that from happening."
Best thing to prevent timing issues is to keep everything inside dsp.
Here's a Gen-version with two minor variations because i thought i made a mistake by probing the wrong value. (i think it turned out ok anyway? I wasn't sure about the left variation)
One thing that really puzzles me is that when i inspect the values with capture i get a zero from one output while it appears to be max value for the other? Also can't tell why the phasor reset happens at different lines in the capture data. At a frequency of 5 one resets at line 1349 while the other resets at 1202? What?!

(@Will: i went through a name change recently (luvulongtime) and i might have responded with that on your "inverted probability" thread. Anyway i haven't forgotten about your request for a singular "negative" phase but i was banging my head against the wall to make sense of all the logic so i decided to drop it and see if i can approach it with a clear mind later)
i almost said somehting like "why dont you do that with sample and hold" yesterday (wait for nonzero to zero transition to close a gate or set the output to zero or another init value of your envelope; the phasor would continue to run but you block or replace its output after one cycle exactly at the correct time), but that does not work - it is the typical logical gate/feedback loop problem "do something, but only once!" which happens in any signal enviroment with blocks bigger than 1.
The point of this phasor is that , after adding counters, one phasor will loop for n times and then turn itself off and trigger the next one in the chain. I will chain a few of them together - each controlling different aspects of different synths. So the one bang phasor may actually be 10 or 100 cycles before turning itself off and starting a different one down the chain.
The TURN OFF part without the bump at the end is all that I need here.
So far @Souce Audio Example 1 [line -> shape] is working the best for doing this. Although I am still working with the other examples.
//
Thanks @MAKEPATCHESNOTWAR!
(I am currently planning to move to Saigon with the next year or so -> (luvulongtime) haha! that was Da Nang, Huế?! ;)
Yes the inverted probability worked fine at the time. It will also be part of this composition as well so I will be coming back to that one once I get these phasors worked out.
what´s maximum lenght that ramp stuff is needed? for one musical note? then you could try to make a "master line~" similar to how we do it with phasors. it would have a fixed legth of 20 seconds and the segments could be made by scaling.
expensive on DSP, but at least DSP-only and no workaround needed.
@ROMAN THILENIUS no I haven't arrived at composing hour long, day long, or the case of John Cage years long single events yet!
Currently testing up to 10 second long phasor~ pulses.
I am just going through a shape~ phase. It can literally do ADSR, but you can pack in long strings that go much further than ADSR. so that's what this is all about.
Seems like shape~ is the same as line~ and curve~ but has the *~ built in to it so phasor~ plugs in. But it has modes that automatically adjust the shapes to fit into the phasor~ pulse. That's what I like.
Here is a prototype module using @Source Audio recommendation #1
connect 2 of these together - (have to put one external gate to turn them off - for now)
(shape controls sold separately!)
I hope I'll get discount ...
if you need only single instance running at a time why not use single
line~ -> shape~
and let them perform entire script ?
@Source Audio - edit - isn't that what id did?
I used your line~ -> shape~
the rest is when each 'session' finishes, everything gets muted and moves to the next group of instruments.
writing it all out helps me to understand what is going on. later - yes one instance that resets everything after each time around
//
its like having a chamber orchestra that plays for bit, some of them go home, some stay, some new folks show up, and continue seamlessly for the next section on so on. sections may be 1 second or one hour long whatever -
once I figure out who says, who goes, who returns, the whole thing can be reduced to a single section - turning things on and off - presets etc
"not john cage" is exactly what i had in mind.

"a phasor which runs 4 times then stops."
the same works with phasor~ instead of line~, too, so that you can chain several of those constructs after another at audiorate. in case you really need to chain, because even a speed change could also be done within a single phasor ramp.
(...and to be able to use shape~, of course.)
Thanks everyone. I got what I needed here.
Cheers.
I am afraid even if you are satisfied, you can't prevent
phasor~ pyjama-party to continue, ha,ha
Exactly! Here's a gen-version of a phasor that runs for n-cycles. I figured out what the issue with the screenshot was; Because of the values being bigger a line in the window on the right consists of 8 values as opposed to 9 on the left.
I forgot where i exactly picked up on the username. I always thought it came from Appocalypse Now but after rewatching it a while back i think it might have been The Deerhunter? Idk but definitely a Vietnam war-era movie yeah
@MAKEPATCHESNOTWAR - Kubrick - Full Metal Jacket.
Thanks for the patch!
@Source Audio - ok then.

there is a loadbang missing in this patch.
@MAKEPATCHESNOTWAR - that gen phasor with built in counter is amazing - thanks!
edit - patch removed due to incompatibility with the OP's brain.
Sure, no problem i figured it could be useful. Unfortunately the patch is not showing up btw. as they're all Bpatchers.
Full metal jacket ofcourse! It demands a rewatch soon
THIS IS MY PHASOR~! THERE ARE MANY OTHERS LIKE IT BUT THIS ONE IS MINE! 🤪
Born to Phase~
I have a question about this gen~ phasor to shape~
When the shape~ attack is 1. 0. 0. it jumps to 1 after completing a cycle.
But if I give it a slight slope - 1. 11. 0. , it remains at 0 after competing a cycle.
???
Second question -
I built the gen~ phasor in rnbo. Using feedback in place of history. But the repeats will only turn off after 1 repeat. any more than 1 and it doesn't turn off- something I did wrong..?
(edit - kind of works, but if I put 2 repeats it sometimes runs 1 2 or 3 cycles before turning off)

Ok, first question is weird and needs some further inspection... I tried with a [sig~ 0] and it remains 0. so it doesn't appear to be a quirk of shape itself.
Are you sure the second question is a Gen patcher? I ask because of the bang in the upperleft-corner? That shouldn't be possible in Gen right? I'm not familiar with RNBO yet though so i imagine i may be missing something? Maybe someone else can chime in here? Is it possible to debug in RNBO like you do in Gen because i wonder what the output is exactly?
(the puns are killing me! lol)
It's because of history that Gen~ is actually one sample behind. Because of this phasor already outputs the value for the first sample when [sah] receives the trigger to sample the 0. needed to turn the phasor off.
A solution for this would be to multiply the value coming from sah with the output from phasor but i'll dive into this later when i have more time and see if that is actually viable or not... I think the real solution would be to maybe offset the frequency of phasor by one sample?
Irrefutable proof that the stock phasor~ is also lying so that kinda gets me off the hook :D

At these values rounding becomes a thing so it's actually 0.99999999923 or something like that. I wonder how phasor~ is built and how the reset is dealt with because you can either add the remaining values to zero or actually have it start from zero but i think its the former otherwise [==~ 0.] would work.
@MAKEPATCHESNOTWAR - the new solution seems to work. Thanks.
//
About rnbo - that click in side is for debugging. params, bangs, sliders etc can be adjusted from inside of rnbo. I will rebuild it modeled after the new gen you sent and see if it works.
Ok, after diving into this i've found that phasor starts counting from 0.00 but never actually reaches 1 because of the way it wraps around which is most likely just modulo. The way the Genphasor works is that it starts counting from 1 and i don't actually have a solution at hand that doesn't do this. The reason for this is because of history; if you'd start counting from 0 history will add 0 to the existing value in the next cycle so that won't go anywhere...
In the screenshot i used a frequency of 2400 hz and 4 repeats so a single cycle has a duration of exactly 20 samples (samplerate(48000)/2 * 0.1) or 21 samples if you count from 0.00 to 0.00.

The new patch does solve the issue with curve~ btw and a cycle is exactly 20 samples at it should but in total it just runs for 1 sample less because it starts counting from 1 instead of 0.
I checked to see what ramp~ was doing but it appears it runs for 21 samples at a frequency of 2400hz :D but this is because it starts counting from 0. and actually reaches 1.

simply put... rnbo´s fixed point is more similar to int than to float... surprises included.
and then there is that other trap. do we count 20 or 21? does 1.0 count in a system where it is identical to 0.0? or where it happens at the same time?
to grasp this sample counting stuff i always fall back on the basis of the sampling theorem: no, a sample is NOT a point on a timeline.
the first sample starts at T 0, the last sample ends at T 1 . this is not a looping/non-looping problem and also not an int vs. float problem, you would simply count apples and pears.
thanks for the report everyone. apples and pears. got it!

Perhaps helpful to break down what a phasor is. Basically at the core is an accumulator (aka integrator) that just adds things up over time. In gen~ we can do this by building a feedback loop with + and history. If we want to reset the count, we can add a "switch 0" into this feedback loop. That's what the "accum" circuit is in the image below.
A phasor is essentially just an accumulator fed through a "wrap 0 1" operation, also shown below:

The "wrap" operation is essentially a modulo operation, but it handles negative numbers an a more useful way than "mod" does.
We can take this idea to make a ramp burst generator, that generates N "phasor cycles" then stops. We start from the accumulator, and insert a clipping operation to limit the count at N. So now we have a ramp that goes from 0 to N. Then we send the result through a wrap 0 1 to get back our desired zero-to-one range, which means we will get N ramps:

I also added the calculation to figure out when the Nth ramp is done, simply by testing if our current count is equal or greater than the desired count. This will be zero until the ramps are done, then 1 when the Nth ramp ends.
One thing to note: the "wrap 0 1" will never output 1.0. That's because phase/angle/remainders/etc. are a circular number system. Think of the angle of the hand of a clock, when it reaches 12 it is actually at zero again. There is no 24:00hh, there is only 00:00hh. The remainder left over after rounding any number to the nearest integer is always less than 1. Same goes for a phasor: it should never output exactly 1.0, because 1.0 is actually 0.0 in the circular model of phase.
So that's why, after the N ramps are done, this patch will output zero again.
But if you wanted it to output 1.0 at the end (as if it were a series of 4 line~s), then all you need to do is add out 2 to out 1 :-)
phase/angle/remainders/etc. are a circular number system
as it is with LIFE! 🤪
look there, beyond the winter, beyond the clouds, 'twas a sunny sky behind it all, the entire time! 🌻
👽
Thanks for the wisdom Graham!
No peaks without valleys... I for one embrace the winterdepression, without it summer has no meaning...
Ahhh- (no, not Irene Adler’s ringtone!)
aha, so at 2400 military time, which does not exist, irene rings her ringtone. i will keep that in mind.
graham´s use of [wrap] also rings a bell. (not sure yet if it is an alarm bell, but i hear something ringing, and this time it is not a filter.)
to my limited knowledge a phase accumulator based system can not make use of infinitely modulo-ing (wrapping, folding, clipping...) its output for whatever purpose, because there is no infitite counter.
so from my very limited perspective (as an 32-bit MSP user) there should be no other way than to reset the counter itself sooner or later - and not its output. otherwise it can only run only a few minutes to hours depending on step size/frequency.
the max [accum] object´s third inlet silenty gives us a hint how the MSP phasor~ object (probably) does it internally, too: "when the next addition would result in 1. or greater than 1., multiply the accumulated/bufferend value by 0. and output 0."
i.e. reset before count.
"multiply"
no wait, or does it to + -1. ?
...it does + -1.

or actually... + -int().
with -1 it will only work up to nyquist. (same limitation as present in MSP phasor~)
obvious fix.

................................
Graham's logic works perfectly - thanks!
However, whenever possible I would only like to use buttons, not toggles.
Don't know enough about gen to convert the switch from a toggle to a button.
How do that?
In some cases, I may want this particular situation to be able to trigger forward to another instance of itself, or re-trigger itself.
[button] -> [click~] -> [gen~]
click~ generates a single sample spike of 1.0 within a signal that is otherwise zeroes, i.e. a "trigger" signal.
Or, if you have a reason why you need to keep toggle -> gen~, gen~ will interpret that as a "gate" signal: 1.0 while the toggle is on, 0.0 when it is off.
Within gen~ you can turn any "gate"-like signal into a "trigger" by looking for its rising edge:
[in] -> [bool] -> [change] -> [> 0]
The [bool] turns zero into zero, anything else into 1.0.
The [change] outputs +1 when the input is rising, -1 when falling, and 0 otherwise; so it will spike +1 when the gate starts, and -1 when the gate ends.
The [> 0] outputs 1 when the input is positive; so it will output 1 when the gate starts, and otherwise is zero.
This sequence of [bool] > [change] > [> 0] could be saved as an abstraction "gate2trig" for re-use.