File tree 1 file changed +14
-2
lines changed
1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -23,16 +23,28 @@ impl From<AmpFactor> for f32 {
23
23
}
24
24
}
25
25
26
- #[ inline]
27
26
fn decibels_to_linear ( decibels : f32 ) -> f32 {
28
27
f32:: powf ( 10.0f32 , decibels / 20.0 )
29
28
}
30
29
30
+ fn linear_to_decibels ( linear : f32 ) -> f32 {
31
+ 20.0 * f32:: log10 ( linear. abs ( ) )
32
+ }
33
+
31
34
impl Mul for AmpFactor {
32
35
type Output = Self ;
33
36
34
37
fn mul ( self , rhs : Self ) -> Self :: Output {
35
- todo ! ( )
38
+ match self {
39
+ AmpFactor :: Linear ( l1) => match rhs {
40
+ AmpFactor :: Linear ( l2) => Self :: Linear ( l1 * l2) ,
41
+ AmpFactor :: Decibel ( d2) => Self :: Linear ( l1 * decibels_to_linear ( d2) ) ,
42
+ } ,
43
+ AmpFactor :: Decibel ( d1) => match rhs {
44
+ AmpFactor :: Linear ( l2) => AmpFactor :: Decibel ( d1 * linear_to_decibels ( l2) ) ,
45
+ AmpFactor :: Decibel ( d2) => AmpFactor :: Decibel ( d1 * d2) ,
46
+ } ,
47
+ }
36
48
}
37
49
}
38
50
You can’t perform that action at this time.
0 commit comments