1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-27 01:31:42 +00:00

Eliminated foolish double indirection on phase history.

This commit is contained in:
Thomas Harte 2017-07-15 22:40:38 -04:00
parent 253f9603ed
commit 4489f120f9
2 changed files with 6 additions and 8 deletions

View File

@ -17,9 +17,8 @@ DigitalPhaseLockedLoop::DigitalPhaseLockedLoop(int clocks_per_bit, int tolerance
tolerance_(tolerance), tolerance_(tolerance),
phase_(0), phase_(0),
window_length_(clocks_per_bit), window_length_(clocks_per_bit),
phase_error_pointer_(0) { phase_error_pointer_(0),
phase_error_history_.reset(new std::vector<int>(length_of_history, 0)); phase_error_history_(length_of_history, 0) {}
}
void DigitalPhaseLockedLoop::run_for_cycles(int number_of_cycles) { void DigitalPhaseLockedLoop::run_for_cycles(int number_of_cycles) {
phase_ += number_of_cycles; phase_ += number_of_cycles;
@ -51,15 +50,14 @@ void DigitalPhaseLockedLoop::post_phase_error(int error) {
phase_ -= (error + 1) >> 1; phase_ -= (error + 1) >> 1;
// use the average of the last few errors to affect frequency // 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; phase_error_pointer_ = (phase_error_pointer_ + 1)%phase_error_history_size;
int total_error = 0; int total_error = 0;
for(size_t c = 0; c < phase_error_history_size; c++) { 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); int denominator = (int)(phase_error_history_size * 4);
window_length_ += (total_error + (denominator >> 1)) / denominator; window_length_ += (total_error + (denominator >> 1)) / denominator;

View File

@ -52,7 +52,7 @@ class DigitalPhaseLockedLoop {
Delegate *delegate_; Delegate *delegate_;
void post_phase_error(int error); 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_; size_t phase_error_pointer_;
int phase_; int phase_;