# Is there an "algorithm" for the time duration of a repeating rhythm?

Is there a way to determine the amount of additional rest time required after a rhythmic figure in order to ensure that the entire phrase loops seamlessly within a defined time signature? I want to measure the amount of time in seconds.

For example, I used a stopwatch to tap a rhythm. I measured how much time separated each tap (and I assumed the taps themselves don't consume any time). I did this twice: the first time, I included a rest at the end of the phrase. The second time, I didn't include a rest at the end of the phrase. The following numbers give the duration (in seconds) between successive taps. For example, the first item, "1. (tap) 0.274," indicates that the amount of time between the first tap and the second tap is 0.274 seconds. Here's scenario 1, which includes the final rest at the end of the phrase:

1. (tap) 0.274 s
2. (tap) 0.257 s
3. (tap) 0.262 s
4. (tap) 0.249 s
5. (tap) 0.468 s
6. (tap) 0.504 s
7. (tap) 0.237 s
8. (tap) 0.251 s
9. (tap) 0.466 s
10. (tap) 0.978 s

There were 10 taps in this rhythm, as shown. After completing duration no. 10, the rhythm would start again, so that the 11th tap would be the start of the second loop. The total time for this phrase is 3.946 seconds. The number of taps per minute is 167.26.

However, if I were to remove the final 0.978 s duration after the 10th tap, (scenario 2), then the total time for the phrase is 2.968 s, and the number of taps per minute is 202.16. In this second instance, the loop would rush into the beginning and would eventually sound like another rhythm. In other words, the loop was too short when I skipped this final 0.978 s duration.

I am trying to understand how would someone take scenario 2 and determine from the values that, in order to have a seamless loop, they would need an extra duration of 0.978 seconds at the end. How can this be determined? This is a 4/4 rhythm.

• I don't really understand what you are trying to do, but it looks to me as if your "beats" 5 6 and 9 are really two beats each, and "beat" 10 is four, which gives a 16-beat pattern. Also, if you use free software like Audacity (or many other alternatives) you can measure the "beats" much more consistently than by "using a stop watch".
– user19146
Commented Aug 2, 2017 at 19:53
• Sigh -__-. I had a feeling that my question was a mess. I do apologise for this. I'm trying to understand rest times in a mathematical way. For example, in software like FL studios where the user plays a beat and presses play to hear it back, the software plays back a loop of the user's rhythm. The software would have looked at factors from that rhythm -including rest times- to know how to playback that rhythm in a loop. Even if the user's input was rhythmless, the playback would still be a loop of that input. i'm trying to figure out how the software does that. Does this make better sense? Commented Aug 2, 2017 at 20:02
• Before understanding rhythm and beats in a mathematical way, have you made sure you understand them very well in a musical way? Can you tell us what time signature the example rhythm could be in? Is it a 4/4 rhythm or 6/8 or what? Understand the musical aspects of rhythm will make the mathematical aspects much easier. Commented Aug 2, 2017 at 20:07
• I feel that I do understand in a musical way. Although, of course, please let me know what else I am missing in question. It would be 4/4 Commented Aug 2, 2017 at 20:09
• In your "scenario 2" you can add any number of "beats" you like as a rest at the end of the pattern. For example I'm currently working on a 20th-century "classical" piece where most of the music is in alternating "bars" with 23 and 15 beats! You can't "determine mathematically" how the music is intended to sound. There are even pieces which have a fraction of a beat at the end of each bar (e.g. 2 beats + 2/3 of a beat per bar - though you could think of that as "8 beats divided into 3+3+2".)
– user19146
Commented Aug 2, 2017 at 21:13

### General Method

There is a way to figure it out. First, let's establish the fundamental unit of your rhythm. 1, 2, 3, 4, 7, and 8 all have the duration of one fundamental unit. This fundamental unit is called a "beat." So duration 5, duration 6, and duration 9 all last two beats each. Duration 10 lasts four beats.

Using this as the fundamental unit, one beat lasts 0.25±0.01 s. (±0.01 s is the standard deviation based on the fluctuation in your counting of the fundamental unit.) If we have 0.25s/beat, we can take the reciprocal to get:

So your pattern has a tempo of 240 bpm. Since we're working in 4/4 time, each beat is a quarter note (that's what the denominator of 4/4 indicates). Here's your rhythm:

Using this example as a guide, here's the general approach:

1. determine the key signature (X/Y, e.g., 3/4)
2. determine the duration of one beat (Y represents the duration of a beat; normally we refer to the duration as a quarter note or eighth note, but you're referring to it as an amount of time in seconds)
3. multiply the beat duration (Y) by the number of beats (X) to get the time duration of a single measure--the duration that you must repeat/loop
4. optional: multiply the value from step 3 by 4, because music is often written in 4-bar phrases

### First Example

For example, in your case, we would have:

1. the key signature is 4/4
2. one beat lasts for a time duration of 0.25 s
3. multiplying 0.25 s by 4, we get 1.0 s as the time duration of one measure
4. optional: multiplying the value from step 3 (1.0 s) by 4 gives 4.0 s

And so, in your example, each phrase that you loop must be 4.0 s long. (This assumes you'll be using a 4-bar phrase, which is true in the case of the example you provided.) When we add up the duration of 1-10, we get a total of 3.946 s, which almost perfectly matches are ideal value of 4.0 s. In the second case you describe, the time is only 2.968 s, which means you need to add a final 1.032 s of "rest" to bring the total phrase up to 4.0 s (2.968 s + 1.032 s = 4.000 s.) This additional "rest" duration of 1.032 s is almost exactly the same as the value you found to work: 0.978 s. The difference is simply a result of imprecision.

### Second Example

Here's a second way to do the calculation. Let's say you have these values, and we're working in a 4/4 time signature again:

• (tap) 0.173 s ≈ 0.2 s
• (tap) 0.182 s ≈ 0.2 s
• (tap) 0.390 s ≈ 0.4 s
• (tap) 0.599 s ≈ 0.6 s
• (tap) 0.397 s ≈ 0.4 s
• (tap) 0.186 s ≈ 0.2 s
• (tap) 0.425 s ≈ 0.4 s

You can see I've rounded the values. The reason is that it's extremely reasonable for the taps to be off by ~0.03 s. All of the original values above are all within that tolerance, and so it's fine to standardize the numbers by rounding to the nearest tenth of a second.

As we can see from the list above, the smallest unit (the duration of 1 beat) is 0.2 s. Let's convert each time (above) into a number of beats. We divide every time value by the duration of 1 beat to get the number of beats that each tap counts for:

• (tap) 0.2 s / 0.2 s = 1 beat(s)
• (tap) 0.2 s / 0.2 s = 1 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)
• (tap) 0.6 s / 0.2 s = 3 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)
• (tap) 0.2 s / 0.2 s = 1 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)

Adding up all of the beats gives a total of 12 beats. In 4/4 time, one measure contains 4 quarter-note beats, or four 0.2-s-long beats. So 12 beats would be 3 measures, and 16 beats would be 4 measures. To extend the current phrase to a 4-bar phrase, you need to add 4 more beats, each of which would last 0.2 s. So the time you need to add is 4 x 0.2 s = 0.8 s. This might sound even more natural. Here's what that could look like:

• (tap) 0.2 s / 0.2 s = 1 beat(s)
• (tap) 0.2 s / 0.2 s = 1 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)
• (tap) 0.6 s / 0.2 s = 3 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)
• (tap) 0.2 s / 0.2 s = 1 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)

or

• (tap) 0.2 s / 0.2 s = 1 beat(s)
• (tap) 0.2 s / 0.2 s = 1 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)
• (tap) 0.6 s / 0.2 s = 3 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)
• (tap) 0.2 s / 0.2 s = 1 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)
• (tap) 0.2 s / 0.2 s = 1 beat(s)
• (tap) 0.2 s / 0.2 s = 1 beat(s)
• (tap) 0.4 s / 0.2 s = 2 beat(s)

where the added portion has been bolded.

• Thank you for cleaning up my question. You were right to replace beat with tap. I have been going through your explanation and am trying to make a single formula out of it - let me know what you think. 1. get the mean of the rest times - this will be the duration of one beat ±1, 2. multiply this value by the number of beats, 3. i.e. for 3/4 you multiply by 3 and for 2/4 by 2. How does this look? Commented Aug 3, 2017 at 23:12
• I feel silly to still be asking questions even after such a thorough explanation. However, when I attempt to apply it to a different rhythm and test it out in some software (Sonic Pi), it just doesn't seem to sound right. Is it possible for you to do the example as mathematical solution so that each line of your explanation is working out the scenario in maths? Please let me know if this is pushing it, thanks Commented Aug 3, 2017 at 23:16
• @Madra, I've tried to make the edit you requested. See the 4 steps at the bottom of my answer. Would you post the new beats in a comment? Commented Aug 4, 2017 at 0:45
• Thank you for taking the time to explain further. These are the new taps: 1: 0.173 2: 0.182 3: 0.390 4: 0.599 5: 0.397 6: 0.186 7: 0.425 4/4 time signature again, total time 2.352, 8 taps, approx 11 beats (Can't tell if I should count the 0.599 as 2 or 3 beats) and 7 "rests", they have a bpm of 204. Mean 2.352/11, 0.21*4 = 0.84 or 0.8. It sounds good. I'm going to keep trying it out. Thank you very much for your help Commented Aug 4, 2017 at 16:55
• @Madra, I've edited my answer above to include this second example. I would round the time values to: 0.2, 0.2, 0.4, 0.6, 0.4, 0.2, 0.4. The smallest unit is 0.2 s. So the first duration lasts 1 beat, the second duration lasts 1 beat, the third duration lasts 2 beats, etc. We can rewrite it this way: 1 beat, 1 beat, 2 beats, 3 beats, 2 beats, 1 beat, 2 beats. This adds to 12 beats total, which is 3 measures in 4/4 time. If you want 4 measures in 4/4 time, then you need 16 beats total, so you must add 4 more beats, or 4 x 0.2 = 0.8 s of time. I've edited this solution into my answer, above. Commented Aug 4, 2017 at 18:43