MCPcopy Index your code
hub / github.com/FrameworkComputer/inputmodule-rs / input_eq_cmd

Function input_eq_cmd

inputmodule-control/src/inputmodule.rs:691–755  ·  view source on GitHub ↗

Equalizer-like animation that expands as volume goes up and retracts as it goes down

(serialdevs: &Vec<String>)

Source from the content-addressed store, hash-verified

689#[cfg(feature = "audio-visualizations")]
690// Equalizer-like animation that expands as volume goes up and retracts as it goes down
691fn input_eq_cmd(serialdevs: &Vec<String>) {
692 // Example from https://github.com/Rahix/visualizer2/blob/canon/README.md
693
694 // Initialize the logger. Take a look at the sources if you want to customize
695 // the logger.
696 vis_core::default_log();
697
698 // Load the default config source. More about config later on. You can also
699 // do this manually if you have special requirements.
700 vis_core::default_config();
701
702 // Initialize some analyzer-tools. These will be moved into the analyzer closure
703 // later on.
704 let mut analyzer = vis_core::analyzer::FourierBuilder::new()
705 .length(512)
706 .window(vis_core::analyzer::window::nuttall)
707 .plan();
708
709 let spectrum = vis_core::analyzer::Spectrum::new(vec![0.0; analyzer.buckets()], 0.0, 1.0);
710
711 let mut frames = vis_core::Visualizer::new(
712 AnalyzerResult {
713 spectrum,
714 volume: 0.0,
715 beat: 0.0,
716 },
717 // This closure is the "analyzer". It will be executed in a loop to always
718 // have the latest data available.
719 move |info, samples| {
720 analyzer.analyze(samples);
721
722 info.spectrum.fill_from(&analyzer.average());
723 info.volume = samples.volume(0.3) * 400.0;
724 info.beat = info.spectrum.slice(50.0, 100.0).max() * 0.01;
725 info
726 },
727 )
728 // Build the frame iterator which is the base of your loop later on
729 .frames();
730
731 for frame in frames.iter() {
732 // This is just a primitive example, your vis core belongs here
733
734 frame.info(|info| {
735 let sampled_volume = info.volume;
736 let limited_volume = sampled_volume.min(34.0);
737
738 let display_max_widths = [10.0, 14.0, 20.0, 28.0, 34.0, 28.0, 20.0, 14.0, 10.0];
739
740 let volumes_to_display = display_max_widths
741 .iter()
742 .map(|x| {
743 let computed_width = (limited_volume / 34.0) * x;
744 let next_lowest_odd = computed_width - (computed_width % 2.0) - 1.0;
745 next_lowest_odd as u8
746 })
747 .collect::<Vec<_>>();
748

Callers 1

serial_commandsFunction · 0.85

Calls 1

eq_cmdFunction · 0.85

Tested by

no test coverage detected