1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-21 02:17:08 +00:00

Made an attempt to eliminate creeping tape processing accuracy misses, which implied factoring out the GCM and LCD functions, which I then felt didn't really amount to signal processing.

This commit is contained in:
Thomas Harte
2016-07-29 05:19:01 -04:00
parent 5c1614ce7b
commit e55db0cfe8
8 changed files with 197 additions and 34 deletions
+42
View File
@@ -13,11 +13,25 @@
namespace SignalProcessing {
/*!
Allows a repeating action running at an input rate to determine how many times it should
trigger an action that runs at an unrelated output rate; therefore it allows something with one
clock to sample something with another.
Uses a Bresenham-like error term internally for full-integral storage with no drift.
*/
class Stepper
{
public:
/*!
Establishes a stepper with a one-to-one conversion rate.
*/
Stepper() : Stepper(1,1) {}
/*!
Establishes a stepper that will receive steps at the @c input_rate and dictate the number
of steps that should be taken at the @c output_rate.
*/
Stepper(uint64_t output_rate, uint64_t input_rate) :
accumulated_error_(0),
input_rate_(input_rate),
@@ -26,6 +40,11 @@ class Stepper
adjustment_up_((int64_t)(output_rate % input_rate) << 1),
adjustment_down_((int64_t)input_rate << 1) {}
/*!
Advances one step at the input rate.
@returns the number of output steps.
*/
inline uint64_t step()
{
uint64_t update = whole_step_;
@@ -38,11 +57,34 @@ class Stepper
return update;
}
/*!
Advances by @c number_of_steps steps at the input rate.
@returns the number of output steps.
*/
inline uint64_t step(uint64_t number_of_steps)
{
uint64_t update = whole_step_ * number_of_steps;
accumulated_error_ += adjustment_up_ * (int64_t)number_of_steps;
if(accumulated_error_ > 0)
{
update += 1 + (uint64_t)(accumulated_error_ / adjustment_down_);
accumulated_error_ = (accumulated_error_ % adjustment_down_) - adjustment_down_;
}
return update;
}
/*!
@returns the output rate.
*/
inline uint64_t get_output_rate()
{
return output_rate_;
}
/*!
@returns the input rate.
*/
inline uint64_t get_input_rate()
{
return input_rate_;