BpmDetection

Struct BpmDetection 

Source
pub struct BpmDetection { /* private fields */ }
Expand description

Result from BPM detection containing up to 5 candidates sorted by confidence.

Implementations§

Source§

impl BpmDetection

Source

pub fn from_array(arr: [(f32, f32); 5]) -> Self

Creates a new detection result from an array of candidates.

Source

pub fn with_beats(arr: [(f32, f32); 5], beat_timings: Vec<BeatTiming>) -> Self

Creates a new detection result with beat timings.

Source

pub fn top_candidate(&self) -> Option<&BpmCandidate>

Returns the top BPM candidate (highest confidence).

Source

pub fn candidates(&self) -> &[BpmCandidate]

Returns all candidates.

Source

pub fn bpm(&self) -> Option<f32>

Returns the most likely BPM value.

Examples found in repository?
examples/beat_timing.rs (line 21)
8fn main() -> Result<(), bpm_analyzer::Error> {
9    // Configure the analyzer for electronic music
10    let config = AnalyzerConfig::electronic();
11
12    println!("Starting BPM analyzer...");
13    println!("Listening for beats and tempo...\n");
14
15    // Start the analyzer
16    let receiver = begin(config)?;
17
18    // Process detections
19    for detection in receiver.iter() {
20        // Print BPM if detected
21        if let Some(bpm) = detection.bpm() {
22            println!("🎵 Detected BPM: {:.1}", bpm);
23        }
24
25        // Print beat timings
26        if let Some(last_beat) = detection.last_beat() {
27            print!(
28                "🥁 Beat at {:.2}s (strength: {:.2})",
29                last_beat.time_seconds, last_beat.strength
30            );
31
32            // Show beat interval if we have at least 2 beats
33            if let Some(interval) = detection.last_beat_interval() {
34                let instant_bpm = 60.0 / interval;
35                print!(" | Interval: {:.3}s ({:.1} BPM)", interval, instant_bpm);
36            }
37            println!();
38        }
39
40        // Print all recent beat timings
41        let beats = detection.beat_timings();
42        if beats.len() >= 4 {
43            println!("📊 Recent beats: {} detected", beats.len());
44            for (i, beat) in beats.iter().rev().take(4).enumerate() {
45                println!(
46                    "   {} {:.2}s ago (strength: {:.2})",
47                    if i == 0 { "•" } else { " " },
48                    beats.last().unwrap().time_seconds - beat.time_seconds,
49                    beat.strength
50                );
51            }
52        }
53
54        println!();
55    }
56
57    Ok(())
58}
Source

pub fn in_range(&self, min: f32, max: f32) -> Vec<BpmCandidate>

Returns candidates within a specific BPM range.

Source

pub fn beat_timings(&self) -> &[BeatTiming]

Returns the detected beat timings.

Examples found in repository?
examples/beat_timing.rs (line 41)
8fn main() -> Result<(), bpm_analyzer::Error> {
9    // Configure the analyzer for electronic music
10    let config = AnalyzerConfig::electronic();
11
12    println!("Starting BPM analyzer...");
13    println!("Listening for beats and tempo...\n");
14
15    // Start the analyzer
16    let receiver = begin(config)?;
17
18    // Process detections
19    for detection in receiver.iter() {
20        // Print BPM if detected
21        if let Some(bpm) = detection.bpm() {
22            println!("🎵 Detected BPM: {:.1}", bpm);
23        }
24
25        // Print beat timings
26        if let Some(last_beat) = detection.last_beat() {
27            print!(
28                "🥁 Beat at {:.2}s (strength: {:.2})",
29                last_beat.time_seconds, last_beat.strength
30            );
31
32            // Show beat interval if we have at least 2 beats
33            if let Some(interval) = detection.last_beat_interval() {
34                let instant_bpm = 60.0 / interval;
35                print!(" | Interval: {:.3}s ({:.1} BPM)", interval, instant_bpm);
36            }
37            println!();
38        }
39
40        // Print all recent beat timings
41        let beats = detection.beat_timings();
42        if beats.len() >= 4 {
43            println!("📊 Recent beats: {} detected", beats.len());
44            for (i, beat) in beats.iter().rev().take(4).enumerate() {
45                println!(
46                    "   {} {:.2}s ago (strength: {:.2})",
47                    if i == 0 { "•" } else { " " },
48                    beats.last().unwrap().time_seconds - beat.time_seconds,
49                    beat.strength
50                );
51            }
52        }
53
54        println!();
55    }
56
57    Ok(())
58}
Source

pub fn last_beat(&self) -> Option<&BeatTiming>

Returns the most recent beat timing, if available.

Examples found in repository?
examples/beat_timing.rs (line 26)
8fn main() -> Result<(), bpm_analyzer::Error> {
9    // Configure the analyzer for electronic music
10    let config = AnalyzerConfig::electronic();
11
12    println!("Starting BPM analyzer...");
13    println!("Listening for beats and tempo...\n");
14
15    // Start the analyzer
16    let receiver = begin(config)?;
17
18    // Process detections
19    for detection in receiver.iter() {
20        // Print BPM if detected
21        if let Some(bpm) = detection.bpm() {
22            println!("🎵 Detected BPM: {:.1}", bpm);
23        }
24
25        // Print beat timings
26        if let Some(last_beat) = detection.last_beat() {
27            print!(
28                "🥁 Beat at {:.2}s (strength: {:.2})",
29                last_beat.time_seconds, last_beat.strength
30            );
31
32            // Show beat interval if we have at least 2 beats
33            if let Some(interval) = detection.last_beat_interval() {
34                let instant_bpm = 60.0 / interval;
35                print!(" | Interval: {:.3}s ({:.1} BPM)", interval, instant_bpm);
36            }
37            println!();
38        }
39
40        // Print all recent beat timings
41        let beats = detection.beat_timings();
42        if beats.len() >= 4 {
43            println!("📊 Recent beats: {} detected", beats.len());
44            for (i, beat) in beats.iter().rev().take(4).enumerate() {
45                println!(
46                    "   {} {:.2}s ago (strength: {:.2})",
47                    if i == 0 { "•" } else { " " },
48                    beats.last().unwrap().time_seconds - beat.time_seconds,
49                    beat.strength
50                );
51            }
52        }
53
54        println!();
55    }
56
57    Ok(())
58}
Source

pub fn last_beat_interval(&self) -> Option<f64>

Returns the time interval between the last two beats, if available.

Examples found in repository?
examples/beat_timing.rs (line 33)
8fn main() -> Result<(), bpm_analyzer::Error> {
9    // Configure the analyzer for electronic music
10    let config = AnalyzerConfig::electronic();
11
12    println!("Starting BPM analyzer...");
13    println!("Listening for beats and tempo...\n");
14
15    // Start the analyzer
16    let receiver = begin(config)?;
17
18    // Process detections
19    for detection in receiver.iter() {
20        // Print BPM if detected
21        if let Some(bpm) = detection.bpm() {
22            println!("🎵 Detected BPM: {:.1}", bpm);
23        }
24
25        // Print beat timings
26        if let Some(last_beat) = detection.last_beat() {
27            print!(
28                "🥁 Beat at {:.2}s (strength: {:.2})",
29                last_beat.time_seconds, last_beat.strength
30            );
31
32            // Show beat interval if we have at least 2 beats
33            if let Some(interval) = detection.last_beat_interval() {
34                let instant_bpm = 60.0 / interval;
35                print!(" | Interval: {:.3}s ({:.1} BPM)", interval, instant_bpm);
36            }
37            println!();
38        }
39
40        // Print all recent beat timings
41        let beats = detection.beat_timings();
42        if beats.len() >= 4 {
43            println!("📊 Recent beats: {} detected", beats.len());
44            for (i, beat) in beats.iter().rev().take(4).enumerate() {
45                println!(
46                    "   {} {:.2}s ago (strength: {:.2})",
47                    if i == 0 { "•" } else { " " },
48                    beats.last().unwrap().time_seconds - beat.time_seconds,
49                    beat.strength
50                );
51            }
52        }
53
54        println!();
55    }
56
57    Ok(())
58}

Trait Implementations§

Source§

impl Clone for BpmDetection

Source§

fn clone(&self) -> BpmDetection

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BpmDetection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,