Skip to content

Commit 32493dd

Browse files
committed
Restore random_eq, pin vis-core, restore release profile from main
1 parent 457a7b2 commit 32493dd

File tree

4 files changed

+29
-75
lines changed

4 files changed

+29
-75
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ overflow-checks = true
3939

4040
# cargo build/run --release
4141
[profile.release]
42+
codegen-units = 1
4243
debug = 2
43-
incremental = true
44-
lto = 'thin'
45-
opt-level = 0
46-
split-debuginfo = "packed"
44+
debug-assertions = false
45+
incremental = false
46+
lto = 'fat'
47+
opt-level = 3
48+
overflow-checks = false
4749

4850
# do not optimize proc-macro crates = faster builds from scratch
4951
[profile.dev.build-override]

inputmodule-control/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ image = { version = "0.24.5", default-features = false, features = [
1515
rand = "0.8.5"
1616
chrono = "0.4.23"
1717

18-
vis-core = { git = "https://github.com/Rahix/visualizer2.git" }
18+
vis-core = { git = "https://github.com/Rahix/visualizer2.git", rev = '1fe908012a9c156695921f3b6bb47178e1332b92' }

inputmodule-control/src/inputmodule.rs

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use chrono::Local;
55
use image::codecs::gif::GifDecoder;
66
use image::{io::Reader as ImageReader, Luma};
77
use image::{AnimationDecoder, DynamicImage, ImageBuffer};
8+
use rand::prelude::*;
89
use serialport::{SerialPort, SerialPortInfo, SerialPortType};
910

1011
use crate::b1display::{B1Pattern, Fps, PowerMode};
@@ -620,6 +621,26 @@ fn display_gray_image_cmd(serialdev: &str, image_path: &str) {
620621
commit_cols(&mut port);
621622
}
622623

624+
/// Display an equlizer looking animation with random values.
625+
fn random_eq_cmd(serialdevs: &Vec<String>) {
626+
loop {
627+
// Lower values more likely, makes it look nicer
628+
//weights = [i*i for i in range(33, 0, -1)]
629+
let population: Vec<u8> = (1..34).collect();
630+
let mut rng = thread_rng();
631+
let vals = population
632+
.choose_multiple_weighted(&mut rng, 9, |item| (34 - item) ^ 2)
633+
.unwrap()
634+
.copied()
635+
.collect::<Vec<_>>();
636+
for serialdev in serialdevs {
637+
eq_cmd(serialdev, vals.as_slice());
638+
}
639+
thread::sleep(Duration::from_millis(200));
640+
}
641+
}
642+
643+
623644
/// The data-type for storing analyzer results
624645
#[derive(Debug, Clone)]
625646
pub struct AnalyzerResult {
@@ -628,75 +649,6 @@ pub struct AnalyzerResult {
628649
beat: f32,
629650
}
630651

631-
/// Display an equlizer looking animation with random values.
632-
fn random_eq_cmd(serialdevs: &Vec<String>) {
633-
// Example from https://github.com/Rahix/visualizer2/blob/canon/README.md
634-
635-
// Initialize the logger. Take a look at the sources if you want to customize
636-
// the logger.
637-
vis_core::default_log();
638-
639-
// Load the default config source. More about config later on. You can also
640-
// do this manually if you have special requirements.
641-
vis_core::default_config();
642-
643-
// Initialize some analyzer-tools. These will be moved into the analyzer closure
644-
// later on.
645-
let mut analyzer = vis_core::analyzer::FourierBuilder::new()
646-
.length(512)
647-
.window(vis_core::analyzer::window::nuttall)
648-
.plan();
649-
650-
let spectrum = vis_core::analyzer::Spectrum::new(vec![0.0; analyzer.buckets()], 0.0, 1.0);
651-
652-
let mut frames = vis_core::Visualizer::new(
653-
AnalyzerResult {
654-
spectrum,
655-
volume: 0.0,
656-
beat: 0.0,
657-
},
658-
// This closure is the "analyzer". It will be executed in a loop to always
659-
// have the latest data available.
660-
move |info, samples| {
661-
analyzer.analyze(samples);
662-
663-
info.spectrum.fill_from(&analyzer.average());
664-
info.volume = samples.volume(0.3) * 400.0;
665-
info.beat = info.spectrum.slice(50.0, 100.0).max() * 0.01;
666-
info
667-
},
668-
)
669-
// Build the frame iterator which is the base of your loop later on
670-
.frames();
671-
672-
for frame in frames.iter() {
673-
// This is just a primitive example, your vis core belongs here
674-
675-
frame.info(|info| {
676-
// for n in 0..info.volume as usize {
677-
// print!("{}",n);
678-
// }
679-
for serialdev in serialdevs {
680-
eq_cmd(
681-
serialdev,
682-
&[
683-
info.volume as u8,
684-
info.volume as u8,
685-
info.volume as u8,
686-
info.volume as u8,
687-
info.volume as u8,
688-
info.volume as u8,
689-
info.volume as u8,
690-
info.volume as u8,
691-
info.volume as u8,
692-
],
693-
)
694-
}
695-
});
696-
thread::sleep(Duration::from_millis(30));
697-
}
698-
}
699-
700652
// Equalizer-like animation that expands as volume goes up and retracts as it goes down
701653
fn input_eq_cmd(serialdevs: &Vec<String>) {
702654
// Example from https://github.com/Rahix/visualizer2/blob/canon/README.md

0 commit comments

Comments
 (0)