mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
moved sinc() to utils
This commit is contained in:
parent
6c5a418693
commit
6769872b39
4 changed files with 9 additions and 10 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
6
utils.hh
6
utils.hh
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue