summaryrefslogtreecommitdiff
path: root/src/value-map.cpp
diff options
context:
space:
mode:
authorVasile Vilvoiu <vasi.vilvoiu@gmail.com>2020-12-29 19:33:03 +0200
committerVasile Vilvoiu <vasi.vilvoiu@gmail.com>2020-12-29 19:33:03 +0200
commit26293db40f8ac62f3971e0e9dbbc0bf3439e61c0 (patch)
tree218c93aba851c3c3123e9e72d25c974aa65cfd52 /src/value-map.cpp
Initial commit
Diffstat (limited to 'src/value-map.cpp')
-rw-r--r--src/value-map.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/value-map.cpp b/src/value-map.cpp
new file mode 100644
index 0000000..4e6a231
--- /dev/null
+++ b/src/value-map.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2020-2021 Vasile Vilvoiu <vasi.vilvoiu@gmail.com>
+ *
+ * specgram is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+#include "value-map.hpp"
+
+ValueMap::ValueMap(double lower, double upper) : lower_(lower), upper_(upper)
+{
+}
+
+dBFSValueMap::dBFSValueMap(double mindb) : ValueMap(mindb, 0)
+{
+}
+
+RealWindow
+dBFSValueMap::Map(const RealWindow& input)
+{
+ auto n = input.size();
+ RealWindow output;
+ output.resize(n);
+
+ for (unsigned int i = 0; i < n; i ++) {
+ output[i] = 20.0 * std::log10(input[i] / n);
+ output[i] = std::clamp<double>(output[i], this->lower_, 0.0f);
+ output[i] = 1.0f - output[i] / this->lower_;
+ }
+
+ return output;
+} \ No newline at end of file