1pub const CUSTOM_WIDTH: usize = 32;
5
6pub type CustomWaveform = [f32; CUSTOM_WIDTH];
8
9pub(crate) fn sine(period: f32) -> f32 {
11 f32::sin(period * std::f32::consts::TAU)
12}
13
14pub(crate) fn triangle(period: f32) -> f32 {
16 -(period - 0.5).abs() * 4.0 + 1.0
17}
18
19pub(crate) fn rec_sine(period: f32) -> f32 {
21 if period < 0.5 {
22 f32::sin(period * std::f32::consts::TAU) * 2.0 - 1.0
23 }
24 else {
25 -1.0
26 }
27}
28
29pub(crate) fn saw(period: f32) -> f32 {
31 period * 2.0 - 1.0
32}
33
34pub(crate) fn square(period: f32) -> f32 {
36 if period < 0.5 {1.0}
37 else {-1.0}
38}
39
40pub(crate) fn pulse(period: f32) -> f32 {
42 if period < 0.25 {1.0}
43 else {-1.0}
44}
45
46pub(crate) fn noise() -> f32 {
48 rand::random::<f32>() * 2.0 - 1.0
49}
50
51pub(crate) fn custom(period: f32, data: &CustomWaveform) -> f32{
53 let index = (period * CUSTOM_WIDTH as f32).floor() as usize;
54 data[index]
55}