2016-07-12 02:12:58 +00:00
|
|
|
//
|
|
|
|
// DigitalPhaseLockedLoop.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 11/07/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef DigitalPhaseLockedLoop_hpp
|
|
|
|
#define DigitalPhaseLockedLoop_hpp
|
|
|
|
|
2016-07-13 00:23:56 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2016-07-12 02:12:58 +00:00
|
|
|
namespace Storage {
|
|
|
|
|
|
|
|
class DigitalPhaseLockedLoop {
|
|
|
|
public:
|
|
|
|
/*!
|
|
|
|
Instantiates a @c DigitalPhaseLockedLoop.
|
|
|
|
|
|
|
|
@param clocks_per_bit The expected number of cycles between each bit of input.
|
|
|
|
@param tolerance The maximum tolerance for bit windows — extremes will be clocks_per_bit ± tolerance.
|
2016-07-13 00:23:56 +00:00
|
|
|
@param length_of_history The number of historic pulses to consider in locking to phase.
|
2016-07-12 02:12:58 +00:00
|
|
|
*/
|
2016-07-14 23:42:01 +00:00
|
|
|
DigitalPhaseLockedLoop(int clocks_per_bit, int tolerance, int length_of_history);
|
2016-07-12 02:12:58 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Runs the loop, impliedly posting no pulses during that period.
|
|
|
|
|
|
|
|
@c number_of_cycles The time to run the loop for.
|
|
|
|
*/
|
2016-07-14 23:42:01 +00:00
|
|
|
void run_for_cycles(int number_of_cycles);
|
2016-07-12 02:12:58 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Announces a pulse at the current time.
|
|
|
|
*/
|
|
|
|
void add_pulse();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
A receiver for PCM output data; called upon every recognised bit.
|
|
|
|
*/
|
|
|
|
class Delegate {
|
|
|
|
public:
|
2016-07-13 01:42:23 +00:00
|
|
|
virtual void digital_phase_locked_loop_output_bit(int value) = 0;
|
2016-07-12 02:12:58 +00:00
|
|
|
};
|
|
|
|
void set_delegate(Delegate *delegate)
|
|
|
|
{
|
|
|
|
_delegate = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Delegate *_delegate;
|
2016-07-13 00:23:56 +00:00
|
|
|
|
2016-07-14 23:42:01 +00:00
|
|
|
std::unique_ptr<int> _pulse_history;
|
|
|
|
int _current_window_length;
|
|
|
|
int _length_of_history;
|
|
|
|
int _samples_collected;
|
2016-07-13 00:23:56 +00:00
|
|
|
|
2016-07-14 23:42:01 +00:00
|
|
|
int _next_pulse_time;
|
|
|
|
int _window_offset;
|
2016-07-13 00:23:56 +00:00
|
|
|
bool _window_was_filled;
|
|
|
|
|
2016-07-14 23:42:01 +00:00
|
|
|
int _clocks_per_bit;
|
|
|
|
int _tolerance;
|
2016-07-12 02:12:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DigitalPhaseLockedLoop_hpp */
|