Cogs.Core
dBToLinearTask.cpp
1#include "SinglePingIsoSurfacesTasks.h"
2#include "dBToLinearTask.h"
3#include "Platform/Instrumentation.h"
4
5#include "Foundation/Logging/Logger.h"
6
7#include <algorithm>
8
9using std::transform;
10using std::exp2;
11using std::min;
12using std::numeric_limits;
13
14using namespace Cogs::Core;
15
16namespace{
17 Cogs::Logging::Log logger = Cogs::Logging::getLogger("EchoLinearizeTask");
18
19
20 static const float factorA = (float)(log2(10.0) / 10.0);
21 static const float factorAe = (float)(log(10.0) / 10.0);
22 static const float scale_dB = 100.0f; // Constant added to dB value to utilize both positive and negative exponents.
23
24 inline float linearize(float v)
25 {
26 float w = exp2(factorA*(v + scale_dB));
27 if (!isfinite(w)) {
28 w = v < 0.f ? 0.f : numeric_limits<float>::max();
29 }
30 return w;
31 };
32
33
34}
35
36float EchoSounder::dBToLinear(float v)
37{
38 return ::linearize(v);
39 //float w = exp2(factorA*(v + scale_dB));
40 //if (!isfinite(w)) {
41 // w = v < 0.f ? 0.f : numeric_limits<float>::max();
42 //}
43 //return w;
44};
45
46void EchoSounder::dBToLinearTask::operator()()
47{
48 CpuInstrumentationScope(SCOPE_ECHOSOUNDER, "Linearize");
49
50 if (!std::isfinite(overflowThreshold)) overflowThreshold = std::numeric_limits<float>::max();
51
52 auto end = in + N;
53 while (in < end)
54 {
55 auto val = *in++;
56
57 if (overflowThreshold < val) val = 0.f;
58 else val = ::linearize(val);
59
60 *out++ = val;
61 }
62}
Log implementation class.
Definition: LogManager.h:139
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Definition: LogManager.h:180
void COGSFOUNDATION_API log(const char *message, const char *source, const Category category, uint32_t errorNumber)
Logs the given message with source and category.
Definition: LogManager.cpp:306