moved sinc() to utils

This commit is contained in:
Ahmet Inan 2019-01-03 19:50:18 +01:00
commit 6769872b39
4 changed files with 9 additions and 10 deletions

View file

@ -56,6 +56,7 @@ Some everyday helpers:
* [signum function](https://en.wikipedia.org/wiki/Sign_function)
* [lerp function](https://en.wikipedia.org/wiki/Linear_interpolation)
* [probability density function](https://en.wikipedia.org/wiki/Probability_density_function) of the [normal distribution](https://en.wikipedia.org/wiki/Normal_distribution)
* [sinc function](https://en.wikipedia.org/wiki/Sinc_function)
### [resampler.hh](resampler.hh)

View file

@ -10,6 +10,7 @@ Copyright 2018 Ahmet Inan <inan@aicodix.de>
#include "window.hh"
#include "spline.hh"
#include "utils.hh"
#include "const.hh"
namespace DSP {
@ -19,11 +20,6 @@ class Resampler
{
typedef DSP::UniformNaturalCubicSpline<TAPS * OVER, TYPE, TYPE> spline_type;
spline_type lpf;
static TYPE sinc(TYPE x)
{
return TYPE(0) == x ? TYPE(1) : std::sin(DSP::Const<TYPE>::Pi() * x) / (DSP::Const<TYPE>::Pi() * x);
}
public:
Resampler(TYPE cutoff, TYPE alpha)
{

View file

@ -29,6 +29,12 @@ TYPE normal_pdf(TYPE x, TYPE m, TYPE s)
return std::exp(-std::pow((x - m) / s, TYPE(2)) / TYPE(2)) / (Const<TYPE>::SqrtTwoPi() * s);
}
template <typename TYPE>
TYPE sinc(TYPE x)
{
return TYPE(0) == x ? TYPE(1) : std::sin(Const<TYPE>::Pi() * x) / (Const<TYPE>::Pi() * x);
}
}
#endif

View file

@ -9,6 +9,7 @@ Copyright 2018 Ahmet Inan <inan@aicodix.de>
#include "const.hh"
#include "kahan.hh"
#include "utils.hh"
#include "coeffs.hh"
namespace DSP {
@ -40,11 +41,6 @@ struct Hamming : public CoeffsFunc<TYPE>
template <typename TYPE>
class Lanczos : public CoeffsFunc<TYPE>
{
static TYPE sinc(TYPE x)
{
return TYPE(0) == x ? TYPE(1) : std::sin(Const<TYPE>::Pi() * x) / (Const<TYPE>::Pi() * x);
}
public:
TYPE operator () (int n, int N)
{
return sinc(TYPE(2 * n) / TYPE(N - 1) - TYPE(1));