Skip to content

Commit

Permalink
Return a pitch of 0 if the acf norm threshold was not reached
Browse files Browse the repository at this point in the history
  • Loading branch information
kgreenek committed Aug 6, 2018
1 parent ebf5886 commit 56a12bf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ pub mod pitch_extractor;
use pitch_extractor::{PitchExtractor, YinPitchExtractor};

pub const CHANNELS: usize = 1;
pub const RMS_THRESHOLD: f32 = 0.02;
pub const RMS_THRESHOLD: f32 = 0.03;

// TODO(kgreenek): Set these values at run-time as parameters independent of the sample rate.
// Reasonable values for a sample rate of 16khz.
const WINDOW_SIZE: usize = 100;
const PITCH_MAX_T: usize = 150;
pub const WINDOW_SIZE: usize = 100;
pub const PITCH_MAX_T: usize = 150;
// Reasonable values for a sample rate of 44.1khz.
//pub const WINDOW_SIZE: usize = 256;
//pub const PITCH_MAX_T: usize = 1024;
Expand Down
5 changes: 0 additions & 5 deletions src/pitch_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,12 @@ where
self.update_acf_norm();
for channel in 0..F::n_channels() {
self.pitch[channel] = 0;
let mut acf_norm_min_value = *self.acf_norm[0].channel(channel).unwrap();
for (frame_index, &acf_norm_frame) in self.acf_norm[..].iter().enumerate() {
let acf_norm_sample = acf_norm_frame.channel(channel).unwrap();
if *acf_norm_sample < 0.1.to_sample() {
self.pitch[channel] = frame_index;
break;
}
if *acf_norm_sample < acf_norm_min_value {
acf_norm_min_value = *acf_norm_sample;
self.pitch[channel] = frame_index;
}
}
}
self.pitch()
Expand Down

0 comments on commit 56a12bf

Please sign in to comment.