summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2017-07-12 20:35:21 +0200
committerJustin Worthe <justin@worthe-it.co.za>2017-07-12 20:35:21 +0200
commit4dd91d7fc35685f4ad4c909ba72a03f21185283d (patch)
tree590196a1bb2813db4764ec13736215ba9c491f56
parent73e106a45cd62508ef4bf163479d79ea6339f569 (diff)
Simplified loop for doing calculations from microphone samples
In the benchmarks, the correlation can be done in 0.5ms. I'm only expecting new samples from the microphone every 23ms at best. I don't need to worry about dropping frames at this point.
-rw-r--r--src/gui.rs13
1 files changed, 1 insertions, 12 deletions
diff --git a/src/gui.rs b/src/gui.rs
index f298790..a75e573 100644
--- a/src/gui.rs
+++ b/src/gui.rs
@@ -163,18 +163,7 @@ fn start_listening_current_dropdown_value(dropdown: &gtk::ComboBoxText, mic_send
fn start_processing_audio(mic_receiver: Receiver<Vec<f32>>, cross_thread_state: Arc<RwLock<CrossThreadState>>) {
thread::spawn(move || {
- loop {
- let mut samples = None;
-
- // ignore all pending samples until we get to the most recent one
- while let Ok(next_samples) = mic_receiver.try_recv() {
- samples = Some(next_samples);
- }
- let samples = match samples {
- Some(samples) => samples,
- None => {continue;}
- };
-
+ while let Ok(samples) = mic_receiver.recv() {
let signal = ::transforms::align_to_rising_edge(&samples);
let correlation = ::transforms::correlation(&samples);
let fundamental = ::transforms::find_fundamental_frequency_correlation(&samples, ::audio::SAMPLE_RATE);