# Is it possible to calculate a bar based on song BPM and time position in the song? [duplicate]

I'm using a spreadsheet to analyze song arrangements. I know the BPM of the song.

I'd like to just listen to the song, and then input the time where I'd like to make a note (say 1:50 or 90 seconds) and have a formula determine what bar this happened at (vs. what time).

What might the formula be to determine the bar from time and BPM?

EDIT: I'm almost every case, I'm listening to music in 4/4!

• Does this answer your question? I'm trying to figure out number of measures Oct 31, 2021 at 2:09
• Since the time signature is known, the calculation is exactly the one given in the duplicate, where the total duration of the song is replaced by the duration up to the point in question. Oct 31, 2021 at 2:10
• Looking at the question and the answers so far, there is a hidden assumption that the song is metrically regular with the same number of beats in each bar. This is not necessarily true. Oct 31, 2021 at 6:28
• @No'amNewman - that has to be the case - otherwise it's virtually impossible to do an accurate calculation. Without it being a given that the beat is regular and the bars are all the same length, it all becomes meaningless.
– Tim
Oct 31, 2021 at 8:39
• Is this really a question that is on-topic on Music Theory & Practice? It's just basic trivial middle-school math, after all. Oct 31, 2021 at 9:14

What might the formula be to determine the bar from time and BPM?

If you multiply beats per unit time by the time, you get the number of beats. To find the number of bars, divide by the number of beats per bar. If your time is expressed in seconds, you also need to convert minutes to seconds. You also need to add one bar, because the beginning of bar 1 is at t=0.

For example, 1:50 is 110 seconds, so, if there are 108 beats per minute and 3 beats in each bar, you have

``````(108 beats / min) * 110 seconds / (60 seconds / min) / (3 beats / bar) + 1 = bar 67
``````

Another example, 90 seconds is 1.5 minutes, so, assuming 72 bpm and 5 beats per bar, you have

``````(72 beats / minute) * 1.5 minutes / (5 beats / bar) + 1 = bar 22.6
``````

That is, it's the third beat of the five in bar 22.

• The only problem being that bar 1 doesn't always begin at 0:00 in an audio recording Oct 31, 2021 at 1:00
• Bar 22.6 should be the fourth beat of bar 22 (22.0 is beat 1, 22.2 is 2, ...) Oct 31, 2021 at 1:03
• The real problem with this is that musical performers don't keep exact time, and indeed, if you listen to music in exact time, it often seems a little wrong. You'll likely be off by a second or two with any calculation. Oct 31, 2021 at 2:18
• Marking this as the answer because it helped me to get this formula working in Google Sheets: `=((BPM*SECONDS)/60)/4+1` Oct 31, 2021 at 2:33
• This is logical and mathematically sound, but music isn’t always like this. Another problem is that sometimes there’s a pause or a bar or two with a different time sig or a rubato or ral. or rit. or meno mosso. But since "all models are wrong, some models are useful", this would give a decent ball park number, even if it’s inaccurate.
– Pam
Oct 31, 2021 at 12:01

To make this work, you have to know how many beats constitute a bar. To get that, you need to listen to the song and determine where the downbeats are and how many beats separate each downbeat. The downbeat tells you where the bar starts, and total beats until the next downbeat tells you how many beats are in each bar. From there, you calculate the total number of beats up to the point of the note of interest and divide by the beats per bar. Calculating the total number of beats can be done by knowing the bpm and time location of the note in question.

I'll go ahead and address the question in the title: "is it possible" ... and answer "only rarely!" Here's a rundown of reasons it might not work:

• Silence at the start of the track. Rarely, in a recorded track, is there audio at 0:00 exactly. If you're at 60bpm, and there are 2 seconds of silence at the beginning, your beat count is off by two. Ok, so you could factor in an algorithm that starts counting from the first signal.
• Pickups. Sometimes the very first beat or two aren't part of the first bar, but are "before" the first bar. Consider the Christmas song "The First Noël." The first two notes, sung to the word "The," are a "pickup." The first bar actually begins with the word "First." So your algorithm would have to not only detect audio, but do beat detection, and on top of that detect strong beats vs weak to try to find the "downbeat," the beginning of a measure. If the first downbeat is preceded by half a measure or less of "extra" notes, they count as bar 0, a "pickup" bar.
• Tempo changes. The algorithm is a simple calculation for a track that simply picks one BPM and sticks to it throughout. There are some genres, like a lot of electronic music, where this might be common enough, but there are also some where it would be the exception rather than the rule. French Impressionist music has an official tempo change every couple of measures (and "unofficial" ebbs and flows from beat to beat). But what about a nice Sousa march? Surely there's nothing squarer; a march is all about keeping a steady tempo. But oh wait, there's that one spot in "Stars & Stripes Forever" where it slows down...
• Rubato. This is a different kind of tempo change; rather than actually changing to a new BPM for a section of the work, this is about simply stretching or squeezing individual beats, on purpose, for expressive purposes. You could find, out of 10 different beats, 10 different durations, differing by milliseconds or even several seconds. And the distinction isn't specified in the score, maybe not even mentioned, but at the discretion of the performer.

So ultimately, to pull all this off programmatically, for anything other than a track in which beat 1 starts at 0:00 and the BPM is rock steady throughout, it would require not only a simple mathematical algorithm, but an AI that is trained to recognize beats and map fluctuations. While beat detection is certainly a thing, in my experience, it takes a lot of human correction and doesn't do well with flexible tempo.

• I'd add that even music that sounds like it keeps a constant tempo throughout will usually have subtle-but-significant fluctuations. Only for music that has been recorded on a clicktrack the concept of “song BPM” is really well-defined. Oct 31, 2021 at 20:15