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:
46
SignalProcessing/Stepper.hpp
Normal file
46
SignalProcessing/Stepper.hpp
Normal 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 */
|
Reference in New Issue
Block a user