Deepnote Synthesizer Voice Library v1.0.0
A C++14 header-only library implementing the THX Deep Note effect
Loading...
Searching...
No Matches
scaler.hpp
Go to the documentation of this file.
1
34#pragma once
35
36#include "range.hpp"
37#include "util/namedtype.hpp"
38
39namespace deepnote
40{
41
42namespace nt
43{
44using InputRange = NamedType<Range, struct InputRangeTag>;
45using OutputRange = NamedType<Range, struct OutputRangeTag>;
46}; // namespace nt
47
48struct Scaler
49{
50 Scaler()
51 : input(Range(nt::RangeLow(0.0), nt::RangeHigh(1.0)))
52 , output(Range(nt::RangeLow(0.0), nt::RangeHigh(1.0)))
53 {
54 }
55
56 explicit Scaler(const nt::InputRange input, const nt::OutputRange output)
57 : input(input.get())
58 , output(output.get())
59 {
60 }
61
62 explicit Scaler(const nt::InputRange input)
63 : Scaler(input, nt::OutputRange(Range(nt::RangeLow(0.0), nt::RangeHigh(1.0))))
64 {
65 }
66
67 Scaler(const Scaler &other) = default;
68 Scaler &operator=(const Scaler &other) = default;
69
70 float operator()(const float value) const
71 {
72 //
73 // normalize the input value to a range between 0.0 and 1.0
74 // then scale it to the output range
75 // then offset it to the output start
76 //
77 return (normalize(value) * output.length()) + output.get_low().get();
78 }
79
80 private:
81 float normalize(const float value) const { return (value - input.get_low().get()) / input.length(); }
82
83 Range input;
84 Range output;
85};
86
87} // namespace deepnote
Type-safe wrapper utilities for the Deep Note synthesizer.
Range constraint and validation utilities for the Deep Note synthesizer.