aboutsummaryrefslogtreecommitdiffstats
path: root/nihav-codec-support/src
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2022-06-16 16:32:34 +0200
committerKostya Shishkov <kostya.shishkov@gmail.com>2022-06-16 16:32:34 +0200
commit03d914bb5e76c7e83cf98a501238472732bf11c8 (patch)
tree7ce60abe4311552e7cb4be298ba05eefbab70ef9 /nihav-codec-support/src
parent27608aa646760a85d108d651814485ba66424a9b (diff)
downloadnihav-03d914bb5e76c7e83cf98a501238472732bf11c8.tar.gz
codec-support: add division support for FFTComplex
Diffstat (limited to 'nihav-codec-support/src')
-rw-r--r--nihav-codec-support/src/dsp/fft.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/nihav-codec-support/src/dsp/fft.rs b/nihav-codec-support/src/dsp/fft.rs
index 4629f75..9a80509 100644
--- a/nihav-codec-support/src/dsp/fft.rs
+++ b/nihav-codec-support/src/dsp/fft.rs
@@ -1,6 +1,6 @@
//! FFT and RDFT implementation.
use std::f32::{self, consts};
-use std::ops::{Not, Neg, Add, AddAssign, Sub, SubAssign, Mul, MulAssign};
+use std::ops::{Not, Neg, Add, AddAssign, Sub, SubAssign, Mul, MulAssign, Div};
use std::fmt;
/// Complex number.
@@ -26,6 +26,14 @@ impl FFTComplex {
pub fn scale(self, scale: f32) -> Self {
FFTComplex { re: self.re * scale, im: self.im * scale }
}
+ /// Returns squared modulus value of the complex number.
+ pub fn sq_modulus(self) -> f32 {
+ self.re * self.re + self.im * self.im
+ }
+ /// Returns reciprocal of the complex number.
+ pub fn reciprocal(self) -> Self {
+ !self.scale(self.sq_modulus())
+ }
}
impl Neg for FFTComplex {
@@ -87,6 +95,13 @@ impl MulAssign for FFTComplex {
}
}
+impl Div for FFTComplex {
+ type Output = FFTComplex;
+ fn div(self, other: Self) -> Self::Output {
+ self * other.reciprocal()
+ }
+}
+
impl fmt::Display for FFTComplex {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "({}, {})", self.re, self.im)