Skip to main content

Crate chord_detector

Crate chord_detector 

Source
Expand description

§chord_detector

A unified crate for real‐time audio analysis: compute 12‐bin chromagrams and detect musical chords with minimal latency.

§Example

use chord_detector::{Chromagram, ChordDetector};

fn run() -> Result<(), Box<dyn std::error::Error>> {
    // 1) Build a chromagram pipeline
    let mut chroma = Chromagram::builder()
        .frame_size(1024)
        .sampling_rate(48_000)
        .build()?;

    // 2) Build a chord detector
    let mut detector = ChordDetector::builder()
        .bleed(0.15)
        .build();

    // 3) In your audio loop:
    let audio_frame: Vec<f32> = vec![0.0; 1024]; // fill with actual samples
    if let Some(chroma_bins) = chroma.next(&audio_frame)? {
        let chord = detector.detect_chord(&chroma_bins)?;
        println!(
            "Detected {:?} {:?} chord with confidence {:.3}",
            chord.root,
            chord.quality,
            chord.confidence
        );
    }

    Ok(())
}

§Features

  • chromagram (default): enables FFT‐based chromagram via rustfft

Re-exports§

pub use chord_detector::Chord;
pub use chord_detector::ChordDetector;
pub use chord_detector::ChordDetectorBuilder;
pub use chord_detector::ChordError;
pub use chord_detector::ChordKind;
pub use chord_detector::NoteName;
pub use chromagram::Chromagram;
pub use chromagram::ChromagramBuilder;
pub use chromagram::ChromagramError;

Modules§

chord_detector
Chord detection module. Chord Detector
chromagram
Chromagram computation module. Chromagram