IPB

Welcome Guest ( Log In | Register )

8 Pages V   1 2 3 > »   
Reply to this topicStart new topic
foo_bpm, Automatic song BPM analysis
fraganator
post Dec 21 2009, 16:33
Post #1





Group: Developer
Posts: 155
Joined: 22-March 06
Member No.: 28717



Updated to version 0.2.4.1. Download here: foo_bpm 0.2.4.1
From the changelist:

0.2.4.1 (20/04/2010)
- A few more bug fixes. Songs where the sample rate can not be queried will have the BPM set to zero.
- Context menu option to double/halve BPMs of selected tracks

0.2.4 (01/02/2010)
- Recompiled to include static link the Visual Studio 2008 Runtime. Download the static version if you're having runtime problems.

0.2.4 (12/01/2010)
- Crash report fix (component about info)

0.2.3 (11/01/2010)
- Updated to foobar2000 1.0 SDK
- Added double/halve buttons to results dialog
- Added option to auto write tags after analysis
- Limit preference range inputs
- Crash report fix (using info not yet cached)

Please note: foobar2000 1.0 is now the minimum supported version.

You can access the manual BPM calculation window through the context menu (right-click->BPM Analysis->Manually tap BPM for current track). Clicking the Update Tag button will write the BPM to the currently playing file.

No changes have been made to the algorithm itself, but the parameters are now available for tweaking. You will probably have the most luck experimenting with the "Samples Per Song" value, followed by "Seconds Per Sample". Try increasing one or both, though calculation speed will take a hit.

Here's a quick overview of some of the parameters:
"Seconds Per Sample" - The number of seconds of audio grabbed from the file at any one time. The result of this sample produces a single BPM value.
"Samples Per Song" - The number of times we grab an audio sample from the file. This determines the size of the final list of candidate BPMs.
"Sample Offset (Min/Max)" - When grabbing audio samples from a file, start from the minimum offset and move towards the max offset. These values are used to avoid slow fade in or fade outs of songs.
"Calculated BPM (Min/Max)" - Limits the range of the BPM calculation to these values. Change the min and max to suit particular styles of music (e.g. 70-110 for hip-hop, 150-200 for d'n'b, etc)

-----------------------------

Hi everyone,

I'd like to introduce my first foobar2000 component: foo_bpm

As the name suggests, it is designed to calculate the BPMs (beats per minute) of any tracks in foobar2000.

I like to DJ a bit in my spare time, and I also buy a fair number of CDs for DJing and general listening. The problem is when DJing, I'm not familiar enough with the tempo of my new tunes to drop them straight into mixes. So I wrote this component so I could use the foobar2000 to sort and manage new tracks by their BPM, helping me select new tracks to play with a minimum of fuss. The component could also presumably be used to come up with playlists of a certain tempo for exercise workouts, etc.

The BPM analysis algorithm is based loosely on the work presented in the paper Tempo and Beat Estimation of Musical Signals (pdf).

Here's a brief overview of how it works:
1. Grab a 10 second sample from the song
2. Transform the sample from the time domain into the frequency domain using windowed, overlapping FFTs, also know as Short Time Fourier Transforms (STFTs).
3. Onset (or beat) detection is performed on the resulting STFT. The onset detection function takes the spectral flux of the STFT to generate a list of candidate beats.
4. The candidate beats are run through an auto-correlation function to determine the dominant beat frequency, and hence the BPM.
5. These steps are repeated at different points throughout the song, resulting in a list of candidate BPMs.
6. The BPM list is sorted and the average mode value is chosen as the BPM.

The FFTW library is used for calculating the FFT. A dll for this library is included with foo_bpm.


Download:
foo_bpm 0.2.4.1

Installation:
- Download the above 7zip file.
- Unzip foo_bpm.dll to the foobar2000 components directory
- Unzip libfftw.dll to the foobar2000 directory (NOT the components directory)

Usage:
- Highlight one or more files in your playlist. Rightclick on them and select "BPM Analysis->Automatically analyse BPMs..."
- After the analysis has completed, the results are automatically written to the "BPM" field of the tag.
- If the BPM field already exists for a song, it will NOT be overwritten.

Known Problems:
- The calculated BPMs are not always accurate, especially for songs without obvious beats or large changes in tempo. You can compare the accuracy of the calculated BPM with the included manual BPM tapping function.
- In a number of cases a song's BPM may be calculated as double or half of its 'true' BPM. So don't be alarmed if you see some obviously slow R'n'B songs with BPMs of 180 or more! They are actually half of that.
- Songs shorter than 10 seconds will automatically have their BPM set to 0. This is by design as it isn't possible to accurately determine the BPM of such a short track.
- There can be large discrepancies between BPMs calculated to the nearest BPM and BPMs calculated to 1 or 2 decimal places. I would recommend using either 1 or 2 decimal places as they seem to be closer to the real BPM.
- Tapping the spacebar on the manual tapping window when the large Tap Here button loses focus will stop working. The button must be clicked again to regain focus so the spacebar will work.
- BPMs calculated for the same song at different bitrates (eg mp3 V0 vs mp3 V5) can have significantly different results. This relates to the spectral flux calculation and will be improved.

Future changes:
- Improve the current BPM algorithm (wrong BPMs, double/halved BPMs, overall speed)
- Implement other BPM algorithms such as this and this
- Add a menu option and dialog window with a button to manually calculate the BPM by tapping/clicking along with the current playing song- DONE
- Add a confirmation dialog after a BPM scan has completed before writing the values to the files (similar to ReplayGain) - DONE
- Add option to double/halve individual calulated BPMs if need be. - DONE Will also add to context menu. - ALSO DONE
- Add a properties page with all of the algorithm parameters available for tweaking - DONE
- Specialise the algorithm parameters for different genres, then automatically scan using those parameters based on the GENRE tag
- Cleanup and release the source code - DONE
- Handle manual BPM calculation when button is pressed down, not released


Please download it and let me know what you think! smile.gif

This post has been edited by fraganator: Apr 20 2010, 14:17
Go to the top of the page
+Quote Post
Canar
post Dec 21 2009, 16:51
Post #2





Group: Super Moderator
Posts: 3370
Joined: 26-July 02
From: princegeorge.ca
Member No.: 2796



Very nice! I need to test it out first, but I'm not sure I'd have been able to come up with a better algorithm. I'm excited for the source-code release of this.


--------------------
You cannot ABX the rustling of jimmies.
No mouse? No problem.
Go to the top of the page
+Quote Post
blonde
post Dec 21 2009, 17:23
Post #3





Group: Members
Posts: 59
Joined: 17-July 07
From: Eastern Canada
Member No.: 45402



Very cool! Looking forward to trying this. Thanks!
Go to the top of the page
+Quote Post
Keesface
post Dec 21 2009, 17:25
Post #4





Group: Members
Posts: 96
Joined: 23-November 09
From: The Netherlands
Member No.: 75220



I'm gonna try this, sounds very cool!

Will it also be possible to use the bpm value in title formatting? (something like %BPM%)
Go to the top of the page
+Quote Post
kode54
post Dec 21 2009, 17:30
Post #5





Group: Admin
Posts: 4625
Joined: 15-December 02
Member No.: 4082



QUOTE (Keesface @ Dec 21 2009, 08:25) *
Will it also be possible to use the bpm value in title formatting? (something like %BPM%)

Since the results are written to the file tags, it should be possible to use %bpm% for any file which has already been scanned.
Go to the top of the page
+Quote Post
fraganator
post Dec 21 2009, 17:32
Post #6





Group: Developer
Posts: 155
Joined: 22-March 06
Member No.: 28717



Yep, that's not a problem. I have a column in my playlist to display %BPM% and it works just fine, so it should be available anywhere in foobar2000 you can use % style formatting.

Edit: What kode54 said smile.gif
Go to the top of the page
+Quote Post
Keesface
post Dec 21 2009, 17:37
Post #7





Group: Members
Posts: 96
Joined: 23-November 09
From: The Netherlands
Member No.: 75220



I just found out, it's awesome!


p.s. The command in my context menu is still under legacy commands, could you make a separate context group for it?

This post has been edited by Keesface: Dec 21 2009, 17:39
Go to the top of the page
+Quote Post
Jack Schmaltz
post Dec 21 2009, 17:43
Post #8





Group: Members
Posts: 216
Joined: 7-November 08
From: H:N:L, UK
Member No.: 61899



thanks for this, just having a play with it now by throwing it at various styles of music.

one suggestion so far, would it be possible to have a Results Window open displaying the results once the analysis is complete?

thanks again


--------------------
http://www.discogs.com/user/jackschmaltz
Go to the top of the page
+Quote Post
fraganator
post Dec 21 2009, 17:47
Post #9





Group: Developer
Posts: 155
Joined: 22-March 06
Member No.: 28717



QUOTE (Keesface @ Dec 22 2009, 00:37) *
p.s. The command in my context menu is still under legacy commands, could you make a separate context group for it?

Are you using one of the fb2k 1.0 betas? The 1.0 SDK might need to be made available before I can change the context menu like that. Can anyone confirm this? I was thinking of just moving it under Utils or something anyways.

QUOTE (Jack Schmaltz)
one suggestion so far, would it be possible to have a Results Window open displaying the results once the analysis is complete?

Yep, it's on my do to list smile.gif
Go to the top of the page
+Quote Post
Keesface
post Dec 21 2009, 17:52
Post #10





Group: Members
Posts: 96
Joined: 23-November 09
From: The Netherlands
Member No.: 75220



QUOTE (fraganator @ Dec 21 2009, 17:47) *
QUOTE (Keesface @ Dec 22 2009, 00:37) *
p.s. The command in my context menu is still under legacy commands, could you make a separate context group for it?

Are you using one of the fb2k 1.0 betas? The 1.0 SDK might need to be made available before I can change the context menu like that. Can anyone confirm this? I was thinking of just moving it under Utils or something anyways.

Yes I'm using 1.0 beta 5. I forgot about the SDK, i think you're right there. Utils would be a good group i guess smile.gif
Go to the top of the page
+Quote Post
Jack Schmaltz
post Dec 21 2009, 17:53
Post #11





Group: Members
Posts: 216
Joined: 7-November 08
From: H:N:L, UK
Member No.: 61899



QUOTE (fraganator @ Dec 21 2009, 16:47) *
Yep, it's on my do to list smile.gif


ah, my apologies. i did read the to do list but obviously didn't sink in.

so far the results are very accurate with styles like Psy-Trance & Hardcore Techno, a bit off with some Breakcore/Hardcore Techno i have but the beats on the inaccurate results are fairly inconsistant anyway so isn't a fault of the component in my opinion.

looking forward to the development of this, thanks again


--------------------
http://www.discogs.com/user/jackschmaltz
Go to the top of the page
+Quote Post
fraganator
post Dec 21 2009, 18:01
Post #12





Group: Developer
Posts: 155
Joined: 22-March 06
Member No.: 28717



Autechre, Aphex Twin and Squarepusher were the yard sticks for the more extreme BPM tests and the component doesn't do too badly. You're right though that the results can be fairly inaccurate when it comes to genres like that. Hopefully things will improve!
Go to the top of the page
+Quote Post
Jack Schmaltz
post Dec 21 2009, 18:10
Post #13





Group: Members
Posts: 216
Joined: 7-November 08
From: H:N:L, UK
Member No.: 61899



if i can help in anyway with regards to testing & sending results etc. please let me know as i'd be more than happy to help, as like yourself i like to know the bpm's for dj'ing purposes & currently do it manually with a bpm counter.

regarding testing again, some Drum & Bass i have doesn't appear to perform greatly, with it either being spot on or very off. the off results having pretty consistant beats also.

i can see this component being my new fave biggrin.gif


--------------------
http://www.discogs.com/user/jackschmaltz
Go to the top of the page
+Quote Post
fraganator
post Dec 21 2009, 18:16
Post #14





Group: Developer
Posts: 155
Joined: 22-March 06
Member No.: 28717



Alright, that'd be cool. I'll PM you if I need some more testing done. What are the artists/names of some of the songs where the component gives poor results? I may have them in my collection.
Go to the top of the page
+Quote Post
Jack Schmaltz
post Dec 21 2009, 18:41
Post #15





Group: Members
Posts: 216
Joined: 7-November 08
From: H:N:L, UK
Member No.: 61899



some of the inaccurate ones so far:

I:gor - Icebreaker (foo_bpm:157.3 / manual bpm:200)
I:gor - God Left This Place (foo_bpm:171.0 / manual bpm:185)
I:gor - A Man With A Gun (foo_bpm:167.3 / manual bpm:185)
Nanotek - Better Place (foo_bpm: 116.1 / manual bpm:174)
Current Value - The Edge Of The Cliff (foo_bpm:132.4 / manual bpm:174)
Throttler - Overbrewed (foo_bpm:122.8 / manual bpm:184)
DJ G-I-S - Savage (Technical Itch Remix) (foo_bpm:119.9 / manual bpm:179)

i'm startled by this plugin, half the tracks i scan to try & catch it out work brilliantly, great work.
some come through at half bpm, but as you have already pointed this out & i have noticed the same behaviour previously with other auto bpm counters i won't add them as inaccurate.

This post has been edited by Jack Schmaltz: Dec 21 2009, 19:37


--------------------
http://www.discogs.com/user/jackschmaltz
Go to the top of the page
+Quote Post
Canar
post Dec 21 2009, 18:54
Post #16





Group: Super Moderator
Posts: 3370
Joined: 26-July 02
From: princegeorge.ca
Member No.: 2796



If the BPMs were simply normalized to between 100 and 200 it would be fine, I think. Doubled/halved BPMs are basically identical anyhow.


--------------------
You cannot ABX the rustling of jimmies.
No mouse? No problem.
Go to the top of the page
+Quote Post
odyssey
post Dec 22 2009, 11:27
Post #17





Group: Members
Posts: 2296
Joined: 18-May 03
From: Denmark
Member No.: 6695



Thanks! biggrin.gif

Any chance the written tag-field could be customized in the future?


--------------------
Can't wait for a HD-AAC encoder :P
Go to the top of the page
+Quote Post
fraganator
post Dec 22 2009, 16:31
Post #18





Group: Developer
Posts: 155
Joined: 22-March 06
Member No.: 28717



Thanks everyone for the encouraging comments. I'm just in the process of cleaning up the code, then will get stuck into the requests raised so far.

QUOTE (Jack Schmaltz @ Dec 22 2009, 01:41) *
some of the inaccurate ones so far:

<tracklist>

Thanks for the feedback. I'll look into the results when I have a chance.


QUOTE (odyssey @ Dec 22 2009, 18:27) *
Any chance the written tag-field could be customized in the future?

I shall add it to my to do list smile.gif
Go to the top of the page
+Quote Post
grimes
post Dec 22 2009, 23:07
Post #19





Group: Developer
Posts: 304
Joined: 12-November 07
From: Frankfurt
Member No.: 48701



Analysing BPMs... get stuck. Next track (album) has bpm-tag already!
Go to the top of the page
+Quote Post
fraganator
post Dec 23 2009, 15:04
Post #20





Group: Developer
Posts: 155
Joined: 22-March 06
Member No.: 28717



The plugin should skip over any tracks that already have the BPM tag.. so perhaps it's getting stuck not because the track already has a BPM tag, but for some other reason.

If you analyse each track in the album individually, does it still get stuck?
Go to the top of the page
+Quote Post
grimes
post Dec 23 2009, 15:30
Post #21





Group: Developer
Posts: 304
Joined: 12-November 07
From: Frankfurt
Member No.: 48701



analyzing smaller portions (per album) works, so it seems not to be a problem of the individual track. problem happens at track 668 of 11715. analyzing this amount was a little bit optimistic rolleyes.gif

EDIT: Happens again with smaller portions (about 1000 tracks). Here whole portion hangs but analyzing individual album works. It stops at last track of an album (a Jethro Tull bootleg) next album again already bpm-tagged. (Thick as a brick (studio))

This post has been edited by grimes: Dec 23 2009, 15:44
Go to the top of the page
+Quote Post
fraganator
post Dec 23 2009, 17:14
Post #22





Group: Developer
Posts: 155
Joined: 22-March 06
Member No.: 28717



OK, thanks for the feedback. Sounds like a bug when analysing large lists. The biggest I tested with was ~500 tracks, so I'll try out some 1000+ file lists to try reproduce the problem.
Go to the top of the page
+Quote Post
Case
post Dec 23 2009, 18:20
Post #23





Group: Developer (Donating)
Posts: 2260
Joined: 19-October 01
From: Finland
Member No.: 322



I scanned over 3000 tracks at once yesterday without trouble, so it's not about list size. Unrelated question: Is it intentional that you decode entire track and not just short snippet from it?
Go to the top of the page
+Quote Post
Sylph
post Dec 23 2009, 18:31
Post #24





Group: Members
Posts: 259
Joined: 1-February 08
Member No.: 50965



Reason unknown, but by right-clicking on a track in playlist, it won't show up. In beta 5.
Go to the top of the page
+Quote Post
fraganator
post Dec 23 2009, 18:35
Post #25





Group: Developer
Posts: 155
Joined: 22-March 06
Member No.: 28717



QUOTE (Case @ Dec 24 2009, 01:20) *
I scanned over 3000 tracks at once yesterday without trouble, so it's not about list size. Unrelated question: Is it intentional that you decode entire track and not just short snippet from it?

That's interesting about the playlist size. What file formats are your songs in grimes and Case? Also what are the sample rates, bit depth, number of channels, etc?

Only a short audio snippet (10 seconds) is used for a single BPM estimate, but that BPM estimate may be inaccurate. So to help ensure the correct BPM estimate is made, multiple 10 second snippets are taken from the song at different points and the BPMs calculated. So it may seem like the whole file is being decoded, but in reality it is multiple 10 second chunks of the file that are being decoded. So yes, it is by design smile.gif

QUOTE (Sylph @ Dec 24 2009, 01:31) *
Reason unknown, but by right-clicking on a track in playlist, it won't show up. In beta 5.

It's probably under Legacy Commands. I'll fix things up once the 1.0 SDK is out.
Go to the top of the page
+Quote Post

8 Pages V   1 2 3 > » 
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 22nd October 2014 - 01:14