From: Applied CD on
I?ve got a giant array of audio sample data (glFreqData[sampleTime]), about
1700 samples, 16 frequency bins per sample. I?m using the following code to
convert system time to a sample time index however on some machines I?m getting
a negative sample index. My guess is that _system.milliseconds is exceeding
maxInteger but I don?t see any documentation on what to expect when that
happens (if you do the math, _system.milliseconds will exceed maxInt in just
under 25 hours). I can easily flip the sign but when the time is negative, is
the system counting up (toward 0), or down (increasingly negative)?

mySample = ((_system.milliseconds/100) mod glFreqData.count) + 1


From: Mike Blaustein on
I think I have a different calculator than you, but for me, the
maxInteger comes out to just under 25 days... not hours.

put the maxInteger
-- 2147483647

theSeconds=the maxinteger/1000
put theSeconds
-- 2147483

theMinutes=theSeconds/60
put theMinutes
-- 35791

theHours=theMinutes/60
put theHours
-- 596

theDays=theHours/24
put theDays
-- 24

All of which is neither here nor there. You can try to make the
milliseconds a float, but I doubt that would help. I don't know what
Director would do if the milliseconds goes beyond that. Often when a
number that should be an integer goes beyond the maxInteger, it turns
into -2147483647 (negative maxinteger) and stays that way. I have never
had trouble using the milliseconds, and I have used it on some long term
kiosks that stayed up for as long as Windows would stay up without
crashing. If you are having trouble with it, you may want to make your
calculations based on a variable that is set by a timer or timeout
object so it can be reset if it gets too high.
From: alchemist on
-- the issue ---
Assuming you are on windows (should be the same on mac, but not so familiar
with mac internals) the milliseconds returns the result of the windows API
GetTickCount() function.
This function returns an unsigned long (32 bit) value. The range of such a
value is 0-4294967295 (4GB). So, after about 49 days, this value will reset
to 0, and continue from there.
Furthermore, when converting the value to a signed long -as director is
doing- you get a negative value after half that time (25 days, not hours).
You can convert the negative value to a positive float by using:
if (val < 0) then val=float(the maxinteger)*2+2 + val
put the maxinteger
-- 2147483647
put float(the maxinteger)*2+2 + ( the maxinteger +1 )
-- 2147483648.0000
put float(the maxinteger)*2+2 + (-1)
-- 4294967295.0000
You can also workaround the timer reset issue, by comparing the last value
to a previous one.. However:

-- solution --
I had created a small Xtra a while ago, that returned high precission
(sub-milliseconds accuracy) time as a float number.
I believe this should solve your problem. So, if you are on windows, mail me
to send it to you. info at (reverse >) gr. rtr.


> but when the time is negative, is the system counting up (toward 0), or
> down (increasingly negative)?
increasingly negative up to -1, 0, 1, 2...

"Applied CD" <webforumsuser(a)macromedia.com> wrote in message
news:g4bn7t$mkq$1(a)forums.macromedia.com...
> I?ve got a giant array of audio sample data (glFreqData[sampleTime]),
> about
> 1700 samples, 16 frequency bins per sample. I?m using the following code
> to
> convert system time to a sample time index however on some machines I?m
> getting
> a negative sample index. My guess is that _system.milliseconds is
> exceeding
> maxInteger but I don?t see any documentation on what to expect when that
> happens (if you do the math, _system.milliseconds will exceed maxInt in
> just
> under 25 hours). I can easily flip the sign but when the time is negative,
> is
> the system counting up (toward 0), or down (increasingly negative)?
>
> mySample = ((_system.milliseconds/100) mod glFreqData.count) + 1
>
>






From: Andrew Morton on
Mike Blaustein wrote:
> Often when a
> number that should be an integer goes beyond the maxInteger, it turns
> into -2147483647 (negative maxinteger)...

Off-by-one error!

put the maxinteger+1
-- -2147483648

> ...and stays that way.

Huh?

OP: there's a technote on the issue:
http://www.adobe.com/go/tn_16259

Andrew


From: Applied CD on
Thanks all. That tech note should really be part of the documentation. Sorry
about the math, yeah it?s 25 days, not hours. For my own purposes I only need
to count out regular beats at 1/10 second intervals until my data set runs out,
then start over.

The following should work for me. I know there?s a chance of repeated beats
transitioning from ? to + and again at + to ? however this small glitch occurs
at the millisecond level, far below the resolution of my data set. Also, I know
the abs() shouldn?t be necessary but mySample is used as a list index so now
I?m being paranoid and want to be sure it?s never negative.


myTime = _system.milliseconds
if myTime < 0 then
myTime = the maxInteger + myTime
end if
mySample = ((abs(myTime)/100) mod glFreqData.count) + 1