1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::sig::Signal;
use core::num::Wrapping;
const SEQUENCE: u64 = 0xb5ad4eceda1ce2a9;
#[derive(Default, Clone, Debug)]
#[allow(missing_copy_implementations)]
pub struct White {
x: Wrapping<u64>,
w: Wrapping<u64>,
}
impl White {
#[inline(always)]
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn noise(&mut self) -> Signal {
self.x *= self.x;
self.w += Wrapping(SEQUENCE);
self.x += self.w;
self.x = (self.x >> 32) | (self.x << 32);
Signal::from(
((self.x.0 as i32) as f64 + 0.5) * (i32::MAX as f64 + 0.5).recip(),
)
}
}