yin

Crates.ioyin
lib.rsyin
version0.2.0
sourcesrc
created_at2020-07-21 21:22:19.146959
updated_at2020-07-27 00:14:57.993756
descriptionA library for fundamental frequency estimation of periodic signals
homepagehttps://github.com/saresend/yin
repositoryhttps://github.com/saresend/yin
max_upload_size
id267794
size8,136
Samuel Resendez (saresend)

documentation

README

Yin: Frequency Estimation For Rust

Yin provides a function for estimating the fundamental frequency of a signal, based on the following article:

[1] De Cheveigné, A., & Kawahara, H. (2002). YIN, a fundamental frequency estimator for speech and music. The Journal of the Acoustical Society of America, 111(4), 1917-1930.

Link to Paper

Installation

Add the following to your Cargo.toml

yin = "0.1.0"

Usage

        // Configure params for our estimator, see docs for details
        let estimator = Yin::init(0.1, 10.0, 30.0, 80);
        let mut example = vec![];
        let mut prev_value = -1.0;
        // Periodic over every 4 values of i, giving us a frequency of: 80 / 4 == 20
        for i in 0..80 {
            if i % 2 != 0 {
                example.push(0.0);
            } else {
                prev_value *= -1.0;
                example.push(prev_value);
            }
        }
        let freq = estimator.estimate_freq(&example);
        assert_eq!(freq, 20.0);

Benchmarks

At the time of writing I have not taken too much time to optimize this implementation, and will be looking at improving the speed of this as needed. Current benchmark timings listed below:

44100hz sample rate, 100hz frequency, 160hz search range: [ 2.4157 ms 2.4244 ms 2.4330 ms ]

Benchmarks are done using criterion, and can be run by cloning the repository and using cargo bench

Commit count: 32

cargo fmt