Clock with ms definition
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.
----------begin_max5_patcher---------- 1335.3oc0ZstahaDE92vSgkkpTqVBcteI+quC6uZ6pJt3v5cASDXTS2U66d8 bwIFxXXLiGvahRPmwNjuym+N2lguOdT57sujsOM4wj+JYznuOdzH8RpEFYsG ktY1KKVOau91RK2tZ05rzIlKkuTu314e4Ab8ZEG1jWrNqTe+v2Vb6gxSW0rT 4+8blABo4EkoIexd0mmUt3y4Eq9mcYKJM2.T.lBlT+B50em7I0exOFOV8qId 5JEY+aEvqgcY1K5+IoaxJ2sMA5vEecsm1VTVLaiF0o+wt7Yqadk84eSeEHpB dN3DT23j4yJV4CofPT0KTXXjxgMyy14v4kx9w6cqHPmSQLwCR.wfSoUdukD. QhDDCZR.itIj.eXSBRseaIAFIF4H915j8qyWjkfcvO7nlmnU9QQNmODgyTpC H1nN3AQLax1ue1pr2wLH.D9..+.h8QH8QH3QBbpTf.B1e5fpXf6RJ0ySSPgh lXlnGhzTv4JoomVusBSN7bA7tDDUgmYdFFIz4RrQSPPXkUZkGXzgNOXH.jPG 0HwwHcx9r0I.WhDvcIShlStX1DoVePLUYvrXvK+RByEsvE2krFWp4zZFwzVJ VDmpub7vtOLPyzFA1Bx7CkkaKbQBj9XZCucFbDG23IWtG8tHvMIE8gPLEGwH kQeSHev4rWb1vLlmv5QBo0XdzvNlWdSh4A2lXd48IlmwGpw7x6ULOaXVmGiO JlmDCBosNBwvgaGg1IFHhn1QHD.bRLxgoVQzrmvP2atVxlnBgSfScEBgYCzr J1hE1zrznLVk6rJHvfToPDhF0chSZ1eWG8L0AoPfCacBhpG+lviyPUjgcCV1 rH1c3mQiDIPG1jforqkDH3HQBreFZ01RB3XENLr2ge6PW0Jgnzh9ghmms3qU 4KSfpucQRQ8.wHWfjd+KmkwL6do8jBkQo0rcYqxd44je8uq9Z4G9M0KOzpwG aZ7XqFSqMbv+TPL4e5YOlkl+b9yRvP3lZ5P2mEk9MHccdwomDu9MTs9wOL1u 8vtE0vod+PS.uhikY6KyKlUlWMFciapJ6dkRt9l9b9xkY5qWSJaxW971JgjE DsHM7ESpMt8hXhd7McQLgP5MUka1ZUnTkEf29Qy3M+g8.qpy+tSXEBMs7aRO weyJPzhk9fVd2PKVpwGwzaAlwduk0SvRMs2GdhW5Vonidh4jpHDnY9B46sp8 D7s8YhZ18q4YhE6MrBDspdb587EVdGCMcmhcYYOyYjdKSzVg5ITO7D0Nq0IO gvLarCsgKbhkwSTYz6KOA4gmPtNEDhhZD4psBUuC8QAAtJzRsBIpCK0fP5HW rCKj4Yh8O.E9yD0GjiFBmVdlzw5BXjtK.ncJNoVAosBDs5hoWBs7NpfPR7Tj Bf1MBWnCMfnvSYJ7QBgkWWJS3QoLggmxT3S6LpSk7ZJUY5M.Z31isrhZayD8 hn1mhtBPPEcA8VoJtOoE4WYKBviPaOnRXhHVNxlryj93DqdubDi6imbc79YS ha8DqO2CdBG36yjqvSnMUPZqaAueRPQW48FVgxs9z90ISW46fSVz1zJTzR7s s2q.sziPK8Vwsrf3VB1gksIcZ+EAFiwMpwmE6XhCq9ebCU6H3K0PXWiN4lsz sd7ZqPBzOnEcIz1Q8tZNHQUxZBYh9SCzaIq0V8AjuXG2rt1wMXJjwXT1arLn eY4KN3FuqscSZnIrZ8dAs9z0MqqZB6fkbVywLUVgNloOYNPcrW0.wDxm9Iz. +FtYqzgGl7YOUg2zmbPeIoaGj7RfKBglpL9w3+Gv6KdYU -----------end_max5_patcher-----------
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?
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!
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.
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.
@ 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.
----------begin_max5_patcher---------- 1006.3oc0Y00bhBCE8Y7WACuttcxMg.Xea+crSmNnlZYW9vQhc6tc5+8kj.U sMnQERSePYHRjy8jSN26EdYhWv7pmY0A925+SeOuWl34IGRLfW64dAEoOuHO sVdYAEr55zUrfopeiydlKGG0MR1R44Uy+02gntAK2VTskmy3x+DnczGpJ4ko EL4D9wlrz7tqWcw7+tlovVPf+c6Mo5r+I+A.eCZ2cHqr6FfaGbcJewiYkqte CaAW8OATTyb7wXp3.AeCcpOjbCx+NwTdcxDwWSuRxnZMqTCej3fzQjjGhhUz Qr36AmNVjyR2ngOnNHefQCGeLeKmWoSH.yNdj+g3adZ4pcw3AACzevLSFKTk TWEXhuunXoj8mFj+wk1p7bcAXOKsgWvR6z89bVKyGgYBkTRLQdfNSXBnXl1o Tm9Da48MQRyLtOky2j0rVpLJ8dif7BXEyYxfFIGPRoCFwtsjyzsqABGLtMqj uO8JN8rXX5oX3HDRQzig1a8FViO6R+ZFWGMQ9jbWNorKhnHkvQjTzQHfyRHJ 2VJ8pHDd0pU4LMA94Z1dv1.Sij1DGipYaAiuoxGPHcEaEOXqtGlrYXRnRiUZ d3p3k9JvHIBEQgDMrRn6VhgxE.T1.WbMFM204ZSSD1if.ewoINecwQ1ufAkt HgpXA5nHL.cDiC1URKaLLckzqQXXnMbB6hkXzn6DpKFwtoOXKqPTEDQuNevd 2zSl4za5IQJRn05ChtJVn21qHIVo8p1nASGy9qVucQd0heqKJGNerGxqR4C9 pbqTOdL3kl6FK6IleujymUhezIeVKsGRFE8x20vE3gqSnytCwS6HRo6kya3c Dw3uDkAAngnLndDEeSGu.trnHTs6XzDEH2NMInjAJtHIdTJMF6iI93He88MA HGrH4Pk1P8T6.EIc4MNoeuBeSZYcdJm4WT6+3i2VTbayDz83kPt2iSoigPJp gLRUYB3juBlps0gb0zvYWYF3nEl0wKjiUXl7lEjmU992Kn7OTL9gbUc01MK5 vaWoW96dT5KY07rxTdVSo56tHgC7dWziYKWxJ2u9ohrkqqZDGsfnmUtAESh1 FbMLIdXEVDSPjAXZl6AovPqhoDCfj3UfYQHQcOHISSbZm.vpfRzLzokSwVES gNnDW7bzNsfxtPxHCSrcMwmYhDWn4.ywDIR9FoIp2eOYVj5v9mQUU5gIj2N6 ZiDSDgD658SLw.gX2TjXroq3VDSfIXxt6LdWEdGw7GrWFIhIfRz6qMAkIPBm 3foteOcN5I.hMIAfUW7Lw92tESXJG4VHBrKjfPij21ESlTYJX4RtbOHAfC1o yLSk3D2pohqobtlSdcx+Ad06hJC -----------end_max5_patcher-----------
@ 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.
----------begin_max5_patcher---------- 503.3ocyV10ajBBEF9Z8WAgj8ttMiefez65uillFTworqBFASmoS5+8EPcam VlN1LVq23Ld3.799HbfCtNvL9Nh.BtAbGvw4fqiiIjNfyv6NvZ7t7JrvjFjQ dhm8G3U8MII6jlvMsTlbLJsvDSk2u8Fiw5p4cxJhzLLaFhVxYRFtlXx+1VJt B9lVDzmMs34e8lWGFJabT7FB1fk4ORYaenkjK6MSP5FUeT8z7SPn9o9+f60c 4EWW8iqlnmKq3p40h6hs6N+y5t9jk6aH8xUOEXE+.vLLaKDb+7PAOjABnAVj bQT3De4Ka40h80Y7JK.JwNf795.ZtYR+Bi3fuCjHL6FJAJrn7A3WW6WZgMoq U1Lr0w6xXSMQHvaIe.NJYgBC7SSsfjneHj3eNjDYPRTrALIycYjfUdYjfA6O KkQNIEhV6US8QyY4zrNojyrwAzmuK3Ct8XS9kcynKV3iFPQqu5eiL4m+vgv0 KclmiGNAcxa5xq34+0FRBmMjzWeXl4Re4QTrUrXlKXEk89aaaFOc7iYkf20l OJ2wEDfM+WxEDgjxvRppDxqI4cTNORKJHr2dc6ZZQCWs5aPCm3C2TkzTTT5h pnjInn3EUQoSPQIKphzaiNqjBVeR5ca.910zTVciVVMglhlhV1E35aqb9ucg WflTu7h6+3MEVSI -----------end_max5_patcher-----------
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?!…
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…
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>
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.