diff --git a/src/utils.hh b/src/utils.hh index bdf7eb7..d48fee2 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -10,7 +10,7 @@ namespace Heck::OSP { float scalen_min_max(float val, float min, float max); float scalen_center_range(float val, float center, float range); -} // namespace Heck +} // namespace Heck::OSP namespace Heck::OSP { @@ -27,7 +27,7 @@ namespace Heck::OSP { u32 time_last_exec_{}; u32 time_period_{}; }; -} // namespace Heck +} // namespace Heck::OSP namespace Heck::OSP { template class Observer { @@ -56,5 +56,77 @@ namespace Heck::OSP { private: T val_current_{}; }; -} // namespace Heck -#endif // HECK_DAISY_UTILS_HH` \ No newline at end of file +} // namespace Heck::OSP + +namespace Heck::OSP { + namespace Sig { + struct Delta { + float process(float in) + { + float delta = in - history[0]; + if (abs(delta) < 0.4) { + delta == 0; + } + history[0] = in; + return delta; + } + + float history[1]; + }; + + template struct RingBuffer { + void init(float* buffer) + { + buf_ = buffer; + } + + void push_front(float in) + { + u32 index_new = index_first_ + 1; + if (index_new < SIZE) { + index_first_ = index_new; + } else { + index_first_ = 0; + } + + buf_[index_first_] = in; + } + + // index 0 reads the last sample written + float get(u32 index) const + { + u32 pos_read = index_first_ + index; + if (!(pos_read < SIZE)) { + pos_read = pos_read - (SIZE - 1); + } + return buf_[pos_read]; + } + + u32 index_first_{ SIZE - 1 }; + float* buf_; + u32 size = SIZE; + }; + + template struct Delay101 { + void init(Sig::RingBuffer* buff) + { + buff_ = buff; + } + + float process(float sig_in) + { + buff_->push_front(sig_in + (sig_tap1_ * delayfb_)); + sig_tap1_ = buff_->get(buff_->size - (u32)((delaytime_ * delaytime_) * buff_->size)); + return sig_in + sig_tap1_; + } + + float delayfb_; // 0-1 + float delaytime_; // 0-1 + float sig_tap1_; + Sig::RingBuffer* buff_; + }; + + + } // namespace Sig +} // namespace Heck::OSP +#endif // HECK_DAISY_UTILS_HH \ No newline at end of file