Skip to content

Commit

Permalink
add osc
Browse files Browse the repository at this point in the history
  • Loading branch information
aizcutei committed May 28, 2024
1 parent 3b7eedf commit 9175dd2
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 151 deletions.
114 changes: 0 additions & 114 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ rust-version = "1.78"
egui = { version = "0.27.2", features = ["rayon"] }
eframe = { version = "0.27.2", default-features = false, features = [
"default_fonts",
"glow",
"wgpu",
"persistence",
"puffin",
Expand All @@ -31,7 +30,7 @@ rayon = "1.10"
crossbeam-channel = "0.5.12"
puffin = { version = "0.19", optional = true }
puffin_http = { version = "0.16", optional = true }
dasp = { version = "0.11.0", features = ["ring_buffer"] }
# dasp = { version = "0.11.0", features = ["ring_buffer"] }

[features]
default = ["eframe/wgpu"]
Expand All @@ -41,6 +40,8 @@ puffin = ["eframe/puffin", "dep:puffin", "dep:puffin_http"]

[profile.release]
opt-level = 3
strip = true
lto = true

# Optimize all dependencies even in debug builds:
[profile.dev.package."*"]
Expand Down
2 changes: 2 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct NanometersApp {
pub(crate) peak: Peak,
pub(crate) vectorscope: Vectorscope,
pub(crate) spectrogram: Spectrogram,
pub(crate) oscilloscope: Oscilloscope,
}

impl Default for NanometersApp {
Expand Down Expand Up @@ -80,6 +81,7 @@ impl Default for NanometersApp {
peak: Default::default(),
vectorscope: Default::default(),
spectrogram: Default::default(),
oscilloscope: Default::default(),
}
}
}
Expand Down
29 changes: 20 additions & 9 deletions src/audio/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn get_callback(
let stereo_on = setting.sequence[1].contains(&ModuleList::Vectorscope);
let spectrum_on = setting.sequence[1].contains(&ModuleList::Spectrum);
let spectrogram_on = setting.sequence[1].contains(&ModuleList::Spectrogram);
let oscilloscope_on = setting.sequence[1].contains(&ModuleList::Oscilloscope);

let waveform_block_length = 280;
let stereo_block_length = 1;
Expand Down Expand Up @@ -142,6 +143,16 @@ pub fn get_callback(
buf.spectrogram.reset();
}

if oscilloscope_on {
// Oscilloscope
if raw_len >= 2400 {
send_data.oscilloscope = OscilloscopeSendData {
len: 2400,
data: buf.raw.m[raw_len - 2400..raw_len].to_vec(),
};
}
}

if waveform_on {
// Waveform
buf.waveform.update_l(l);
Expand Down Expand Up @@ -203,9 +214,9 @@ pub fn get_callback(
buf.stereo.update(l, r);
if buf.stereo.index >= stereo_block_length {
buf.stereo.index = 0;
send_data.stereo.lissa.push(Pos2::new(l, r));
send_data.vectorscope.lissa.push(Pos2::new(l, r));
send_data
.stereo
.vectorscope
.linear
.push(Pos2::new(-SQRT_2 * s, -SQRT_2 * m));

Expand All @@ -220,7 +231,7 @@ pub fn get_callback(
} else {
0.0
};
send_data.stereo.log.push(Pos2::new(
send_data.vectorscope.log.push(Pos2::new(
0.7071067812 * (log_y - log_x),
-0.7071067812 * (log_x + log_y),
));
Expand All @@ -244,19 +255,19 @@ pub fn get_callback(
}
}

if raw_len >= 4096 {
buf.raw.keep_last(2048);
buf.low_raw.keep_last(2048);
buf.mid_raw.keep_last(2048);
buf.high_raw.keep_last(2048);
if raw_len >= 8192 {
buf.raw.keep_last(4096);
buf.low_raw.keep_last(4096);
buf.mid_raw.keep_last(4096);
buf.high_raw.keep_last(4096);
}
}

// Send data

if stereo_on {
// Stereo
send_data.stereo.max = buf.stereo.max;
send_data.vectorscope.max = buf.stereo.max;
buf.stereo.max = f32::NEG_INFINITY;
}

Expand Down
14 changes: 9 additions & 5 deletions src/frame/main_canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,26 @@ impl NanometersApp {
let mut update_stereogram_data = VectorscopeSendData::new();
let mut update_iir_data = Vec::new();
let mut update_db_data = DBData::new();
let mut update_osc_data = OscilloscopeSendData::new();
let mut update_spectrogram_data = Vec::new();

self.rx.as_mut().unwrap().try_iter().for_each(|data| {
update_iir_data.extend_from_slice(&data.iir);
update_db_data.l = data.db.l;
update_db_data.r = data.db.r;
update_stereogram_data.max = data.stereo.max;
update_stereogram_data.max = data.vectorscope.max;
update_stereogram_data
.lissa
.extend_from_slice(&data.stereo.lissa);
.extend_from_slice(&data.vectorscope.lissa);
update_stereogram_data
.linear
.extend_from_slice(&data.stereo.linear);
.extend_from_slice(&data.vectorscope.linear);
update_stereogram_data
.log
.extend_from_slice(&data.stereo.log);
.extend_from_slice(&data.vectorscope.log);
update_waveform_data.concat(&data.waveform);
update_osc_data = data.oscilloscope;
update_spectrogram_data.extend_from_slice(&data.spectrogram);
});

ui.ctx().request_repaint();
Expand All @@ -104,7 +108,7 @@ impl NanometersApp {
self.peak_meter(&update_iir_data, &update_db_data, meter_rect, ui);
}
ModuleList::Oscilloscope => {
self.oscilloscope_meter(meter_rect, ui);
self.oscilloscope_meter(&update_osc_data, meter_rect, ui);
}
ModuleList::Spectrum => {
self.spectrum_meter(meter_rect, ui);
Expand Down
36 changes: 35 additions & 1 deletion src/frame/oscilloscope_meter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
use crate::setting::*;
use crate::utils::*;
use crate::NanometersApp;
use egui::*;

impl NanometersApp {
pub fn oscilloscope_meter(&mut self, rect: eframe::epaint::Rect, ui: &mut Ui) {
pub fn oscilloscope_meter(
&mut self,
data: &OscilloscopeSendData,
rect: eframe::epaint::Rect,
ui: &mut Ui,
) {
ui.painter().rect_filled(rect, 0.0, self.setting.theme.bg);
if data.data.is_empty() {
ui.painter().add(Shape::line(
self.oscilloscope.plot.clone(),
Stroke::new(2.0, self.setting.theme.main),
));
} else {
if self.setting.oscilloscope.follow_pitch {
} else {
let points: Vec<Pos2> = (0..2400)
.map(|i| {
let x = rect.min.x + rect.width() * i as f32 / 2400.0;
let y = (1.0
- data
.data
.get(data.data.len().saturating_sub(2400) + i)
.unwrap_or(&0.0))
* rect.center().y;
Pos2::new(x, y)
})
.collect();
self.oscilloscope.plot = points.clone();
ui.painter().add(Shape::line(
points,
Stroke::new(2.0, self.setting.theme.main),
));
}
}
}
}
2 changes: 1 addition & 1 deletion src/frame/resize.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use egui::*;

pub fn resize_ui(ui: &mut egui::Ui, rect: egui::Rect) {
let thickness = 1.0;
let thickness = 2.0;
let left_top_corner_rect = egui::Rect::from_min_max(
egui::Pos2::new(rect.min.x, rect.min.y),
egui::Pos2::new(rect.min.x + thickness, rect.min.y + thickness),
Expand Down
5 changes: 3 additions & 2 deletions src/frame/setting_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ impl NanometersApp {
let column = &mut self.setting.sequence[to.col];
to.row = to.row.min(column.len());
column.insert(to.row, item);
self.audio_source_setting.lock().unwrap().sequence =
self.setting.sequence.clone();
if let Ok(mut mutex) = self.audio_source_setting.try_lock() {
mutex.sequence = self.setting.sequence.clone();
}
}
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/frame/vectorscope_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl NanometersApp {
]
.into(),
],
Stroke::new(3.0, self.setting.theme.frame),
Stroke::new(2.0, self.setting.theme.frame),
));
ui.painter().extend(shapes);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ impl NanometersApp {
]
.into(),
],
Stroke::new(3.0, self.setting.theme.frame),
Stroke::new(2.0, self.setting.theme.frame),
));
shapes.push(Shape::line_segment(
[
Expand All @@ -149,7 +149,7 @@ impl NanometersApp {
]
.into(),
],
Stroke::new(3.0, self.setting.theme.frame),
Stroke::new(2.0, self.setting.theme.frame),
));
ui.painter().extend(shapes);
}
Expand Down Expand Up @@ -223,7 +223,7 @@ impl NanometersApp {
[rect.center().x, 0.0].into(),
[rect.center().x, rect.max.y].into(),
],
Stroke::new(3.0, self.setting.theme.frame),
Stroke::new(2.0, self.setting.theme.frame),
));
ui.painter().extend(shapes);
}
Expand Down
Loading

0 comments on commit 9175dd2

Please sign in to comment.