From 47bbfdbf1e2a6193157397938e76b16a1f60e789 Mon Sep 17 00:00:00 2001 From: Vasile Vilvoiu Date: Fri, 16 Jul 2021 18:32:27 +0300 Subject: Add support for arbitrary scales, with custom units. Add support for linear scales. Logging of scale to stderr. Closes #9. --- src/value-map.hpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'src/value-map.hpp') diff --git a/src/value-map.hpp b/src/value-map.hpp index d162f45..2f32d92 100644 --- a/src/value-map.hpp +++ b/src/value-map.hpp @@ -15,15 +15,18 @@ #include enum class ValueMapType { - kdBFS + kLinear, + kDecibel }; class ValueMap { protected: const double lower_; const double upper_; + const std::string unit_; + + ValueMap(double lower_, double upper, const std::string& unit); - ValueMap(double lower_, double upper); public: ValueMap() = delete; @@ -31,18 +34,25 @@ public: auto GetUpperBound() const { return upper_; } virtual RealWindow Map(const RealWindow& input) = 0; - virtual std::string GetUnit() const = 0; - virtual std::string GetName() const = 0; + virtual std::string GetUnit() const; + + static std::unique_ptr Build(ValueMapType type, double lower, double upper, std::string unit); +}; + +class LinearValueMap : public ValueMap { +public: + LinearValueMap(double lower, double upper, const std::string& unit); + + RealWindow Map(const RealWindow& input) override; }; -class dBFSValueMap : public ValueMap { -private: +class DecibelValueMap : public ValueMap { public: - explicit dBFSValueMap(double mindb); + /* unit parameter should NOT contain "dB" prefix */ + DecibelValueMap(double lower, double upper, const std::string& unit); RealWindow Map(const RealWindow& input) override; - std::string GetUnit() const override { return "dBFS"; } - std::string GetName() const override { return "dBFS"; } + std::string GetUnit() const override; }; #endif \ No newline at end of file -- cgit v1.2.3