Mozzi  version v2.0
sound synthesis library for Arduino
AutoRange.h
1 /*
2  * AutoRange.h
3  *
4  * This file is part of Mozzi.
5  *
6  * Copyright 2013-2024 Tim Barrass and the Mozzi Team
7  *
8  * Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
9  *
10  */
11 
12 #ifndef AUTORANGE_H
13 #define AUTORANGE_H
14 
18 template <class T>
19 class
20  AutoRange {
21 
22 public:
28  AutoRange(T min_expected, T max_expected):range_min(max_expected),range_max(min_expected),range(0)
29  {
30  }
31 
32 
36  void next(T n)
37  {
38  if (n > range_max)
39  {
40  range_max = n;
41  range = range_max - range_min;
42  }
43  else
44  {
45  if (n< range_min)
46  {
47  range_min = n;
48  range = range_max - range_min;
49  }
50  }
51  }
52 
56  T getMin()
57  {
58  return range_min;
59  }
60 
61 
65  T getMax()
66  {
67  return range_max;
68  }
69 
70 
75  {
76  return range;
77  }
78 
79 private:
80  T range_max, range_min, range;
81 
82 };
83 
84 #endif // #ifndef AUTORANGE_H
AutoRange(T min_expected, T max_expected)
Constructor.
Definition: AutoRange.h:28
T getMax()
Returns the current maximum.
Definition: AutoRange.h:65
T getRange()
Returns the current range.
Definition: AutoRange.h:74
void next(T n)
Updates the current range.
Definition: AutoRange.h:36
T getMin()
Returns the current minimum.
Definition: AutoRange.h:56
Keeps a running calculation of the range of the input values it receives.
Definition: AutoRange.h:20