summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2017-06-26 22:44:14 +0200
committerJustin Worthe <justin@worthe-it.co.za>2017-06-26 22:44:14 +0200
commitaa8fd313429ead1cb5305da5a00c65097ac117b8 (patch)
tree0408644bb3e7e03effacb481ee6779f735f16197 /src
parent80a596b8d527a0ee50da8536e064631f6763565b (diff)
Increased number of samples
Diffstat (limited to 'src')
-rw-r--r--src/audio.rs4
-rw-r--r--src/gui.rs10
2 files changed, 8 insertions, 6 deletions
diff --git a/src/audio.rs b/src/audio.rs
index bcee400..9a5ea0e 100644
--- a/src/audio.rs
+++ b/src/audio.rs
@@ -3,8 +3,8 @@ use portaudio as pa;
use std::sync::mpsc::*;
-const SAMPLE_RATE: f64 = 44100.0;
-const FRAMES: usize = 512;
+pub const SAMPLE_RATE: f64 = 44100.0;
+pub const FRAMES: usize = 1024;
pub fn init() -> Result<pa::PortAudio, pa::Error> {
pa::PortAudio::new()
diff --git a/src/gui.rs b/src/gui.rs
index 19aeec0..6ab2b50 100644
--- a/src/gui.rs
+++ b/src/gui.rs
@@ -10,6 +10,8 @@ use std::io::Write;
use std::thread;
use std::sync::mpsc::*;
+const FPS: u32 = 30;
+
struct RustyUi {
dropdown: gtk::ComboBoxText,
pitch_label: gtk::Label,
@@ -180,9 +182,9 @@ fn start_processing_audio(mic_receiver: Receiver<Vec<f64>>, cross_thread_state:
};
let signal = ::transforms::align_to_rising_edge(&samples);
- let frequency_domain = ::transforms::fft(&samples, 44100.0);
+ let frequency_domain = ::transforms::fft(&samples, ::audio::SAMPLE_RATE);
let correlation = ::transforms::correlation(&samples);
- let fundamental = ::transforms::find_fundamental_frequency_correlation(&samples, 44100.0);
+ let fundamental = ::transforms::find_fundamental_frequency_correlation(&samples, ::audio::SAMPLE_RATE);
let (pitch, error) = match fundamental {
Some(fundamental) => (::transforms::hz_to_pitch(fundamental), ::transforms::hz_to_cents_error(fundamental)),
None => ("".to_string(), 0.0)
@@ -204,7 +206,7 @@ fn start_processing_audio(mic_receiver: Receiver<Vec<f64>>, cross_thread_state:
}
fn setup_pitch_label_callbacks(state: Rc<RefCell<ApplicationState>>, cross_thread_state: Arc<RwLock<CrossThreadState>>) {
- gtk::timeout_add(16, move || {
+ gtk::timeout_add(1000/FPS, move || {
let ref pitch = cross_thread_state.read().unwrap().pitch;
let ref ui = state.borrow().ui;
ui.pitch_label.set_label(pitch.as_ref());
@@ -325,7 +327,7 @@ fn setup_correlation_drawing_area_callbacks(state: Rc<RefCell<ApplicationState>>
//draw the fundamental
context.new_path();
- let fundamental_x = 44100.0 / fundamental * width / len;
+ let fundamental_x = ::audio::SAMPLE_RATE / fundamental * width / len;
context.move_to(fundamental_x, 0.0);
context.line_to(fundamental_x, height);
context.stroke();