| Mozzi version v1.1.0 sound synthesis library for Arduino |

IntMap.h
1 /*
2 * IntMap.h
3 *
4 * Copyright 2012 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
12 #ifndef INTMAP_H_
13 #define INTMAP_H_
14
15 /** A faster version of Arduino's map() function.
16 This uses ints instead of longs internally and does some of the maths at compile time.
17 */
18 class IntMap {
19
20 public:
21 /** Constructor.
22 @param in_min the minimum of the input range.
23 @param in_max the maximum of the input range.
24 @param out_min the minimum of the output range.
25 @param out_max the maximum of the output range.
26 */
27 IntMap(int in_min, int in_max, int out_min, int out_max)
28 : _IN_MIN(in_min),_IN_MAX(in_max),_OUT_MIN(out_min),_OUT_MAX(out_max),
29 _MULTIPLIER((256L * (out_max-out_min)) / (in_max-in_min))
30 {
31 ;
32 }
33
34 /** Process the next input value.
35 @param n the next integer to process.
36 @return the input integer mapped to the output range.
37 */
38 int operator()(int n) const {
39 return (int) (((_MULTIPLIER*(n-_IN_MIN))>>8) + _OUT_MIN);
40 }
41
42
43 private:
44 const int _IN_MIN, _IN_MAX, _OUT_MIN, _OUT_MAX;
45 const long _MULTIPLIER;
46 };
47
48 #endif /* INTMAP_H_ */
IntMap
A faster version of Arduino&#39;s map() function.
Definition: IntMap.h:18
IntMap::operator()
int operator()(int n) const
Process the next input value.
Definition: IntMap.h:38
IntMap::IntMap
IntMap(int in_min, int in_max, int out_min, int out_max)
Constructor.
Definition: IntMap.h:27