A high-performance command-line tool written in C that detects the BPM (Beats Per Minute) of MP3 files. Uses parallel processing and efficient signal processing algorithms for quick and accurate tempo detection.
- Fast MP3 decoding using libmpg123
- OpenMP parallelization for performance
- Adaptive thresholding for beat detection
- Supports both mono and stereo MP3 files
- Memory-efficient streaming processing
- Handles BPM ranges from 60 to 200 BPM
You need MinGW-w64 and MSYS2 installed on your Windows system. The following libraries are required:
- libmpg123 (for MP3 decoding)
- OpenMP (for parallel processing)
See Releases
-
Install MSYS2 from https://www.msys2.org/
-
Open MSYS2 terminal and install required packages:
pacman -Syu
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-mpg123
- Clone this repository:
git clone https://github.com/badcircle/bpm.git
cd bpm
- Compile the program:
gcc -O3 -fopenmp bpm.c -o bpm.exe -I"C:/msys64/mingw64/include" -L"C:/msys64/mingw64/lib" -lmpg123
.\bpm.exe path\to\your\music.mp3
Example output:
Sample rate: 44100 Hz
Channels: 2
Reading MP3 data...
Read 7654321 mono samples
Number of analysis frames: 14876
Calculating energy...
Detecting onsets...
Found 328 onsets
Calculating BPM...
Median interval: 0.416667 seconds
Estimated BPM: 144
- Audio Decoding: Uses libmpg123 to efficiently decode MP3 files into raw PCM data
- Mono Conversion: Converts stereo audio to mono for consistent processing
- Energy Analysis: Calculates energy levels across small windows of audio data
- Onset Detection: Uses adaptive thresholding to detect significant changes in energy
- BPM Calculation: Analyzes intervals between onsets to determine the dominant tempo
- Mean represents the average "background" level of the song
- Max represents the loudest peak/moment
- Standard deviation tells us how much the song typically varies from that background level
- Threshold is our "this is probably a beat" cutoff point, set above the normal variation (mean + 1.5 * std_dev)
The program uses several optimizations for performance:
- OpenMP parallel processing for frame analysis
- Efficient memory management with streaming processing
- Optimized signal processing algorithms
- Compiler optimizations (-O3 flag)
- Designed for music with clear beats
- Works best with BPM range of 60-200
- May need parameter adjustments for certain genres
- Currently supports MP3 format only
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.