1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-07-24 22:24:23 +00:00

Tidied a little, started working towards supporting speaker output.

This commit is contained in:
Thomas Harte
2016-01-12 22:19:56 -05:00
parent 3437781abd
commit 84ba4e2900
5 changed files with 145 additions and 74 deletions

View File

@@ -0,0 +1,46 @@
//
// Stepper.hpp
// Clock Signal
//
// Created by Thomas Harte on 12/01/2016.
// Copyright © 2016 Thomas Harte. All rights reserved.
//
#ifndef Stepper_hpp
#define Stepper_hpp
#include <stdint.h>
namespace SignalProcessing {
class Stepper
{
public:
Stepper(uint64_t input_rate, uint64_t output_rate)
{
whole_step_ = output_rate / input_rate;
adjustment_up_ = (int64_t)(output_rate % input_rate) << 1;
adjustment_down_ = (int64_t)input_rate << 1;
}
inline uint64_t update()
{
uint64_t update = whole_step_;
accumulated_error_ += adjustment_up_;
if(accumulated_error_ > 0)
{
update++;
accumulated_error_ -= adjustment_down_;
}
return update;
}
private:
uint64_t whole_step_;
int64_t adjustment_up_, adjustment_down_;
int64_t accumulated_error_;
};
}
#endif /* Stepper_hpp */