added delta() and decibel() to utils

This commit is contained in:
Ahmet Inan 2019-01-03 20:20:56 +01:00
commit f3c22ed3cc
2 changed files with 14 additions and 0 deletions

View file

@ -57,6 +57,8 @@ Some everyday helpers:
* [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)
* [delta function](https://en.wikipedia.org/wiki/Dirac_delta_function)
* [decibel function](https://en.wikipedia.org/wiki/Decibel)
### [resampler.hh](resampler.hh)

View file

@ -35,6 +35,18 @@ TYPE sinc(TYPE x)
return TYPE(0) == x ? TYPE(1) : std::sin(Const<TYPE>::Pi() * x) / (Const<TYPE>::Pi() * x);
}
template <typename TYPE>
TYPE delta(TYPE x)
{
return TYPE(0) == x ? TYPE(1) : TYPE(0);
}
template <typename TYPE>
TYPE decibel(TYPE v)
{
return TYPE(10) * std::log10(v);
}
}
#endif