Mozzi  version 2016-12-11-17:03
sound synthesis library for Arduino
AutoRange.h
1 /*
2  * AutoRange.h
3  *
4  * Copyright 2013 Tim Barrass.
5  *
6  * This file is part of Mozzi.
7  *
8  * Mozzi is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
9  *
10  */
11 #ifndef AUTORANGE_H
12 #define AUTORANGE_H
13 
17 template <class T>
18 class
19  AutoRange {
20 
21 public:
27  AutoRange(T min_expected, T max_expected):range_min(max_expected),range_max(min_expected),range(0)
28  {}
29 
30 
34  void next(T n){
35  if (n > range_max) {
36  range_max = n;
37  range = range_max - range_min;
38  }else{
39  if (n< range_min) {
40  range_min = n;
41  range = range_max - range_min;
42  }
43  }
44  }
45 
49  T getMin(){
50  return range_min;
51  }
52 
53 
57  T getMax(){
58  return range_max;
59  }
60 
61 
65  T getRange(){
66  return range;
67  }
68 
69 private:
70  T range_max, range_min , range;
71 
72 };
73 
74 #endif // #ifndef AUTORANGE_H
T getRange()
Returns the current range.
Definition: AutoRange.h:65
T getMax()
Returns the current maximum.
Definition: AutoRange.h:57
T getMin()
Returns the current minimum.
Definition: AutoRange.h:49
Keeps a running calculation of the range of the input values it receives.
Definition: AutoRange.h:18
void next(T n)
Updates the current range.
Definition: AutoRange.h:34
AutoRange(T min_expected, T max_expected)
Constructor.
Definition: AutoRange.h:27