]> OzVa Git service - rust_fft/commitdiff
Added filtering to feedback and the main out main
authorMax Value <greenwoodw50@gmail.com>
Mon, 12 Jan 2026 12:56:29 +0000 (12:56 +0000)
committerMax Value <greenwoodw50@gmail.com>
Mon, 12 Jan 2026 12:56:29 +0000 (12:56 +0000)
untested!

Cargo.toml
src/main.rs
test/example.wav
todo

index 9532aec354840ba5bc2631f31aaab1dfb68ff936..4a1f93211aa7b015898de3a2fef2eba2b9ad5f50 100644 (file)
@@ -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"
index 5184f4d62950e82e47e0fcf9f5adb5b090967b3c..0d4153cc990b6541f39abf210c5ed78f7accf85a 100644 (file)
@@ -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<dyn std::error::Error>> {
        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<dyn std::error::Error>> {
                        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;
        }
 
index 02c44de9c261ef30a3163d3158f2c6a39c2685df..75ac38508f5f36614b2db5485a2eae4cbed1b6a7 100644 (file)
Binary files a/test/example.wav and b/test/example.wav differ
diff --git a/todo b/todo
index f88857ff2bc9f3a2f536d8b5fda53fbc04fc058e..52b5a3563322da4fc71c920760e20972cb5c706a 100644 (file)
--- 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