diff --git a/dsp/src/accu.rs b/dsp/src/accu.rs index 6560896..99369b2 100644 --- a/dsp/src/accu.rs +++ b/dsp/src/accu.rs @@ -5,8 +5,8 @@ pub struct Accu { } impl Accu { - pub fn new(state: i32, step: i32) -> Accu { - Accu { state, step } + pub fn new(state: i32, step: i32) -> Self { + Self { state, step } } } diff --git a/dsp/src/complex.rs b/dsp/src/complex.rs index bb928e0..9829312 100644 --- a/dsp/src/complex.rs +++ b/dsp/src/complex.rs @@ -15,9 +15,9 @@ impl Complex { /// Complex::::from_angle(-1 << 30); // -pi/2 /// ``` #[inline(always)] - pub fn from_angle(angle: i32) -> Complex { + pub fn from_angle(angle: i32) -> Self { let (c, s) = cossin(angle); - Complex(c, s) + Self(c, s) } /// Return the absolute square (the squared magnitude). diff --git a/dsp/src/iir_int.rs b/dsp/src/iir_int.rs index 2edca3a..93626de 100644 --- a/dsp/src/iir_int.rs +++ b/dsp/src/iir_int.rs @@ -19,7 +19,7 @@ impl Vec5 { /// /// # Returns /// 2nd-order IIR filter coefficients in the form [b0,b1,b2,a1,a2]. a0 is set to -1. - pub fn lowpass(f: f32, q: f32, k: f32) -> Vec5 { + pub fn lowpass(f: f32, q: f32, k: f32) -> Self { // 3rd order Taylor approximation of sin and cos. let f = f * 2. * PI; let fsin = f - f * f * f / 6.; @@ -31,7 +31,7 @@ impl Vec5 { let a1 = (2. * fcos / a0) as _; let a2 = ((alpha - 1.) / a0) as _; - Vec5([b0, 2 * b0, b0, a1, a2]) + Self([b0, 2 * b0, b0, a1, a2]) } } diff --git a/dsp/src/lockin.rs b/dsp/src/lockin.rs index 19f13e2..61627cf 100644 --- a/dsp/src/lockin.rs +++ b/dsp/src/lockin.rs @@ -1,4 +1,7 @@ -use super::{iir_int::{IIR, Vec5}, Accu, Complex}; +use super::{ + iir_int::{Vec5, IIR}, + Accu, Complex, +}; use serde::{Deserialize, Serialize}; #[derive(Copy, Clone, Default, Deserialize, Serialize)] @@ -10,10 +13,8 @@ pub struct Lockin { impl Lockin { /// Create a new Lockin with given IIR coefficients. pub fn new(ba: Vec5) -> Self { - let mut iir = IIR::default(); - iir.ba = ba; - Lockin { - iir, + Self { + iir: IIR { ba, ..Default::default() }, state: [Vec5::default(); 2], } } diff --git a/dsp/src/rpll.rs b/dsp/src/rpll.rs index 9759cf9..79a2b30 100644 --- a/dsp/src/rpll.rs +++ b/dsp/src/rpll.rs @@ -22,8 +22,8 @@ impl RPLL { /// /// Returns: /// Initialized RPLL instance. - pub fn new(dt2: u8) -> RPLL { - RPLL { + pub fn new(dt2: u8) -> Self { + Self { dt2, ..Default::default() } @@ -107,7 +107,7 @@ mod test { impl Harness { fn default() -> Self { - Harness { + Self { rpll: RPLL::new(8), dt2: 8, shift_frequency: 9,