## Clock with ms definition

Mar 26, 2011 at 3:18pm

# Clock with ms definition

Hello,

I need to have a clock in a patch that start to count when it receives a time message from another patch. Example, the first patch send a msg: 13:52:22:982031, the second patch read the content and start to count from that time.
This is my implementation but I would like to know if there is any object with precise clock in Max, [date] has just tick as smallest definition.

Thanks.

– Pasted Max Patch, click to expand. –
#55835
Mar 26, 2011 at 3:37pm

Hello,

[cpuclock] ?

#200725
Mar 26, 2011 at 6:06pm

Thanks,

Looking at the help file says “can be used to time real world events with microsecond precision” but if I monitor it at a constant (1000ms) rate with a [metro] object, I get different results, with high differences up to 23ms error. The problem could be both in the metro object and the cpuclock, I am doing this test in two computers, one is a macbook and a low performance netbook. I get the biggest differences between time results in the netbook.
I noticed also with other tests that this time differences are accentuated when the computers are under high cpu usage.
My main purpose is to run in this two computer a clock that would give me a costant time reference in both of them but this shift is creating obviously some problems.

From the helpfile of the cpuclock, I get that the output of cpuclock is the time elapsed in ms from the moment the application was launched, so the smallest value is 1ms. Am I right?

Thanks.

#200726
Mar 26, 2011 at 7:37pm

Make sure to eliminate the influence of monitoring, for example by collecting the values in a list before printing. When doing this I get quite exact values with differences less than 0.1ms!

#200727
Mar 26, 2011 at 10:44pm

Thanks, I do not get the same precision as you but is better without lists, but I have not tested on the netbook yet. Anyway how do you truncate a decimal number taking only the last two digits of it?
I have tried with [sprintf %.2f] but does not work.
the fact is that i am dealing with big numbers as, 14705867.976603 , apart from the fact that I do not need all that decimal points but just one or two, I think I am going over the capabilities of Max for the 32bit.

Thanks.

#200728
Mar 27, 2011 at 6:49am

Hello,

- i don’t think 14705867.976603 is a big number for a floating point value ; FLT_MAX (≥1E+37) ; so problem should come from ^2 approximation artifact rather than overflow.

- have a look on the [p sched_test] in the [cpuclock] help patcher.

- if you want better accuracy you can change scheduler settings of maxMSP in preferences.

- 23ms !!! please post you benchmark patch.

#200729
Mar 28, 2011 at 10:40am

I am not entirely surprised about [metro 1000] showing 23ms deviation. That’s sort of high, but if you were expecting 0 deviation that was simply illusory.

In re: sprintf… you might try the symout option.

#200730
Mar 28, 2011 at 1:06pm

@ vanille bechamel
I looked at the sched_test already but only on my main computer, the mac, but i did not on the netbook.
I am posting here the patch that you are curious to see, it is not a benchmark patch, but a patch I need to read the cpuclock in order to use it as an indication for other duties.
The 23ms was an high peak anyway and not a constant variation on the netbook, on the other two computers, where I tested, the variations were always in the order of 2 ms, maximum. Removing message boxes and other lists the variation diminished even more. I think a problem with the netbook when I did the test was the fact that I was collecting all the result in a [coll] object, the patch I am showing you now is then an old and wrong version.
I have all the results in a text file collected in the [coll] object from the netbook.

– Pasted Max Patch, click to expand. –

@ Peter Castine
I did not expect 0 deviation but was a big surprise anyway to see even 2ms variations. I thought that that the maximum would be around 0.1ms, but I was wrong. :)
using the symout option seems to work but if i need to convert the symbol again into a number seems to restore part of the decimal number I previously rounded, the fun part is that it does it just when I am using as source to round the values from the cpuclock object.
The second problem is that as soon as some time elapse since I open Max, and the cpuclock numbers are getting bigger, when I connect the cpuclock output to a floatnum it loses definition in the decimals.

– Pasted Max Patch, click to expand. –
#200731
Mar 28, 2011 at 4:14pm

Hello maxers,

i got around 1 ms deviation …

– Pasted Max Patch, click to expand. –
#200732
Mar 28, 2011 at 6:31pm

i think it is a scary (and cool) test. i get 2.5ms with overdrive off and between wide spectrum of 0.7 and 1.1 with overdrive on. maybe i need to optimise my system a bit more?!…

#200733
Mar 30, 2011 at 6:37am

What do you need this precision for? Any scheduler event has a jitter/variance of about what you experience. The CPU clock is still very exact, the variance is only due to the moment you look at it. Inside its absolutely precise.
The only application I can think of where this variance within the scheduler interval is not acceptable is combining sounds in MSP (which would change the sound, not the rhythm/timing). But there you have a sampling rate, and could use that as reference. Just never leave the audio domain.

For anything else, 1.1 ms is more than adequate. Keep overdrive on, and you can tweak the scheduler parameters in the preferences. For sure a netbook has more difficulties to pack all scheduler events together. You might create a backlog…

Stefan

#200734
Mar 30, 2011 at 12:24pm

@andgu

I agree that 23ms seems high. OTOH, you referred earlier to a “low performance netbook”. Depending on your patch and how you’re measuring things, yeah, sure.

On the “rounding” front: are you aware of how 32-bit floats work? I don’t want to sound rude, but math in Max makes a *lot* more sense after spending a bit of time with a tutorial on digital arithmetic. There’s a very good tutorial by Peter Elsea on this subject specifically for Max < ftp://arts.ucsc.edu/pub/ems/maxtutors/Max&Numbers.pdf>

#200735
Oct 19, 2011 at 10:07am

your idea is great . Sorry to say that i am unable to answer but definitely i will give you a link through whch you will be able to find your solution.
math tutors

#200736

Anonymous

Anonymous
Nov 2, 2011 at 1:37pm

Having difficulty working out Math problems? Stuck with your homework and having nightmares before your next Math test? TutorVista’s tutors can help you. get you online tutoring

#200737

You must be logged in to reply to this topic.