|
|
@ -2,38 +2,8 @@ |
|
|
|
#define HECK_OSP_UTILS_HH |
|
|
|
|
|
|
|
#include "daisy_seed.h" |
|
|
|
#include "osp_types.hh" |
|
|
|
#include "utils.hh" |
|
|
|
|
|
|
|
namespace Heck::OSP { |
|
|
|
template<typename T> class Observer { |
|
|
|
|
|
|
|
public: |
|
|
|
bool on_change(T val_new, std::function<void(T val_current)> fn) |
|
|
|
{ |
|
|
|
if (val_new != val_current_) { |
|
|
|
val_current_ = val_new; |
|
|
|
fn(val_current_); |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
bool on_change_fuzzy(T val_new, T min_deviation, std::function<void(T val_current)> fn) |
|
|
|
{ |
|
|
|
if (std::abs(val_new - val_current_) >= min_deviation) { |
|
|
|
val_current_ = val_new; |
|
|
|
fn(val_current_); |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
private: |
|
|
|
T val_current_{}; |
|
|
|
}; |
|
|
|
} // namespace Heck::OSP
|
|
|
|
|
|
|
|
namespace Heck::OSP { |
|
|
|
namespace Sig { |
|
|
|
struct Delta { |
|
|
@ -50,7 +20,8 @@ namespace Heck::OSP { |
|
|
|
float history[1]; |
|
|
|
}; |
|
|
|
|
|
|
|
template<u32 SIZE> struct RingBuffer { |
|
|
|
template<u32 SIZE> |
|
|
|
struct RingBuffer { |
|
|
|
void init(float* buffer) |
|
|
|
{ |
|
|
|
buf_ = buffer; |
|
|
@ -83,7 +54,8 @@ namespace Heck::OSP { |
|
|
|
u32 size = SIZE; |
|
|
|
}; |
|
|
|
|
|
|
|
template<int SIZE> struct Delay101 { |
|
|
|
template<int SIZE> |
|
|
|
struct Delay101 { |
|
|
|
void init(Sig::RingBuffer<SIZE>* buff) |
|
|
|
{ |
|
|
|
buff_ = buff; |
|
|
|