1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00

Ensured offset means exactly one thing.

This commit is contained in:
Thomas Harte 2017-07-21 20:58:17 -04:00
parent 807e1d36d5
commit 163c0f1b44

View File

@ -47,8 +47,8 @@ void DigitalPhaseLockedLoop::add_pulse() {
} }
} }
void DigitalPhaseLockedLoop::post_phase_offset(int phase, int offset) { void DigitalPhaseLockedLoop::post_phase_offset(int new_phase, int new_offset) {
offset_history_[offset_history_pointer_] = offset; offset_history_[offset_history_pointer_] = new_offset;
offset_history_pointer_ = (offset_history_pointer_ + 1) % offset_history_.size(); offset_history_pointer_ = (offset_history_pointer_ + 1) % offset_history_.size();
// use an unweighted average of the stored offsets to compute current window size, // use an unweighted average of the stored offsets to compute current window size,
@ -65,7 +65,7 @@ void DigitalPhaseLockedLoop::post_phase_offset(int phase, int offset) {
window_length_ = total_spacing / total_divisor; window_length_ = total_spacing / total_divisor;
} }
int error = phase - (window_length_ >> 1); int error = new_phase - (window_length_ >> 1);
// use a simple spring mechanism as a lowpass filter for phase // use a simple spring mechanism as a lowpass filter for phase
phase_ -= (error + 1) >> 1; phase_ -= (error + 1) >> 1;