We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › framerate and time calculation
Page Index Toggle Pages: 1
framerate and time calculation (Read 615 times)
framerate and time calculation
Aug 15th, 2008, 3:56pm
 
hi,

i've another little problem with processing, i've a timeline where i want to see the real time, i supposed to do that in this simple way, that function return something like the time in milliseconds.

public float getTime() {
   return (FRAME_COUNTER*1000/FRAME_RATE);
 }

i incrase the FRAME_COUNTER everytime that the draw function is called, but this function dosen't return the real time, it depends on frame rate, more high it is and more slow my timeline slide.

also i used FRAME_COUNTER*1000 because i cannot get the float value from the operation, why? i need something really precise.

I'm working on a software to synchronize visual effects and sounds track then i cannot loose time between the sequence.


Thanks.


Andrea
Re: framerate and time calculation
Reply #1 - Aug 15th, 2008, 4:22pm
 
Use frameCount and millis(), this is already handled for you.

The division problem is described in Help -> Troubleshooting:
http://processing.org/reference/troubleshooting/index.html#integers
Re: framerate and time calculation
Reply #2 - Aug 15th, 2008, 5:14pm
 
thank you.
Re: framerate and time calculation
Reply #3 - Aug 15th, 2008, 7:21pm
 
with millis() i've some problems because it's not precise i mean that i tried to use millis() and an offset to know when my sequence started.

millis count the time since starting an applet but i need the that this time is 0 when i run my sequence, using and offset like this one

void draw() {
 if (running){
   if (cube.seqs.length>0) {
     Frame f = cube.getNextFrame();
     drawMatrix(f);
     FRAME_COUNTER ++;
   }
}else {start_time = millis();}
 franky.drawTimeline();
}

i loose just a few milliseconds, can i do that with more precision?
Re: framerate and time calculation
Reply #4 - Aug 17th, 2008, 6:42pm
 
Hey, you might want to have a look at a solution I've posted over here for a slightly different context (but should be helpful anyhow):

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1213599231;start=2#2

Hope that helps!
Re: framerate and time calculation
Reply #5 - Aug 17th, 2008, 7:13pm
 
hi

your solution seems interesting, also in order to dont's loose some milliseconds i thought that i could user a negative value to reset my time, maybe i could calculate the probability or the average of the error.
Page Index Toggle Pages: 1