mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 22:35:45 +00:00
added quick and dirty decibel approximation
This commit is contained in:
parent
2d8cedbd66
commit
97d5b68045
1 changed files with 20 additions and 0 deletions
20
utils.hh
20
utils.hh
|
|
@ -43,7 +43,27 @@ TYPE delta(TYPE x)
|
|||
template <typename TYPE>
|
||||
TYPE decibel(TYPE v)
|
||||
{
|
||||
#if 0
|
||||
return TYPE(10) * log10(v);
|
||||
#else
|
||||
static constexpr TYPE
|
||||
// 2*1024*10/l(10)
|
||||
scale = 8894.350989378597430295120259412072085389250678859091274024013479236L,
|
||||
inv1 = TYPE(1) / TYPE(1),
|
||||
inv3 = TYPE(1) / TYPE(3),
|
||||
inv5 = TYPE(1) / TYPE(5),
|
||||
inv7 = TYPE(1) / TYPE(7),
|
||||
inv9 = TYPE(1) / TYPE(9),
|
||||
inv11 = TYPE(1) / TYPE(11),
|
||||
inv13 = TYPE(1) / TYPE(13);
|
||||
TYPE x = v;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
x = sqrt(x);
|
||||
x = (x - TYPE(1)) / (x + TYPE(1));
|
||||
TYPE xx = x * x;
|
||||
return scale * x * (xx * (xx * (xx * (xx * (xx * (xx *
|
||||
inv13 + inv11) + inv9) + inv7) + inv5) + inv3) + inv1);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue