// Copyright 2015-2020 Mobilinkd LLC. #pragma once #include "Filter.h" #include #include namespace modemm17 { template struct BaseFirFilter : FilterBase { BaseFirFilter(const std::array& taps) : taps_(taps) { history_.fill(0.0); } float operator()(float input) override { history_[pos_++] = input; if (pos_ == N) pos_ = 0; float result = 0.0; size_t index = pos_; for (size_t i = 0; i != N; ++i) { index = (index != 0 ? index - 1 : N - 1); result += history_.at(index) * taps_.at(i); } return result; } void reset() { history_.fill(0.0); pos_ = 0; } private: const std::array& taps_; std::array history_; size_t pos_ = 0; }; template BaseFirFilter makeFirFilter(const std::array& taps) { return std::move(BaseFirFilter(taps)); } } // modemm17