1
1
// use std::clone;
2
2
3
- #[ derive( Clone ) ]
3
+ use crate :: osc:: ShapeMath :: { Sawwave , Sinewave , Squarewave , Trianglewave } ;
4
+
5
+ #[ derive( Debug , Clone , Copy ) ]
4
6
pub enum ShapeMath {
5
7
Sinewave ,
6
8
Squarewave ,
7
9
Sawwave ,
8
10
Trianglewave
9
11
}
10
12
11
- #[ derive( Clone ) ]
13
+ #[ derive( Debug , Clone ) ]
12
14
pub struct Oscillator {
13
15
amp : f32 ,
14
16
freq : f32 ,
@@ -19,16 +21,16 @@ pub struct Oscillator {
19
21
impl ShapeMath {
20
22
pub fn compute ( & self , freq : f32 , time : f32 ) -> f32 {
21
23
match self {
22
- ShapeMath :: Sinewave => ( 2.0 * std:: f32:: consts:: PI * freq * time) . sin ( ) ,
23
- ShapeMath :: Squarewave => ( 2.0 * std:: f32:: consts:: PI * freq * time) . sin ( ) . signum ( ) ,
24
- ShapeMath :: Sawwave => 2.0 * ( freq * time - freq * time. floor ( ) ) - 1.0 ,
25
- ShapeMath :: Trianglewave => ( 2.0 * ( freq * time - 0.5 ) ) . abs ( ) - 1.0 ,
24
+ Self :: Sinewave => ( 2.0 * std:: f32:: consts:: PI * freq * time) . sin ( ) ,
25
+ Self :: Squarewave => ( 2.0 * std:: f32:: consts:: PI * freq * time) . sin ( ) . signum ( ) ,
26
+ Self :: Sawwave => 2.0 * ( freq * time - freq * time. floor ( ) ) - 1.0 ,
27
+ Self :: Trianglewave => ( 2.0 * ( freq * time - 0.5 ) ) . abs ( ) - 1.0 ,
26
28
}
27
29
}
28
30
}
29
31
30
32
impl Oscillator {
31
- pub fn new ( amp : f32 , freq : f32 , shape : ShapeMath ) -> Oscillator {
33
+ pub fn new ( amp : f32 , freq : f32 , shape : ShapeMath ) -> Self {
32
34
Oscillator {
33
35
amp,
34
36
freq,
@@ -37,7 +39,7 @@ impl Oscillator {
37
39
}
38
40
}
39
41
40
- pub fn with_input ( amp : f32 , freq : f32 , shape : ShapeMath , input : Oscillator ) -> Oscillator {
42
+ pub fn with_input ( amp : f32 , freq : f32 , shape : ShapeMath , input : Oscillator ) -> Self {
41
43
Oscillator {
42
44
amp,
43
45
freq,
@@ -46,14 +48,14 @@ impl Oscillator {
46
48
}
47
49
}
48
50
49
- pub fn clone_osc ( & self ) -> Oscillator {
50
- Oscillator {
51
- amp : self . amp ,
52
- freq : self . freq ,
53
- shape : self . shape . clone ( ) ,
54
- input : self . input . clone ( ) ,
55
- }
56
- }
51
+ // pub fn clone_osc(&self) -> Self {
52
+ // Oscillator {
53
+ // amp: self.amp,
54
+ // freq: self.freq,
55
+ // shape: self.shape.clone(),
56
+ // input: self.input.clone(),
57
+ // }
58
+ // }
57
59
58
60
pub fn frequency_modulation ( & self , time : f32 ) -> f32 {
59
61
let input_freq = match & self . input {
0 commit comments