From 26293db40f8ac62f3971e0e9dbbc0bf3439e61c0 Mon Sep 17 00:00:00 2001 From: Vasile Vilvoiu Date: Tue, 29 Dec 2020 19:33:03 +0200 Subject: Initial commit --- src/value-map.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/value-map.cpp (limited to 'src/value-map.cpp') 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 + * + * 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(output[i], this->lower_, 0.0f); + output[i] = 1.0f - output[i] / this->lower_; + } + + return output; +} \ No newline at end of file -- cgit v1.2.3