Some python code for calculating BPM and delay times

Some time ago I wrote this little script (I called it beatcalculator).

Pretty straightforward command line utility, use the switch –help to get help.

Here is the script, exported from emacs with htmlize-buffer: beatcalculator.

Copy and paste this code into a file called beatcalculator, put that file in your $PATH and give it execution privileges with chmod +x.

Then you can use it on the command line as simple calculator, providing the bpm you want to examine, or you can ask to analyze a wave file. you have to specify the number of bars contained in the wav file and optionally the meter (defaults to 4/4)

Here’s an example of the output you get (with a file with 2 bars of music):


$ beatcalculator -f afroeira123.6.wav -B 2

Meter is 4/4
--------------------------------------------------------------------------- 

afroeira123.6.wav is 3883 milliseconds
Bpm of afroeira123.6.wav is 123.62

123.62 beats per minute (bpm):

Note                            Delay time                       LFO freq
---------------------------------------------------------------------------
Whole                          1941.433 ms                        0.52 Hz
Dotted Half                    1456.075 ms                        0.69 Hz
Half                            970.717 ms                        1.03 Hz
Dotted Quarter                  728.038 ms                        1.37 Hz
Quarter                         485.358 ms                        2.06 Hz
Dotted Eight                    364.019 ms                        2.75 Hz
Quarter Triplet                 323.579 ms                        3.09 Hz
Eight                           242.679 ms                        4.12 Hz
Dotted Sixteenth                182.009 ms                        5.49 Hz
Eight Triplet                    161.78 ms                        6.18 Hz
Sixteenth                        121.34 ms                        8.24 Hz
Dotted Thirty Second             91.005 ms                       10.99 Hz
Sixteenth Triplet                  80.9 ms                       12.36 Hz
Thirty Second                     60.67 ms                       16.48 Hz

Hope you enjoy it.
Send me comments and suggestions to improve it.

About these ads
Tagged , , , ,

5 thoughts on “Some python code for calculating BPM and delay times

  1. hectorlopez says:

    Reblogged this on My personal Blog.

  2. Mike says:

    Hi , I was just asking myself what should I use and how your code to be able to make a python script that uses your script for analyse the bmp of a song as a function. I would appreciate some help ;).

    • emillo says:

      Hi, sorry for the long time to reply. Unfortunately, my script doesn’t analyze the bpm but only calculates it by dividing the lenght of the sample by the number of musical bars (provided as command line parameter), so it is useful only for short and well cut samples, not for entire songs.

      Regards

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 326 other followers

%d bloggers like this: