diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2017-07-12 20:35:21 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2017-07-12 20:35:21 +0200 |
commit | 4dd91d7fc35685f4ad4c909ba72a03f21185283d (patch) | |
tree | 590196a1bb2813db4764ec13736215ba9c491f56 /src/gui.rs | |
parent | 73e106a45cd62508ef4bf163479d79ea6339f569 (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.
Diffstat (limited to 'src/gui.rs')
-rw-r--r-- | src/gui.rs | 13 |
1 files changed, 1 insertions, 12 deletions
@@ -163,18 +163,7 @@ fn start_listening_current_dropdown_value(dropdown: >k::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); |