# Help required to calculate change in tempo over time

#### sammyg

##### New member
Hi There,

I am in need of help to figure out the best way to track a time interval that changes tempo/length over a period of time. So that I know the start time of the next interval.

For example, say I have an audio loop playing at 120bpm and the loop length is 2 seconds. If I was to change the tempo to 80bpm at 1.5 seconds, how would I calculate the next interval or start time of the loop, which now has a length of 3 seconds.

Any help would be great!

#### MarkFL

Staff member
If you have a 2 second loop that has a tempo of 120 bpm, then you have 2 bps. If the tempo changes to 80 bpm at 1.5 seconds, you have already played 3 beats at the original tempo, and the remaining beat at the new tempo will take 0.75 seconds, so the loop will increase in length by 0.25 seconds.

I don't see why the new loop would be 3 seconds in duration. Could you elaborate?

#### sammyg

##### New member
If you have a 2 second loop that has a tempo of 120 bpm, then you have 2 bps. If the tempo changes to 80 bpm at 1.5 seconds, you have already played 3 beats at the original tempo, and the remaining beat at the new tempo will take 0.75 seconds, so the loop will increase in length by 0.25 seconds.

I don't see why the new loop would be 3 seconds in duration. Could you elaborate?
By changing the tempo the loop will adjust in pitch as to keep in time with the tempo. This change in pitch results in change in length. Increasing the tempo shortens the loop and vice-versa. The loop would be 3 seconds to span an entire bar before it repeats. I worked that out by 120bpm / 80bpm x 2 seconds = 3 seconds.

I am looking for an equation to calculate next StartTime if the loop started at 0 and changes tempo x number of times over a period of time.

#### MarkFL

Staff member
If the entire loop, which at 120 bpm takes 2 seconds, is played at 80 bpm, then yes, it will take 3 seconds, as 120:80 = 3:2. But, I thought you are changing the tempo after 1.5 seconds, and playing the remaining beat at the new tempo.

#### sammyg

##### New member
Yes I am. So from 0 to 1.5 seconds the tempo would be 120bpm with a starting length of 2 seconds. Then same loop will play from 1.5 seconds to 2.25 seconds at 80bpm with a remaining length of 0.75. Then at 2.5 seconds the tempo may change to 60bpm and so on and so forth...

I need to be able to do this more than once and continuously over a period of time. Is there an equation I could use to calculate this? Gathering I know the current time, how could I work out the StartTime of the next interval/loop?

#### MarkFL

Staff member
So, from 2.25 to 2.5 second, the loop restarts, still at 80 bpm, and during this 0.25 seconds will play 1/3 beats, leaving 11/3 beats now to be played ay 60 bpm, or 1 bps, so it will take 11/3 seconds to complete at the new tempo.

Thus, if we have an $n$ beat loop which begins at a tempo of $T_1$ bpm, then after $t<\dfrac{60n}{T_1}$ seconds changes to a new tempo of $T_2$ bpm, the duration $d$ of the loop in seconds will be:

$$\displaystyle d=t+\left(n-t\cdot\frac{T_1}{60} \right)\cdot\frac{60}{T_2}$$

#### sammyg

##### New member
Thank you! That's very helpful. If you are also able to consider the following it would be great...

Rather than working out the remaining duration, is it possible to equate the next StartTime of the loop if i know it has been playing for 17.5 seconds at 120bpm, then 6.75 seconds at 80bpm, then for 11 seconds at 90bpm, so on and so forth.... ?

That gives a total of 32.25 seconds of elapsed time. At what time would the next interval begin?

#### MarkFL

Staff member
At this point, I will have to hand it off to someone else, as it is just after 4:30 am here, and nearing time for my slumber. If, when I get up and after I have completed a project I have waiting for me, and no one has offered further help, I will be glad to try to offer assistance. #### sammyg

##### New member
Thanks for all your help so far. Any further assistance would be greatly appreciated. #### MarkFL

Staff member
It seems to me that what you could do is take each time interval on a case-by-case basis and compute how many loops will play, and use the formula I gave above for the transition from one tempo to another. I don't see a simple formula for this; it's just going to take a lot of arithmetic.

#### sammyg

##### New member
I thought this would be the case. Although the current equation requires the time property to be small to compute the remaining duration. Is it possible to use 17.5 seconds and then figure out the next interval when changed to 80bpm?

For example, nextInterval = 17.5 + ...

Then the result should be 18.25 with 0.75 remaining of the loop at the new tempo (80bpm).

Are you able to show an example of how this would work?

Last edited:

#### sammyg

##### New member
I'm fairly sure I have worked it out...

i = t + ( ( ceil( t / n ) * ( n - t ) ) * ( t1 / t2 ) )

Please excuse my formatting, I wasn't sure how to do Ceil in LaTex.

#### MarkFL

To format that in $\LaTeX$ use the code (after rearranging a little and omitting some unnecessary bracketing):
$$\displaystyle i=t+\left\lceil\frac{t}{n} \right\rceil\frac{T_1}{T_2}(n-t)$$