]> OzVa Git service - rust_fft/commitdiff
Clippy changes
authorMax Value <greenwoodw50@gmail.com>
Mon, 12 Jan 2026 00:10:13 +0000 (00:10 +0000)
committerMax Value <greenwoodw50@gmail.com>
Mon, 12 Jan 2026 00:10:13 +0000 (00:10 +0000)
src/image_array.rs
src/main.rs

index ae23ca30f323a028947a8d0c22901ac2e54fec65..d7049e5071f988f6d32542a504d42198b694e9ac 100644 (file)
@@ -65,12 +65,12 @@ impl ImageArray {
                }
        }
 
-       pub fn from_camera (&mut self) {
+       pub fn read_camera (&mut self) {
                let frame = self.camera.frame().unwrap();
 
                println!("{}", frame.resolution());
 
-               self.camera_buffer = frame.buffer()[..].try_into().expect("Image is wrong size");
+               self.camera_buffer = frame.buffer()[..].into();
 
                unsafe {
                        ProcessCapture (
@@ -94,7 +94,7 @@ impl ImageArray {
                }
        }
 
-       pub fn from_buffer (&mut self, buffer: &Vec<Complex<f32>>) -> () {
+       pub fn read_buffer (&mut self, buffer: &[Complex<f32>]) {
                let mut r: f32;
                let mut theta: f32;
                let mut amplitude: f32;
@@ -145,7 +145,7 @@ impl ImageArray {
                }
        }
 
-       pub fn to_buffer (&mut self, buffer: &mut Vec<Complex<f32>>) -> () {
+       pub fn write_buffer (&mut self, buffer: &mut [Complex<f32>]) {
                let mut r: f32;
                let mut amplitude: f32;
 
index d005d8f9c23165d5d6a532f17f44c81cd5d1ba53..8c6895a10d60916b43fcef1080cdc69422cb969e 100644 (file)
@@ -2,7 +2,6 @@ use rustfft::algorithm::Radix4;
 use rustfft::{Fft, FftDirection};
 use rustfft::num_complex::Complex;
 use show_image::{ImageView, ImageInfo, create_window, event};
-use hound;
 use cpal::{StreamConfig, BufferSize, SampleRate};
 use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
 use std::sync::{Arc, Mutex};
@@ -114,7 +113,7 @@ fn main () -> Result<(), Box<dyn std::error::Error>> {
        let stream = device.build_output_stream(
                &StreamConfig{
                        channels: 2,
-                       sample_rate: SampleRate{0: file_rate},
+                       sample_rate: SampleRate(file_rate),
                        buffer_size: BufferSize::Fixed(WINDOW_SIZE as u32)
                },
                move |data: &mut [i16], _: &cpal::OutputCallbackInfo| {
@@ -137,14 +136,14 @@ fn main () -> Result<(), Box<dyn std::error::Error>> {
                        for x in buffer.iter_mut() {
                                *x *= 1f32 / WINDOW_SIZE as f32;
                        }
-                       image_array.from_buffer(&mut buffer);
+                       image_array.read_buffer(&buffer);
 
                        // show the image on screen
                        let image = ImageView::new(ImageInfo::rgb8(WINDOW_SIZE as u32, CHUNK_SIZE as u32), &image_array.data);
                        display_window.set_image ("image", image)?;
 
                        // capture and transform camera view to image
-                       image_array.from_camera();
+                       image_array.read_camera();
 
                        // make and display debug image
                        if DEBUG_MODE {
@@ -153,8 +152,8 @@ fn main () -> Result<(), Box<dyn std::error::Error>> {
                        }
 
                        // convert image to audio
-                       image_array.to_buffer(&mut buffer);
-                       inverse_transform.process_with_scratch(&mut *buffer, &mut scratch);
+                       image_array.write_buffer(&mut buffer);
+                       inverse_transform.process_with_scratch(&mut buffer, &mut scratch);
 
                        // when a "true" is receved by rx, get lock for sample buffer and fill the last half with the audio
                        if rx.recv().unwrap() {
@@ -166,10 +165,7 @@ fn main () -> Result<(), Box<dyn std::error::Error>> {
 
                        i = 0;
                }
-               let value = match sample {
-                       Ok(t) => t,
-                       Err(_) => 0i16
-               };
+               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};
                i += 1;