@@ -242,6 +242,10 @@ pub fn serial_commands(args: &crate::ClapCli) {
242
242
random_eq_cmd ( & serialdevs) ;
243
243
}
244
244
245
+ if ledmatrix_args. input_eq {
246
+ input_eq_cmd ( & serialdevs) ;
247
+ }
248
+
245
249
if ledmatrix_args. clock {
246
250
clock_cmd ( & serialdevs) ;
247
251
}
@@ -636,6 +640,81 @@ fn random_eq_cmd(serialdevs: &Vec<String>) {
636
640
}
637
641
}
638
642
643
+
644
+ // The data-type for storing analyzer results
645
+ #[ derive( Debug , Clone ) ]
646
+ pub struct AnalyzerResult {
647
+ spectrum : vis_core:: analyzer:: Spectrum < Vec < f32 > > ,
648
+ volume : f32 ,
649
+ beat : f32 ,
650
+ }
651
+
652
+ // Equalizer-like animation that expands as volume goes up and retracts as it goes down
653
+ fn input_eq_cmd ( serialdevs : & Vec < String > ) {
654
+ // Example from https://github.com/Rahix/visualizer2/blob/canon/README.md
655
+
656
+ // Initialize the logger. Take a look at the sources if you want to customize
657
+ // the logger.
658
+ vis_core:: default_log ( ) ;
659
+
660
+ // Load the default config source. More about config later on. You can also
661
+ // do this manually if you have special requirements.
662
+ vis_core:: default_config ( ) ;
663
+
664
+ // Initialize some analyzer-tools. These will be moved into the analyzer closure
665
+ // later on.
666
+ let mut analyzer = vis_core:: analyzer:: FourierBuilder :: new ( )
667
+ . length ( 512 )
668
+ . window ( vis_core:: analyzer:: window:: nuttall)
669
+ . plan ( ) ;
670
+
671
+ let spectrum = vis_core:: analyzer:: Spectrum :: new ( vec ! [ 0.0 ; analyzer. buckets( ) ] , 0.0 , 1.0 ) ;
672
+
673
+ let mut frames = vis_core:: Visualizer :: new (
674
+ AnalyzerResult {
675
+ spectrum,
676
+ volume : 0.0 ,
677
+ beat : 0.0 ,
678
+ } ,
679
+ // This closure is the "analyzer". It will be executed in a loop to always
680
+ // have the latest data available.
681
+ move |info, samples| {
682
+ analyzer. analyze ( samples) ;
683
+
684
+ info. spectrum . fill_from ( & analyzer. average ( ) ) ;
685
+ info. volume = samples. volume ( 0.3 ) * 400.0 ;
686
+ info. beat = info. spectrum . slice ( 50.0 , 100.0 ) . max ( ) * 0.01 ;
687
+ info
688
+ } ,
689
+ )
690
+ // Build the frame iterator which is the base of your loop later on
691
+ . frames ( ) ;
692
+
693
+ for frame in frames. iter ( ) {
694
+ // This is just a primitive example, your vis core belongs here
695
+
696
+ frame. info ( |info| {
697
+ for serialdev in serialdevs {
698
+ eq_cmd (
699
+ serialdev,
700
+ & [
701
+ info. volume as u8 ,
702
+ info. volume as u8 ,
703
+ info. volume as u8 ,
704
+ info. volume as u8 ,
705
+ info. volume as u8 ,
706
+ info. volume as u8 ,
707
+ info. volume as u8 ,
708
+ info. volume as u8 ,
709
+ info. volume as u8 ,
710
+ ] ,
711
+ )
712
+ }
713
+ } ) ;
714
+ thread:: sleep ( Duration :: from_millis ( 30 ) ) ;
715
+ }
716
+ }
717
+
639
718
/// Display 9 values in equalizer diagram starting from the middle, going up and down
640
719
/// TODO: Implement a commandline parameter for this
641
720
fn eq_cmd ( serialdev : & str , vals : & [ u8 ] ) {
0 commit comments