summaryrefslogtreecommitdiff
path: root/benches
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2017-07-12 20:35:09 +0200
committerJustin Worthe <justin@worthe-it.co.za>2017-07-12 20:35:09 +0200
commit73e106a45cd62508ef4bf163479d79ea6339f569 (patch)
treecefc2475b16f5edc4cebcd522da1bc03ef1ef39f /benches
parent19ad6abf0933d3e3e5b1b3fa693676c47bb07be9 (diff)
Added benchmark for finding fundamental with correlation
Diffstat (limited to 'benches')
-rw-r--r--benches/transforms.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/benches/transforms.rs b/benches/transforms.rs
new file mode 100644
index 0000000..3a4b906
--- /dev/null
+++ b/benches/transforms.rs
@@ -0,0 +1,35 @@
+#[macro_use]
+extern crate bencher;
+
+extern crate rusty_microphone;
+
+use bencher::Bencher;
+
+use std::f32::consts::PI;
+
+const SAMPLE_RATE: f32 = 44100.0;
+const FRAMES: usize = 1024;
+
+
+fn sin_arg(f: f32, t: f32, phase: f32) -> f32 {
+ 2.0 as f32 * PI * f * t + phase
+}
+
+fn sample_sinusoud(amplitude: f32, frequency: f32, phase: f32) -> Vec<f32> {
+ (0..FRAMES)
+ .map(|x| {
+ let t = x as f32 / SAMPLE_RATE;
+ sin_arg(frequency, t, phase).sin() * amplitude
+ }).collect()
+}
+
+fn bench_correlation_on_sine_wave(b: &mut Bencher) {
+ let frequency = 440.0 as f32; //concert A
+ let samples = sample_sinusoud(1.0, frequency, 0.0);
+
+ b.iter(|| {
+ rusty_microphone::transforms::find_fundamental_frequency_correlation(&samples, SAMPLE_RATE)
+ })
+}
+benchmark_group!(transforms, bench_correlation_on_sine_wave);
+benchmark_main!(transforms);