mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-25 03:32:01 +00:00
Eliminated foolish double indirection on phase history.
This commit is contained in:
parent
6ca712b498
commit
ab51bc443b
@ -17,9 +17,8 @@ DigitalPhaseLockedLoop::DigitalPhaseLockedLoop(int clocks_per_bit, int tolerance
|
||||
tolerance_(tolerance),
|
||||
phase_(0),
|
||||
window_length_(clocks_per_bit),
|
||||
phase_error_pointer_(0) {
|
||||
phase_error_history_.reset(new std::vector<int>(length_of_history, 0));
|
||||
}
|
||||
phase_error_pointer_(0),
|
||||
phase_error_history_(length_of_history, 0) {}
|
||||
|
||||
void DigitalPhaseLockedLoop::run_for_cycles(int number_of_cycles) {
|
||||
phase_ += number_of_cycles;
|
||||
@ -51,15 +50,14 @@ void DigitalPhaseLockedLoop::post_phase_error(int error) {
|
||||
phase_ -= (error + 1) >> 1;
|
||||
|
||||
// use the average of the last few errors to affect frequency
|
||||
std::vector<int> *phase_error_history = phase_error_history_.get();
|
||||
size_t phase_error_history_size = phase_error_history->size();
|
||||
size_t phase_error_history_size = phase_error_history_.size();
|
||||
|
||||
(*phase_error_history)[phase_error_pointer_] = error;
|
||||
phase_error_history_[phase_error_pointer_] = error;
|
||||
phase_error_pointer_ = (phase_error_pointer_ + 1)%phase_error_history_size;
|
||||
|
||||
int total_error = 0;
|
||||
for(size_t c = 0; c < phase_error_history_size; c++) {
|
||||
total_error += (*phase_error_history)[c];
|
||||
total_error += phase_error_history_[c];
|
||||
}
|
||||
int denominator = (int)(phase_error_history_size * 4);
|
||||
window_length_ += (total_error + (denominator >> 1)) / denominator;
|
||||
|
@ -52,7 +52,7 @@ class DigitalPhaseLockedLoop {
|
||||
Delegate *delegate_;
|
||||
|
||||
void post_phase_error(int error);
|
||||
std::unique_ptr<std::vector<int>> phase_error_history_;
|
||||
std::vector<int> phase_error_history_;
|
||||
size_t phase_error_pointer_;
|
||||
|
||||
int phase_;
|
||||
|
Loading…
Reference in New Issue
Block a user