shady_audio/bar_processor/
config.rs

1use std::{num::NonZero, ops::Range};
2
3/// Decides which interpolation strategy for the bars.
4#[derive(Debug, Clone, Copy, Hash)]
5pub enum InterpolationVariant {
6    /// No interpolation strategy should be used.
7    ///
8    /// Only the "supporting bars" (a.k.a. the bars which are picked up for a frequency range) which are calculated are going to be displayed.
9    None,
10
11    /// Use the linear interpolation.
12    ///
13    Linear,
14
15    /// Use the cubic spline interpolation (recommended since it's the smoothest).
16    CubicSpline,
17}
18
19/// Set the distribution of the bars.
20#[derive(Debug, Clone, Copy, Hash, Default)]
21pub enum BarDistribution {
22    /// Tell the [`Barprocessor`] to distribute the bars so that the frequency spectrum
23    /// looks like as if it would grow linear or in other words:
24    /// To make the bars look "natural" to us.
25    #[default]
26    Uniform,
27
28    /// Don't readjust the frequency bars so that it looks "natural" to us but
29    /// physically correct.
30    Natural,
31}
32
33/// The config options for [crate::BarProcessor].
34#[derive(Debug, Clone)]
35pub struct BarProcessorConfig {
36    /// Set the amount of bars which should be created.
37    pub amount_bars: NonZero<u16>,
38
39    /// Set the frequency range which the bar processor should consider.
40    pub freq_range: Range<NonZero<u16>>,
41
42    /// Decide how the bar values should be interpolated.
43    pub interpolation: InterpolationVariant,
44
45    /// Control how fast the bars should adjust to their new height.
46    /// Should be within the range `[0, 1]`.
47    pub sensitivity: f32,
48
49    /// Set the bar distribution.
50    /// In general you needn't use another value than its default.
51    pub bar_distribution: BarDistribution,
52}
53
54impl Default for BarProcessorConfig {
55    fn default() -> Self {
56        Self {
57            interpolation: InterpolationVariant::CubicSpline,
58            amount_bars: NonZero::new(30).unwrap(),
59            freq_range: NonZero::new(50).unwrap()..NonZero::new(10_000).unwrap(),
60            sensitivity: 0.77,
61            bar_distribution: BarDistribution::Uniform,
62        }
63    }
64}