#include "SampleFilter.h" static double filter_taps[SAMPLEFILTER_TAP_NUM] = { 0.008343267095683641, 0.007149583224306389, 0.0014492517668354074, -0.013310605694094289, -0.03450422491286543, -0.05367579867194659, -0.058668616471107396, -0.038574347326520715, 0.010331418196167608, 0.08087666209830409, 0.15569629640166385, 0.21287259655532492, 0.23427451265344573, 0.21287259655532492, 0.15569629640166385, 0.08087666209830409, 0.010331418196167608, -0.038574347326520715, -0.058668616471107396, -0.05367579867194659, -0.03450422491286543, -0.013310605694094289, 0.0014492517668354074, 0.007149583224306389, 0.008343267095683641 }; void SampleFilter_init(SampleFilter* f) { int i; for(i = 0; i < SAMPLEFILTER_TAP_NUM; ++i) f->history[i] = 0; f->last_index = 0; } void SampleFilter_put(SampleFilter* f, double input) { f->history[f->last_index++] = input; if(f->last_index == SAMPLEFILTER_TAP_NUM) f->last_index = 0; } double SampleFilter_get(SampleFilter* f) { double acc = 0; int index = f->last_index, i; for(i = 0; i < SAMPLEFILTER_TAP_NUM; ++i) { index = index != 0 ? index-1 : SAMPLEFILTER_TAP_NUM-1; acc += f->history[index] * filter_taps[i]; }; return acc; }