Is there something off about the way Corona counts seconds?

Hi there,

Working on a simple metronome app. Here’s our “ticking” function:

local function ticking()     function tick()         beat = audio.play( beat1 )         transition.to( stick, { rotation=-45, time=60000/dialNum, onComplete = tock} )     end     function tock()         beat = audio.play( beat1 )         transition.to( stick, { rotation=45, time=60000/dialNum, onComplete = tick} )     end     transition.to (stick, { rotation= -45, time=30000/dialNum, onComplete = tock} ) end

The idea is, when this function is called, a stick object will rotate to 45 degrees and back with a “beat” sound playing on every pass. “dialNum” represents “beats per minute.” So if dialNum is set to 100, then there should be 100 beats per minute.

When we compared this to several online metronomes however, our Metronome was audibly off on its count (and you can imagine how that would be problematic). We can’t figure out why this would be the case, is there a problem with how Corona tracks seconds? Or is there something wrong with our math?

Thanks for taking a look at this.

It’s not hard to imagine there being some small amount of lag with the transition functions. Maybe it’s worth rewriting this to use something tied to the CPU like os.clock()

Transitions are tied to our frame update system. We try to update frames either 30 or 60 times per second, however there are processing things out of our control that can cause the frame rate to drop and our frame updates are not guaranteed to be clock.  We just published a tutorial this week on using enterFrame listeners to animate based on FPS timing. One of the things in the tutorial is a reference to another tutorial that shows you how to do time based animation to smooth out the irregularities on when frames fire. It’s using a “delta time” technique that keeps track of the time difference between frames and give your app better timing.

Rob

Thank you for your replies! We’ll look into it.

It’s not hard to imagine there being some small amount of lag with the transition functions. Maybe it’s worth rewriting this to use something tied to the CPU like os.clock()

Transitions are tied to our frame update system. We try to update frames either 30 or 60 times per second, however there are processing things out of our control that can cause the frame rate to drop and our frame updates are not guaranteed to be clock.  We just published a tutorial this week on using enterFrame listeners to animate based on FPS timing. One of the things in the tutorial is a reference to another tutorial that shows you how to do time based animation to smooth out the irregularities on when frames fire. It’s using a “delta time” technique that keeps track of the time difference between frames and give your app better timing.

Rob

Thank you for your replies! We’ll look into it.