#include "filter_fir_crude.h"

FilterFIRCrude::FilterFIRCrude(const float* coeffs, size_t numTaps) :
_coeffs(coeffs), _histsize(numTaps), _index(0)
{
    _history = new float[_histsize];
    std::memset(_history, 0 , numTaps*sizeof(float));
}

float FilterFIRCrude::process(float input)
{
    _history[_index] = input;

    float result = 0.0f;
    size_t idx = _index;
    for (size_t i = 0; i < _histsize; ++i)
    {
        result += _coeffs[i] * _history[idx];
        if (idx == 0)
        {
            idx = _histsize - 1;
        } else
        {
            --idx;
        }
        _index = (_index + 1) % _histsize;
    }
    return result;
}

