diff --git a/.DS_Store b/.DS_Store
index 3fbde63..078b972 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/README.md b/README.md
index 9de7b0f..d0b5104 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
@@ -19,7 +19,19 @@ Use together with [nanometers-plugin](https://github.com/aizcutei/nanometers_plu
---
## Preview
-![nanometers](./static/example.gif)
+![demo1](./static/demo1.png)
+![demo2](./static/demo2.png)
+![demo3](./static/demo3.png)
+
+
+
+More:
+
+![nanometers](./static/Example.gif)
+![demo4](./static/demo4.png)
+![demo5](./static/demo5.png)
+![demo6](./static/demo6.png)
+
---
## Audio routing support
@@ -31,6 +43,19 @@ Use together with [nanometers-plugin](https://github.com/aizcutei/nanometers_plu
|Linux|🚧|✅ * No test yet|✅ * No test yet|
---
+
+### Self build
+
+You should have Rust installed. If not, install it from [here](https://www.rust-lang.org/tools/install).
+
+Clone the repository:
+
+`git clone`
+
+Build the project:
+
+`cargo build --release`
+
### Testing locally
Make sure you are using the latest version of stable rust by running `rustup update`.
diff --git a/src/audio/callback.rs b/src/audio/callback.rs
index 5add52b..c059491 100644
--- a/src/audio/callback.rs
+++ b/src/audio/callback.rs
@@ -2,7 +2,7 @@ use crate::{setting::*, utils::*};
use crossbeam_channel::{Receiver, Sender};
use egui::{Color32, Pos2};
use realfft::RealFftPlanner;
-use rustfft::num_complex::ComplexFloat;
+use rustfft::num_complex::{Complex, ComplexFloat};
use std::sync::{Arc, Mutex};
const SQRT_2: f32 = 1.4142135;
@@ -40,6 +40,10 @@ pub fn get_callback(
let r = data[1][i];
let m = (l + r) / 2.0;
let s = (l - r) / 2.0;
+ buf.raw.l.push(l);
+ buf.raw.r.push(r);
+ buf.raw.m.push(m);
+ buf.raw.s.push(s);
let raw_len = buf.raw.l.len();
@@ -215,10 +219,6 @@ pub fn get_callback(
let high_r = multiband_high_filter(r, &mut buf.multiband.high_buf);
let high_m = multiband_high_filter(m, &mut buf.multiband.high_buf);
let high_s = multiband_high_filter(s, &mut buf.multiband.high_buf);
- buf.raw.l.push(l);
- buf.raw.r.push(r);
- buf.raw.m.push(m);
- buf.raw.s.push(s);
buf.low_raw.l.push(low_l);
buf.low_raw.r.push(low_r);
buf.low_raw.m.push(low_m);
@@ -400,17 +400,21 @@ fn process_spectrum(buf: &mut AudioSourceBuffer, send_data: &mut SendData, data:
data.l.extend_from_slice(&[0.0; 2048]);
data.r.extend_from_slice(&[0.0; 2048]);
r2c.process(&mut data.l, &mut spectrum).unwrap();
- send_data.spectrum.l = spectrum.clone().iter().map(|i| i.norm()).collect();
+ send_data.spectrum.l = spectrum.clone().iter().map(|i| amp_to_db(i)).collect();
r2c.process(&mut data.r, &mut spectrum).unwrap();
- send_data.spectrum.r = spectrum.clone().iter().map(|i| i.norm()).collect();
+ send_data.spectrum.r = spectrum.clone().iter().map(|i| amp_to_db(i)).collect();
}
SpectrumChannel::MS => {
data.m.extend_from_slice(&[0.0; 2048]);
data.s.extend_from_slice(&[0.0; 2048]);
r2c.process(&mut data.m, &mut spectrum).unwrap();
- send_data.spectrum.l = spectrum.clone().iter().map(|i| i.norm()).collect();
+ send_data.spectrum.l = spectrum.clone().iter().map(|i| amp_to_db(i)).collect();
r2c.process(&mut data.s, &mut spectrum).unwrap();
- send_data.spectrum.r = spectrum.clone().iter().map(|i| i.norm()).collect();
+ send_data.spectrum.r = spectrum.clone().iter().map(|i| amp_to_db(i)).collect();
}
}
}
+
+fn amp_to_db(amp: &Complex) -> f32 {
+ ((amp.norm() / 2048.0).log10() * 20.0 + 150.0) / 150.0
+}
diff --git a/src/frame/setting_panel.rs b/src/frame/setting_panel.rs
index 7b36884..c3a8898 100644
--- a/src/frame/setting_panel.rs
+++ b/src/frame/setting_panel.rs
@@ -510,7 +510,7 @@ impl NanometersApp {
ui.horizontal(|ui| {
ui.label("Smoothing");
ui.add(
- egui::Slider::new(&mut self.setting.spectrum.smoothing, 0.0..=1.25)
+ egui::Slider::new(&mut self.setting.spectrum.smoothing, 0.0..=0.99)
.text(""),
);
});
diff --git a/src/frame/spectrum_meter.rs b/src/frame/spectrum_meter.rs
index bb40bf9..549f4c8 100644
--- a/src/frame/spectrum_meter.rs
+++ b/src/frame/spectrum_meter.rs
@@ -78,7 +78,7 @@ impl NanometersApp {
let mut wave_0_points = Vec::new();
let mut wave_1_points = Vec::new();
if !data.l.is_empty() {
- println!("{:?}", data.l);
+ // println!("{:?}", data.l[0]);
for i in 0..2049 {
if data.l[i] > self.spectrum.ch0[i] {
self.spectrum.ch0[i] = data.l[i];
@@ -272,7 +272,7 @@ fn ref_lines(ui: &mut Ui, rect: Rect, width: f32, color: Color32) -> Vec
fonts,
pos2(rect.left() + 0.5983756514 * rect.width(), 5.0),
Align2::CENTER_CENTER,
- "1000Hz",
+ "1kHz",
FontId::monospace(9.0),
color,
));
@@ -345,7 +345,7 @@ fn ref_lines(ui: &mut Ui, rect: Rect, width: f32, color: Color32) -> Vec
fonts,
pos2(rect.left() + 0.8975634771 * rect.width(), 5.0),
Align2::CENTER_CENTER,
- "10000Hz",
+ "10kHz",
FontId::monospace(9.0),
color,
));
@@ -363,9 +363,13 @@ fn ref_lines(ui: &mut Ui, rect: Rect, width: f32, color: Color32) -> Vec
fn freq_to_pos(rect: Rect) -> Vec {
let mut pos = Vec::with_capacity(2049);
for i in 0..2049 {
- pos.push(
- rect.left() + 0.2991878257 * (((i - 1) as f32 * 23.4375).log10() - 1.0) * rect.width(),
- );
+ if i == 0 {
+ pos.push(rect.left());
+ } else {
+ pos.push(
+ rect.left() + 0.2991878257 * ((i as f32 * 11.71875).log10() - 1.0) * rect.width(),
+ );
+ }
}
pos
}
diff --git a/src/utils/data_struct.rs b/src/utils/data_struct.rs
index c4577de..957b014 100644
--- a/src/utils/data_struct.rs
+++ b/src/utils/data_struct.rs
@@ -162,7 +162,7 @@ impl SpectrogramOneWindow {
}
}
-#[derive(Debug, Clone, Default)]
+#[derive(Debug, Clone)]
pub struct SpectrogramCalcBuffer {
pub ab: bool,
pub a: SpectrogramOneWindow,
@@ -176,11 +176,17 @@ impl SpectrogramCalcBuffer {
ab: false,
a: SpectrogramOneWindow::new(),
b: SpectrogramOneWindow::new(),
- image: vec![Color32::TRANSPARENT; 4096 * 4096],
+ image: vec![Color32::TRANSPARENT; 4000 * 4000],
}
}
}
+impl Default for SpectrogramCalcBuffer {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
#[derive(Debug, Clone, Default)]
pub struct SpectrumCalcBuffer {
pub ab: bool,
diff --git a/static/demo1.png b/static/demo1.png
new file mode 100644
index 0000000..334882f
Binary files /dev/null and b/static/demo1.png differ
diff --git a/static/demo2.png b/static/demo2.png
new file mode 100644
index 0000000..d5cddb2
Binary files /dev/null and b/static/demo2.png differ
diff --git a/static/demo3.png b/static/demo3.png
new file mode 100644
index 0000000..5020219
Binary files /dev/null and b/static/demo3.png differ
diff --git a/static/demo4.png b/static/demo4.png
new file mode 100644
index 0000000..83adc19
Binary files /dev/null and b/static/demo4.png differ
diff --git a/static/demo5.png b/static/demo5.png
new file mode 100644
index 0000000..af4531c
Binary files /dev/null and b/static/demo5.png differ
diff --git a/static/demo6.png b/static/demo6.png
new file mode 100644
index 0000000..ed7d03f
Binary files /dev/null and b/static/demo6.png differ