pll: merge advance into update (like rpll)
This commit is contained in:
parent
971bc1109d
commit
10da2d38ae
@ -45,7 +45,7 @@ impl PLL {
|
|||||||
/// The signal's phase/frequency is reconstructed relative to the sampling period.
|
/// The signal's phase/frequency is reconstructed relative to the sampling period.
|
||||||
///
|
///
|
||||||
/// Args:
|
/// Args:
|
||||||
/// * `x`: New input phase sample.
|
/// * `x`: New input phase sample or None if a sample has been missed.
|
||||||
/// * `shift_frequency`: Frequency error scaling. The frequency gain per update is
|
/// * `shift_frequency`: Frequency error scaling. The frequency gain per update is
|
||||||
/// `1/(1 << shift_frequency)`.
|
/// `1/(1 << shift_frequency)`.
|
||||||
/// * `shift_phase`: Phase error scaling. The phase gain is `1/(1 << shift_phase)`
|
/// * `shift_phase`: Phase error scaling. The phase gain is `1/(1 << shift_phase)`
|
||||||
@ -55,36 +55,34 @@ impl PLL {
|
|||||||
/// A tuple of instantaneous phase and frequency (the current phase increment).
|
/// A tuple of instantaneous phase and frequency (the current phase increment).
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
x: i32,
|
x: Option<i32>,
|
||||||
shift_frequency: u8,
|
shift_frequency: u8,
|
||||||
shift_phase: u8,
|
shift_phase: u8,
|
||||||
) -> (i32, i32) {
|
) -> (i32, i32) {
|
||||||
debug_assert!((1..=30).contains(&shift_frequency));
|
debug_assert!((1..=30).contains(&shift_frequency));
|
||||||
debug_assert!((1..=30).contains(&shift_phase));
|
debug_assert!((1..=30).contains(&shift_phase));
|
||||||
let e = x.wrapping_sub(self.f);
|
let f = if let Some(x) = x {
|
||||||
self.f = self.f.wrapping_add(
|
let e = x.wrapping_sub(self.f);
|
||||||
(1i32 << (shift_frequency - 1))
|
self.f = self.f.wrapping_add(
|
||||||
.wrapping_add(e)
|
(1i32 << (shift_frequency - 1))
|
||||||
.wrapping_sub(self.x)
|
.wrapping_add(e)
|
||||||
>> shift_frequency,
|
.wrapping_sub(self.x)
|
||||||
);
|
>> shift_frequency,
|
||||||
self.x = x;
|
);
|
||||||
let f = self.f.wrapping_add(
|
self.x = x;
|
||||||
(1i32 << (shift_phase - 1))
|
self.f.wrapping_add(
|
||||||
.wrapping_add(e)
|
(1i32 << (shift_phase - 1))
|
||||||
.wrapping_sub(self.y)
|
.wrapping_add(e)
|
||||||
>> shift_phase,
|
.wrapping_sub(self.y)
|
||||||
);
|
>> shift_phase,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
self.x = self.x.wrapping_add(self.f);
|
||||||
|
self.f
|
||||||
|
};
|
||||||
self.y = self.y.wrapping_add(f);
|
self.y = self.y.wrapping_add(f);
|
||||||
(self.y, f)
|
(self.y, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Advance the PLL without providing a new timestamp.
|
|
||||||
pub fn advance(&mut self) -> (i32, i32) {
|
|
||||||
self.x = self.x.wrapping_add(self.f);
|
|
||||||
self.y = self.y.wrapping_add(self.f);
|
|
||||||
(self.y, self.f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user