nooise 1.0.0

Fluid focus music for the terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use rand::Rng;

pub(crate) struct WhiteNoise {
    last: f32,
}

impl WhiteNoise {
    pub(crate) fn new() -> Self {
        Self { last: 0.0 }
    }

    pub(crate) fn next_filtered<R: Rng>(&mut self, rng: &mut R, smoothing: f32) -> f32 {
        let white = rng.gen_range(-1.0..1.0);
        self.last += (white - self.last) * smoothing.clamp(0.0, 1.0);
        self.last
    }
}