diffrhythm_ai

Crates.iodiffrhythm_ai
lib.rsdiffrhythm_ai
version67.0.17
created_at2026-01-04 07:21:57.733787+00
updated_at2026-01-04 07:21:57.733787+00
descriptionHigh-quality integration for https://diffrhythm.ai/
homepagehttps://diffrhythm.ai/
repositoryhttps://github.com/qy-upup/diffrhythm.ai
max_upload_size
id2021509
size9,846
(qy-upup)

documentation

README

diffrhythm.ai

This crate provides foundational algorithms and data structures for analyzing and manipulating rhythmic patterns. It offers tools for tasks such as beat detection, rhythm similarity comparison, and rhythmic transformation.

Installation

Add the following line to your Cargo.toml file under the [dependencies] section: toml diffrhythm-ai = "0.1.0" # Replace with the actual version number

Usage Examples

Here are a few examples demonstrating how to use the diffrhythm.ai crate.

1. Calculating Rhythmic Similarity:

This example demonstrates how to calculate the similarity between two rhythmic patterns represented as vectors of inter-onset intervals (IOIs). rust use diffrhythm_ai::rhythm::RhythmicPattern;

fn main() { let pattern1 = RhythmicPattern::new(vec![0.5, 0.5, 1.0, 0.5]); let pattern2 = RhythmicPattern::new(vec![0.5, 0.5, 0.75, 0.75]);

let similarity = pattern1.compare(&pattern2);

println!("Similarity between patterns: {}", similarity);

}

2. Beat Detection in a Time Series:

This example shows how to use the crate to perform basic beat detection on a simplified time series of event occurrences. rust use diffrhythm_ai::beat_detection::detect_beats;

fn main() { let time_series = vec![0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]; let beats = detect_beats(&time_series);

println!("Detected beats: {:?}", beats);

}

3. Rhythmic Transformation (Tempo Scaling):

This example demonstrates how to scale the tempo of a rhythmic pattern. rust use diffrhythm_ai::rhythm::RhythmicPattern;

fn main() { let mut pattern = RhythmicPattern::new(vec![0.25, 0.25, 0.5]); let original_tempo = pattern.tempo();

pattern.scale_tempo(2.0); // Double the tempo

let new_tempo = pattern.tempo();

println!("Original tempo: {}", original_tempo);
println!("New tempo: {}", new_tempo);

}

4. Normalizing Rhythmic Patterns:

This example demonstrates how to normalize a rhythmic pattern such that the sum of its inter-onset intervals (IOIs) equals 1.0. rust use diffrhythm_ai::rhythm::RhythmicPattern;

fn main() { let mut pattern = RhythmicPattern::new(vec![0.2, 0.3, 0.5]); pattern.normalize();

println!("Normalized pattern: {:?}", pattern.intervals);

}

5. Quantizing Rhythmic Values:

This example shows how to quantize a series of rhythmic values to a specific grid. This can be useful for aligning rhythms to a musical grid. rust use diffrhythm_ai::quantization::quantize_rhythm;

fn main() { let rhythmic_values = vec![0.1, 0.23, 0.35, 0.48, 0.62]; let quantization_grid = vec![0.0, 0.25, 0.5, 0.75, 1.0];

let quantized_values = quantize_rhythm(&rhythmic_values, &quantization_grid);

println!("Original values: {:?}", rhythmic_values);
println!("Quantized values: {:?}", quantized_values);

}

Feature Summary

  • Rhythmic Pattern Representation: Provides a RhythmicPattern struct for representing and manipulating rhythmic sequences.
  • Rhythm Similarity Comparison: Includes functions for comparing the similarity between different rhythmic patterns.
  • Beat Detection: Offers basic beat detection algorithms for identifying rhythmic pulses in time series data.
  • Rhythmic Transformation: Supports tempo scaling and other transformations of rhythmic patterns.
  • Normalization: Functionality to normalize rhythmic patterns.
  • Quantization: Methods for quantizing rhythmic values to a specified grid.

License

MIT

This crate is part of the diffrhythm.ai ecosystem. For advanced features and enterprise-grade tools, visit: https://diffrhythm.ai/

Commit count: 0

cargo fmt