From a1d3b5a8c7d5aa4353f229d117a19d2daa198c64 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Tue, 5 Dec 2023 08:07:21 +0000 Subject: [PATCH] Tidy --- src/main.rs | 10 +++++----- src/vis.rs | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9139798..6c8d612 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ mod cli; const LIGHT_INTERVAL: Duration = Duration::from_millis(100); const SERVICE_TYPE: &str = "_nanoleafapi._tcp.local."; -fn update_lights(panels: NanoleafLayoutResponse, nanoleaf: NanoleafClient, buffer_manager: Arc>, color_channel: Receiver>, intensity: f32) { +fn update_lights(panels: NanoleafLayoutResponse, nanoleaf: NanoleafClient, buffer_manager: Arc>, color_channel: Receiver>, intensity_modifier: f32) { // Needs to be over a sliding window. let mut window = SlidingWindow::new(64); let mut color_set: Vec = Vec::new(); @@ -51,15 +51,15 @@ fn update_lights(panels: NanoleafLayoutResponse, nanoleaf: NanoleafClient, buffe { if let Ok(v) = color_channel.try_recv() { color_set = v; - } + } // else, use the previous value. - if let Some(data) = buffer_manager.write().unwrap().fft_interval(LIGHT_INTERVAL, panels.num_panels) { + if let Some(audio_data) = buffer_manager.write().unwrap().fft_interval(LIGHT_INTERVAL, panels.num_panels) { let mut effect = NanoleafEffectPayload::new(panels.num_panels); for (panel_index, panel) in sorted_panels.iter().enumerate() { if let Some(color) = color_set.get(panel_index) { - let (min, max) = window.submit_new(data[panel_index]); + let (min, max) = window.submit_new(audio_data[panel_index]); let base_int = color.get_lightness() - 10.0; - let intensity = (base_int + ((data[panel_index] + min) / max) * intensity * (panel_index as f32 + 1.0f32).powf(1.05f32)).clamp(5.0, 80.0); + let intensity = (base_int + ((audio_data[panel_index] + min) / max) * intensity_modifier * (panel_index as f32 + 1.0f32).powf(1.05f32)).clamp(5.0, 80.0); let hsl = Hsl::from(color.get_hue(), color.get_saturation(), intensity); let rgb = hsl.to_rgb().as_tuple(); let r = rgb.0.round() as u8; diff --git a/src/vis.rs b/src/vis.rs index 08442ff..bed8732 100644 --- a/src/vis.rs +++ b/src/vis.rs @@ -144,8 +144,6 @@ impl BufferManager { Some(Linear::builder() .elements(&truncated_data[range]) .knots(power_range(POWER_FREQ, count).as_ref()) - //.equidistant::() - //.normalized() .build() .unwrap() .take(out_size)