Skip to content

Commit 3bb4a08

Browse files
committed
Add Mul implementation
1 parent edfce2d commit 3bb4a08

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/source/amplify.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,28 @@ impl From<AmpFactor> for f32 {
2323
}
2424
}
2525

26-
#[inline]
2726
fn decibels_to_linear(decibels: f32) -> f32 {
2827
f32::powf(10.0f32, decibels / 20.0)
2928
}
3029

30+
fn linear_to_decibels(linear: f32) -> f32 {
31+
20.0 * f32::log10(linear.abs())
32+
}
33+
3134
impl Mul for AmpFactor {
3235
type Output = Self;
3336

3437
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+
}
3648
}
3749
}
3850

0 commit comments

Comments
 (0)