1

Is there any possibility that I can get the beat rate (beats per minute or beats per second) of an audio file placed on my server, through PHP. The main scenario is I have some audio file(mp3, wav etc) in some location on my server and I've to categorize them according to their beat rate.


I got this: http://pear.php.net/reference/MP3_IDv2-0.1.4/__filesource/fsource_MP3_IDv2__MP3_IDv2-0.1.4IDv2FrameTBPM.php.html

Can anyone please explaing how to use the function getBPM()

ChrisF
  • 134,786
  • 31
  • 255
  • 325
Irfan Younus
  • 174
  • 2
  • 6

3 Answers3

2

I wrote a simple php class for BPM detection in audio files. It uses soundtouch and ffmpeg to get the BPM. You can get it here - php-bpm-detect

deseven
  • 54
  • 3
1

You could try calling the SoundTouch audio processing library from php after installing it on the server.

The FAQ states that it can detect BPM. I do not know if it can handle mp3 files, but then you could use ffmpeg to convert them to wav and then run the bpm detection.

Please Check the link for more info.

SoundStretch audio processing utility

Surojit
  • 1,282
  • 14
  • 26
  • I've gone through the link which u provided above, i dint find any documentation of it for PHP. – Irfan Younus Apr 23 '13 at 13:57
  • Because this program is not written in PHP. but you can use it with `exec()` PHP function (that launches external application). All you have to do is compile program from link, that won't be very hard. You don't have to learn new language, but learn to compile-it's always useful. – Wookie88 Apr 23 '13 at 14:03
  • I dint get u, please explain a litle. – Irfan Younus Apr 23 '13 at 14:40
  • 1
    [Compiling soundtouch on gnu](http://www.surina.net/soundtouch/README.html) Read the section 2.2. Once you have compiled it and installed it on the server, you can call it using php exec() function. eg. `$bpm=exec('soundtouch abcxyz.wav -bpm')`. Please note that this is only an approximate procedure. – Surojit Apr 23 '13 at 15:19
  • Good call on soundtouch just been looking at that myself for something else. – Dave Apr 24 '13 at 14:14
0

Beat rate (BPM) can be calculated in many ways. First of all you need to find how to detect beats which are nothing but local peaks of sound energy. Supposing you want to analyse WAV file it would be best to search whole file sample-by-sample and find high differences between consecutive samples. How big differences? It is hard to tell, you will have to try with different values (different detection threshold). MP3 detection is harder because it is also compressed.

Here are some other ideas:

How to detect the BPM of a song in php

BTW: Are you sure you want to use PHP for BPM detection? If you have server you can probably use also other langages, like C/C++ launched as cgi script. It would be much more memory- and cpu-effective.

Good luck with your project!

EDIT: Try to use Google to find different projects, but covering the same topic (wav analysis), e.x. http://www.ixwebhosting.mobi/2011/09/20/3445.html - project that draws oscillogram from WAV file and saves it to PNG. If it draws waveform you are one step ahead-now you have to implement algorithm to not draw sample values but analyse them to find beats.

Community
  • 1
  • 1
Wookie88
  • 33,079
  • 4
  • 27
  • 32
  • I've to do it on server side with PHP :( – Irfan Younus Apr 23 '13 at 13:18
  • the main idea is that i have to reflect them in a categorized manner (with respect to beat rate) on some remote source. Files are on server, and only server side language I know is PHP :) – Irfan Younus Apr 23 '13 at 13:21
  • I've edited my post, try this link and searching google more. It can be difficult to find proper algorithm in PHP, you will probably need to find algorithm in different language for reference and try to translate it into PHP. – Wookie88 Apr 23 '13 at 13:25
  • Try using library posted in other answer by neur0tic. – Wookie88 Apr 23 '13 at 14:04
  • It does not have any documentation, explaining how to use it with PHP. – Irfan Younus Apr 23 '13 at 15:21