metronome—what's the best option for solid timing?

Discussion and feedback on Construct 2

Post » Sat May 31, 2014 11:39 am

Hey guys/girls,

I've been playing around with Construct 2 over the past few weeks and I'm starting to find my way around.

I'm making a metronome app and I'm wondering what is the most reliable way to generate a steady, repeating "blip" sound. (I'm saying "blip" to avoid confusion with "tick"!)

So, we have:

(system) every x seconds -> audio play blip
while something is true -> audio play blip, wait x seconds
on timer -> audio play blip

And one I have discovered which seems to work quite well

on layout start -> audio play blip (tag "blip1")
on timer -> seek "blip1" to 0

And so on and so forth.

So, I wonder if any of you experts can tell me which of these will be the most accurate and reliably steady? I'm finding all of them to have occasional glitches and they are not totally rock-steady.

Cheers!

Douglas.
B
5
S
1
Posts: 5
Reputation: 285

Post » Sat May 31, 2014 12:02 pm

Hey douglas,

I gave a solution to a problem that's similar to yours: a metronome plays a sound on beats. Its rhythm is based on a global BPM value. In this thread, you'll find a general code logic that should give you a solid base to build a metronome upon: https://www.scirra.com/forum/viewtopic.php?f=147&t=101187&p=788436#p788436

Without a generic base, you'll have trouble adding functionnality further down the road.
I hope this helps!
B
79
S
22
G
4
Posts: 311
Reputation: 12,844

Post » Sat May 31, 2014 12:16 pm

Hey,

Thanks for that info. Yes, I already have a framework and I am able to change BPM, beats in the bar, etc. I'm just stuck trying to work out what is the best method to accurately time those beats.

For example, I have a global variable "bpm". The simple solution would be to assign your beats per secong (i.e. 60/bpm) to a timer behavior. So, if your bpm is set to 120, you get a timer that runs every .5 sec.

But, I'm wondering how accurate that timer behavior is? Does it run from the system time, or what? Is it rounded down or up? I suppose I'm wondering what the internal precision is and how reliable it is.

Does that make sense?

I see your code is using the "time" in a variable. Is that more accurate than using a "timer" behavior?
B
5
S
1
Posts: 5
Reputation: 285

Post » Sat May 31, 2014 1:20 pm

I'm pretty sure that the timer behavior is a set of calculations results based on the Time variable.
I don't think you need to worry too much about the internal clock's reliability, it should be really precise. You will always have some +/- 17-30ms of error margin that comes along with the framerate. But that's good enough. I've written an example using the Time variable simply because I wasn't aware of the timer behavior ^^' (just starting programming with C2) !

Sorry for the previous answer!
Cheers,
Nathan
B
79
S
22
G
4
Posts: 311
Reputation: 12,844

Post » Sat May 31, 2014 3:50 pm

Thanks again for checking this out.

I'm having a hard time getting my head around how it works.

From what I can understand, the actual event sheet processes as fast as the computer will allow, correct? But the trigger accuracy of certain events is limited to 60fps (or whatever your device happens to be able to deal with). Is that basically how it works?
B
5
S
1
Posts: 5
Reputation: 285


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 8 guests