renamed Window and WinFunc to Coeffs and CoeffsFunc and moved to own header

This commit is contained in:
Ahmet Inan 2019-01-03 19:44:31 +01:00
commit 6c5a418693
2 changed files with 57 additions and 36 deletions

49
coeffs.hh Normal file
View file

@ -0,0 +1,49 @@
/*
Coefficient array helper
Copyright 2018 Ahmet Inan <inan@aicodix.de>
*/
#ifndef COEFFS_HH
#define COEFFS_HH
namespace DSP {
template <typename TYPE>
struct CoeffsFunc
{
virtual TYPE operator () (int, int) = 0;
virtual ~CoeffsFunc() = default;
};
template <int TAPS, typename TYPE>
class Coeffs
{
TYPE w[TAPS];
public:
Coeffs(CoeffsFunc<TYPE> *func)
{
for (int n = 0; n < TAPS; ++n)
w[n] = (*func)(n, TAPS);
}
Coeffs(CoeffsFunc<TYPE> *func0, CoeffsFunc<TYPE> *func1)
{
for (int n = 0; n < TAPS; ++n)
w[n] = (*func0)(n, TAPS) * (*func1)(n, TAPS);
}
void normalize(TYPE divisor = 1)
{
TYPE sum(0);
for (int n = 0; n < TAPS; ++n)
sum += w[n];
for (int n = 0; n < TAPS; ++n)
w[n] /= divisor * std::abs(sum);
}
inline TYPE operator () (int n) { return n >= 0 && n < TAPS ? w[n] : 0; }
inline operator const TYPE * () const { return w; }
};
}
#endif