3 unstable releases
0.2.0 | Nov 8, 2021 |
---|---|
0.1.1 | Sep 28, 2021 |
0.1.0 | Sep 28, 2021 |
#573 in Audio
85KB
997 lines
irapt
An implementation of the IRAPT pitch estimation algorithm.
Contributing Bug Reports
GitHub is the project's bug tracker. Please search for similar existing issues before submitting a new one.
License
Licensed under AGPL-3.0.
lib.rs
:
irapt
is an implementation of the IRAPT pitch estimation algorithm.
IRAPT is an "instantaneous" version of the Robust Algorithm for Pitch Tracking (RAPT).
Usage
Currently, the parameters to Irapt
are technical and may be difficult to tune, but the
Parameters::default
provides a sensible set of defaults for ordinary human speech which is computationally
efficient, given the input can be resampled to the default Parameters::sample_rate
.
The input must be given as a VecDeque
to Irapt::process
which is to facilitate the sliding analysis window.
The number of samples removed from the buffer by process
can be calculated on each invocation in order to track
the global sample index at which each pitch is estimated:
use irapt::{Irapt, Parameters};
use std::collections::VecDeque;
use std::f64::consts::PI;
let parameters = Parameters::default();
let mut irapt = Irapt::new(parameters.clone()).expect("the default parameters should be valid");
let mut sample_buffer = (0..parameters.sample_rate as usize)
.map(|sample_index| f64::sin(sample_index as f64 / parameters.sample_rate * 2.0 * PI * 100.0))
.collect::<VecDeque<_>>();
let mut sample_index = 0;
while let (initial_sample_buffer_len, Some(output)) = (
sample_buffer.len(),
irapt.process(&mut sample_buffer),
) {
let estimated_pitch = output.pitch_estimates().final_estimate();
let estimated_pitch_index = (sample_index as isize + estimated_pitch.offset) as usize;
let estimated_pitch_time = estimated_pitch_index as f64 / parameters.sample_rate;
println!("estimated pitch at {:0.3}: {}Hz with energy {}",
estimated_pitch_time, estimated_pitch.frequency, estimated_pitch.energy);
sample_index += initial_sample_buffer_len - sample_buffer.len();
}
Dependencies
~3.5MB
~68K SLoC