Audio loop with variable intervals (like metronome)

I’d like to play a sound every X seconds, based on what the user sets as the target rate - much like a metronome (well, it is a metronome!)

If the user slides the bar to 1, it would play 1 time per second consistently and evenly. If the users slides to 2 or to 1/2, it would play 2 times/second or 1 time/2 seconds respectively.

I’m thinking delta time would be the best way to get a framerate independent counter (unless you have a better idea), but I’m having a hard time figuring out how to then tell it to play the audio at those intervals.

Here are some pieces of the code, if it helps:

local function getDeltaTime() local temp = system.getTimer() local dt = 0.06 \* ( temp - runtime ) --running at 60FPS runtime = temp return dt end local function runMetronome() local dt = getDeltaTime( runtime ) --Play / loop audio here based on constant time interval end Runtime:addEventListener( "enterFrame", runMetronome )

Thanks all!

I think I figured it out with the help of this thread.

I think I figured it out with the help of this thread.