From f3c22ed3cca0961c29806f0387ac3585e4af3ee4 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Thu, 3 Jan 2019 20:20:56 +0100 Subject: [PATCH] added delta() and decibel() to utils --- README.md | 2 ++ utils.hh | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 1e16bdb..97e6cb7 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/utils.hh b/utils.hh index c155ee2..415ff3e 100644 --- a/utils.hh +++ b/utils.hh @@ -35,6 +35,18 @@ TYPE sinc(TYPE x) return TYPE(0) == x ? TYPE(1) : std::sin(Const::Pi() * x) / (Const::Pi() * x); } +template +TYPE delta(TYPE x) +{ + return TYPE(0) == x ? TYPE(1) : TYPE(0); +} + +template +TYPE decibel(TYPE v) +{ + return TYPE(10) * std::log10(v); +} + } #endif