Forums > Gen

Detecting 1.0 from [phasor] in [gen~]


jin
August 15, 2012 | 10:22 am

Hello all.
This is very simple…maybe silly question.

As far as I know, it’s calculated by single sample in [gen~].
So is there anyway to retrieve 1.0(or any specific float number) from [phasor] in [gen~]?
Or maybe this is not possible in the first place?

Thank you in advanced

– Pasted Max Patch, click to expand. –

August 15, 2012 | 11:19 am

try this (use 0.99 instead of 1– I don’t think phasor is guaranteed to reach exactly 1)

– Pasted Max Patch, click to expand. –

August 15, 2012 | 3:55 pm

detecting an exact number in gen is not going to be very precise because of the nature of floating point numbers. Floating point numbers can’t exactly represent real numbers, so it’s unlikely that the number you’re trying to detect will occur, especially if it’s the result of a series of operations. Instead, you can detect a number by looking for that number + a range around that number that is very small but not inconsequential. For example, if I’m looking for 1.0, I might try detecting with:

abs(in-1.0) < eps

where eps is the small range around the target number I’m looking for.


August 15, 2012 | 8:04 pm

I think I’m correct in saying that phasor (or phasor~) will never truly reach 1. You can, however, either in gen~ or in MSP, use "delta" and "< 0" to look for the sample at which it wraps around toward 0, which is effectively the sample at which it "reaches 1". You can also use < or <= to find when it surpasses some other value.

----------begin_max5_patcher----------
1016.3oc6XssaiBCD8YxWAxOmsBHPtrpuruue.qTTUjC1g3tDaD1oMoUc+1W
iMP.BjPtTZiTdwscFi8YNdlw9z26Y.ly1f4.yeZN0zv38dFFJSIFLR+aCvJ3
F+PHWMM.E+Ja9yf9ZWB7FgxbHChVg4bSqG7xbxVKBwBw1HrdC..ymRcsfQET
3JkCvuhIvvrOhfT1j6wOFmYitdEgJWJEBrSMFAE9KIzfYwXegdCFX49fUeSW
qjwwNIiNxeuztxIuo1U6D24KuFp50Ow3G85kLzukjxhPlbQZLtktgBPeSvbH
MnMjfLbIqjKnzgUNLKvLixmHbS1DsKFOmBcMTM5Y0V5JBFKAs.GOCSgyCUtq
mJcNCprg7qnXbDlhLQqEa825K20qTRl2YljMdbxns03tKKqApI.S+WirAmDP
kw8owItmImXqBWyAmKmTbCvwoLQJUHWCRH9EbLmvnElsA.FEUvrQgOIg+dlo
Vng8yMQnZSV4lhwuPx9dOsQ4oRuLmYQoimpbYhZzRUu35UHJkmeA9rP8pOUV
4NoegA6xSLj4+WLpHN.LYFNgJyz4Xp.JRATtaDdAbcnXV8bYY+Kf93F+3ZO+
M.AwDDil.hReYh4rsapo8PUxewXQMAJLplukKCi074v3D9MsUgSlSAiEV1U9
QprN.J6.BEXAQiUGq7EkrJJlPEk1Hcmnkb+XVXXokR64kZ7fjm593WIHwxRM
ZS7HmNIJ6D.jSQHR.lKJaS.C3UrPD53Arlp9cDnPfs651hYpEq8KY+P8.pzh
Lou7dMHORSxC2Tno6c1u4fUAG0zfvdjNuQUzLYu9CGnGQS8NMx5elVsd84yG
+b4xgMxk1shKscTz3H6aBxLZIjyhMc9LXRuKLqzVe6k2naBlTtil1fygmbuz
LNO806WHOYUCOs61jPBsoNjJjk3udBjyVG6mkJklWXVFixF6BBM+p0o4UhUl
2RBBU9pLc2edxcInlBh9WLhG1RD6dkP7NZGoddMl5uclOT95q5OAxSyzkyOr
ZCaWNEHqRFP9M7OfCPK4KyiW7Jntzqcqh4S81E9m3Su49x217uZdp7fZepry
wep7Ps9gAV4+H+wx0TtbhvE+FB5WGbcNU35nE3XOVqr1Ka7JB1NSVi8oJqIK
3uKq4trl6xZ9hj07nLD5VsLG60PSR+OKpJUFba79aDNT.+dIiQSiousbvn6x
XNaYLoLo9442kwbrBWG2aJYLi5XQAcmLlQeaPbWKU7qV3k55ftR9VcBuTDP4
pDsVgpmboJF16DabwSh1jes+I09mR6obosnwsEnYPmglQs.MdcFZ7ZAZb6Lz
X2Bz3blnQmTWQ3VBPpHXqhXspB0jq1G89O.fr1hA
-----------end_max5_patcher-----------



jin
August 16, 2012 | 8:26 am

OK..I see.
Thanks for all the tricks everyone.



jin
August 16, 2012 | 8:29 am

One more question.

Before gen~ I used [delta~] – [< ~ 0.] way for clock.
Christopher suggested same method but in [gen~].
Between MSP and gen version, which way is better or more precise?

Thank you.



jin
August 16, 2012 | 9:07 am

I tired 3 different ways.

The results are almost same..

– Pasted Max Patch, click to expand. –

August 18, 2012 | 3:15 am

Yes, using [delta] and [< 0] is the recommended way to do it. Also [change] is available; it works like delta but returns 1, 0 or -1 to represent the direction of change only (not the amount).

Note that if the phasor frequency is negative you will get the boolean opposite (i.e. mostly 1′s but a 0 when the phase wraps). If you want to support both positive and negative frequencies, you can try [phasor] -> [change] -> [change], though this will actually give two samples of click (one positive, one negative).



jin
August 21, 2012 | 12:59 pm

I see..

Thanks a lot


Viewing 9 posts - 1 through 9 (of 9 total)