From: Max Value Date: Mon, 12 Jan 2026 12:56:29 +0000 (+0000) Subject: Added filtering to feedback and the main out X-Git-Url: https://git.ozva.co.uk/?a=commitdiff_plain;h=refs%2Fheads%2Fmain;p=rust_fft Added filtering to feedback and the main out untested! --- diff --git a/Cargo.toml b/Cargo.toml index 9532aec..4a1f932 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ rand = "0.9.2" nokhwa = {version = "0.10.10", features = ["input-native"]} relative-path = "2.0.1" yuv = "0.8.9" +lowpass-filter = "0.3.2" [build-dependencies] cc = "1.0" diff --git a/src/main.rs b/src/main.rs index 5184f4d..0d4153c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,8 @@ mod sample_buffer; use image_array::ImageArray; use sample_buffer::SampleBuffer; +use lowpass_filter::LowpassFilter; + const WINDOW_SIZE: usize = 128; const CHUNK_SIZE: usize = 72; const SPECTOGRAM_AREA: usize = WINDOW_SIZE * CHUNK_SIZE; @@ -48,7 +50,16 @@ const LUT_LENGTH: usize = LUT_SIZE * LUT_SIZE * LUT_SIZE * 3; const DEBUG_MODE: bool = true; const CALIBRATION_PATH: &str = "./test/calibration.jpg"; -const AUDIO_PATH: &str = "/home/will/Downloads/Adducci - Around the Horn.wav"; +const AUDIO_PATH: &str = "./test/example.wav"; + +// feedback config +const WET: f32 = 0.0; +const DRY: f32 = 1.0; + +// audio effects and filtering +const MAIN_LOWPASS: f32 = 20000.0; +const FEEDBACK_LOWPASS: f32 = 20000.0; +const FILTER_SCALING: f32 = 1. / 65535.; // to bring any signal down to +-1 extern "C" { fn GetHomography(camera_ptr: usize, homography_ptr: usize); @@ -106,6 +117,10 @@ fn main () -> Result<(), Box> { let mut reader = hound::WavReader::open(audio_path).unwrap(); let file_rate = reader.spec().sample_rate; + // setup the lowpass filters + let main_lowpass = LowpassFilter::new(file_rate, MAIN_LOWPASS); + let feedback_lowpass = LowpassFilter::new(file_rate, FEEDBACK_LOWPASS); + // setup audio output and build output stream let host = cpal::default_host(); let device = host.default_output_device().expect("No output device available"); @@ -159,15 +174,19 @@ fn main () -> Result<(), Box> { if rx.recv().unwrap() { let mut write_buffer = sample_buffer.lock().unwrap(); for (i, x) in write_buffer[SPECTOGRAM_AREA..].iter_mut().enumerate() { - *x = buffer[i].re as i16; + let value = main_lowpass.run(buffer[i].re / i16::MAX as f32); + *x = (value * i16::MAX) as i16; } } i = 0; } - let value = sample.unwrap_or_default(); // if buffer is not full convert value and add to buffer - buffer[i] = Complex{re: value as f32, im: 0f32}; + let mut value = sample.unwrap_or_default() as f32; + let feedback_value = feedback_lowpass.run(buffer[i].re / i16::MAX as f32); + value = (value * DRY) + (feedback_value * i16::MAX * WET); + + buffer[i] = Complex{re: value, im: 0f32}; i += 1; } diff --git a/test/example.wav b/test/example.wav index 02c44de..75ac385 100644 Binary files a/test/example.wav and b/test/example.wav differ diff --git a/todo b/todo index f88857f..52b5a35 100644 --- a/todo +++ b/todo @@ -34,3 +34,7 @@ GPU PERFORMANCE ISSUES: CAPTURE ISSUES: - check nokhwa fps, res, etc - reinstate the read loop + +AUDIO ISSUES: +- disable the feedback mix code +- disable the filtering code