| Crates.io | bpm-analyzer |
| lib.rs | bpm-analyzer |
| version | 0.2.0 |
| created_at | 2026-01-20 20:43:19.305636+00 |
| updated_at | 2026-01-20 22:46:16.711984+00 |
| description | A simple library for calculating the BPM |
| homepage | https://github.com/not-jan/bpm-analyzer |
| repository | https://github.com/not-jan/bpm-analyzer |
| max_upload_size | |
| id | 2057531 |
| size | 201,021 |
A real-time BPM (beats per minute) detection library and application for Rust, using wavelet decomposition and autocorrelation analysis.
Based on Audio Analysis using the Discrete Wavelet Transform by George Tzanetakis, Georg Essl and Perry Cook.
The BPM analyzer uses a sophisticated multi-stage signal processing pipeline:
Add this to your Cargo.toml:
[dependencies]
bpm-analyzer = "0.1"
use bpm_analyzer::{AnalyzerConfig, begin};
fn main() -> Result<(), bpm_analyzer::Error> {
// Configure the analyzer
let config = AnalyzerConfig::builder()
.min_bpm(60.0)
.max_bpm(180.0)
.build();
// Start the analyzer with default device
let bpm_receiver = begin(config)?;
// Process BPM detections
for detection in bpm_receiver.iter() {
if let Some(bpm) = detection.bpm() {
println!("Detected BPM: {:.1}", bpm);
}
// Access beat timings
for beat in detection.beat_timings() {
println!("Beat at {:.2}s (strength: {:.2})", beat.time_seconds, beat.strength);
}
// Get the interval between last two beats
if let Some(interval) = detection.last_beat_interval() {
println!("Last beat interval: {:.3}s", interval);
}
}
Ok(())
}
use bpm_analyzer::{AnalyzerConfig, begin_with_device, list_audio_devices, get_device_by_name};
// List all available devices
let devices = list_audio_devices()?;
for device in &devices {
println!("{} {}", device.name, if device.is_default { "(default)" } else { "" });
}
// Use a specific device by name
let config = AnalyzerConfig::electronic();
let device = get_device_by_name("BlackHole 2ch")?;
let receiver = begin_with_device(config, &device)?;
for detection in receiver.iter() {
if let Some(bpm) = detection.bpm() {
println!("Detected BPM: {:.1}", bpm);
}
}
Run the GUI application:
cargo run --release --features bin
With custom BPM range:
cargo run --release --features bin -- --min-bpm 80 --max-bpm 160
-m, --min-bpm <MIN_BPM>: Minimum BPM to detect (default: 40)-M, --max-bpm <MAX_BPM>: Maximum BPM to detect (default: 240)The analyzer behavior can be customized using AnalyzerConfig:
let config = AnalyzerConfig::builder()
.min_bpm(40.0) // Minimum BPM to detect
.max_bpm(240.0) // Maximum BPM to detect
.window_size(65536) // Analysis window size (must be power of 2)
.queue_size(4096) // Audio queue size
.buffer_size(256) // Audio capture buffer size
.build();
For system audio capture, install BlackHole:
brew install blackhole-2ch
Then configure your system to route audio through BlackHole using a multi-output device.
This library builds on several excellent Rust crates: