Skip to content

Commit

Permalink
max_min: increase step_size to 2
Browse files Browse the repository at this point in the history
This brings another performance win of 5% while only losing accuracy on a
negligible level.
  • Loading branch information
phip1611 committed May 4, 2024
1 parent 0d908eb commit b537a84
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/beat_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ mod tests {
//
// As long as it is reasonable small, I think this is good, I guess?
// [0]: https://electronics.stackexchange.com/questions/372692/low-pass-filter-delay
Some(942)
Some(943)
);
assert_eq!(detector.update_and_detect_beat(core::iter::empty()), None);
}
Expand Down Expand Up @@ -245,13 +245,13 @@ mod tests {
let mut detector = BeatDetector::new(header.sampling_rate as f32, false);
assert_eq!(
simulate_dynamic_audio_source(256, &samples, &mut detector),
&[830]
&[829]
);

let mut detector = BeatDetector::new(header.sampling_rate as f32, false);
assert_eq!(
simulate_dynamic_audio_source(2048, &samples, &mut detector),
&[830]
&[829]
);
}

Expand All @@ -263,7 +263,7 @@ mod tests {
let mut detector = BeatDetector::new(header.sampling_rate as f32, false);
assert_eq!(
simulate_dynamic_audio_source(2048, &samples, &mut detector),
&[1310, 8639]
&[1311, 8639]
);
}

Expand All @@ -275,7 +275,7 @@ mod tests {
let mut detector = BeatDetector::new(header.sampling_rate as f32, true);
assert_eq!(
simulate_dynamic_audio_source(2048, &samples, &mut detector),
&[12936, 93794, 101457, 189599, 270784, 278469]
&[12935, 93793, 101457, 189599, 270783, 278469]
);
}

Expand All @@ -287,7 +287,7 @@ mod tests {
let mut detector = BeatDetector::new(header.sampling_rate as f32, false);
assert_eq!(
simulate_dynamic_audio_source(2048, &samples, &mut detector),
&[29077, 31225, 47052, 65812, 83769, 101994, 120138, 138130]
&[29077, 31225, 47051, 65813, 83769, 101995, 120139, 138129]
);
}

Expand All @@ -299,7 +299,7 @@ mod tests {
let mut detector = BeatDetector::new(header.sampling_rate as f32, true);
assert_eq!(
simulate_dynamic_audio_source(2048, &samples, &mut detector),
&[31334, 47164, 65922, 84221, 102108, 120247, 138561]
&[31333, 47165, 65923, 84221, 102109, 120247, 138561]
);
}
}
10 changes: 5 additions & 5 deletions src/envelope_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ mod tests {
let peak_sample_index = 1430;
assert_eq!(
find_descending_peak_trend_end(&history, peak_sample_index).map(|info| info.index),
Some(7098)
Some(7101)
)
}
// sample1: double beat
Expand All @@ -351,13 +351,13 @@ mod tests {
let peak_sample_index = 1634;
assert_eq!(
find_descending_peak_trend_end(&history, peak_sample_index).map(|info| info.index),
Some(6974)
Some(6979)
);

let peak_sample_index = 8961;
assert_eq!(
find_descending_peak_trend_end(&history, peak_sample_index).map(|info| info.index),
Some(16141)
Some(16142)
);
}
// holiday: single beat
Expand Down Expand Up @@ -389,7 +389,7 @@ mod tests {
.take(1)
.map(|info| (info.from.index, info.to.index))
.collect::<Vec<_>>();
assert_eq!(&envelopes, &[(410, 7098)])
assert_eq!(&envelopes, &[(411, 7098)])
}

#[test]
Expand Down Expand Up @@ -420,6 +420,6 @@ mod tests {
let envelopes = EnvelopeIterator::new(&history, None)
.map(|info| (info.from.index, info.to.index))
.collect::<Vec<_>>();
assert_eq!(&envelopes, &[(256, 1971)]);
assert_eq!(&envelopes, &[(259, 1972)]);
}
}
4 changes: 2 additions & 2 deletions src/max_min_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Iterator for MaxMinIterator<'_> {
.take(sample_count)
// TODO by increasing this, we also have high performance
// improvement chances.
.step_by(1)
.step_by(2)
.max_by(|(_x_index, &x_value), (_y_index, &y_value)| {
if libm::fabsf(x_value) > libm::fabsf(y_value) {
Ordering::Greater
Expand Down Expand Up @@ -119,7 +119,7 @@ mod tests {
(543, 0.39106417),
(865, -0.068865016),
(1027, 0.24600971),
(1302, -0.3068636)
(1301, -0.30671102)
]
);
}
Expand Down

0 comments on commit b537a84

Please sign in to comment.