Mozzi  version v2.0
sound synthesis library for Arduino
IntMap.h
1 /*
2  * IntMap.h
3  *
4  * This file is part of Mozzi.
5  *
6  * Copyright 2012-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 
13 #ifndef INTMAP_H_
14 #define INTMAP_H_
15 
19 class IntMap {
20 
21 public:
28  IntMap(int in_min, int in_max, int out_min, int out_max)
29  : _IN_MIN(in_min),_IN_MAX(in_max),_OUT_MIN(out_min),_OUT_MAX(out_max),
30  _MULTIPLIER((256L * (out_max-out_min)) / (in_max-in_min))
31  {
32  ;
33  }
34 
39  int operator()(int n) const {
40  return (int) (((_MULTIPLIER*(n-_IN_MIN))>>8) + _OUT_MIN);
41  }
42 
43 
44 private:
45  const int _IN_MIN, _IN_MAX, _OUT_MIN, _OUT_MAX;
46  const long _MULTIPLIER;
47 };
48 
49 #endif /* INTMAP_H_ */
A faster version of Arduino's map() function.
Definition: IntMap.h:19
IntMap(int in_min, int in_max, int out_min, int out_max)
Constructor.
Definition: IntMap.h:28
int operator()(int n) const
Process the next input value.
Definition: IntMap.h:39