# Score count-up speed based on music

I'm trying to implement a score count-up that is synced with the tempo of some short music jingle, but I'm failing on calculating the math for it.

Let's say I have a total score of 2000 that I want to count-up on the screen to the player, starting from 0 up to 2000. There's a catch though - I want to have the count-up synced to a short music jingle that's played during the count-up.

Let's say the music jingle is 15 seconds long, in a specific BPM (beats per minute). As soon as the music jingle starts playing, the score starts counting up from 0, in a certain speed. What I would like to have is the score count-up reach 2000 just when the music jingle is ending (so in this case when 15 seconds has passed), so the count-up speed needs to be based on that music jingle's total time, which is 15 seconds. The same mechanic needs to work if I later on decide to change the music jingle to a 8 seconds jingle instead.

I can't really wrap my head around it and needs some assistance.

• Is the music crucial here (eg. matching beats), or do you just need to know how to count up to a target value over a set duration? Mar 21, 2023 at 19:12
• I guess the music isn't really important when I think about it. It's rather the time/duration of the music that is important, and the end result of the score. So no, the count-up doesn't need to match the music's tempo. Mar 21, 2023 at 19:31

progress = secondsSinceCountingStarted/durationSeconds;

If you want to use an easing function as mentioned in the comment, it can be anything that maps f(0) = 0 and f(1) = 1, like the square function (eases in) or smoothstep (eases in & out).