Mozzi  version v2.0
sound synthesis library for Arduino
IntegerType.h
1 /*
2  * IntegerType.h
3  *
4  * This file is part of Mozzi.
5  *
6  * Copyright 2021-2024 Thomas Friedrichsmeier 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 INTTYPE_H_
13 #define INTTYPE_H_
14 
15 #include <Arduino.h>
16 
17 /** @ingroup util
18 Provides appropriate integer types that can bit the given number of bytes on this platform (at most 64).
19 */
20 template<uint8_t BYTES> struct IntegerType {
21  // at an odd value, such as 3 bytes? Add one more byte (up to at most 8 bytes)..
22  typedef typename IntegerType<(BYTES < 8) ? (BYTES+1) : 8>::unsigned_type unsigned_type;
23  typedef typename IntegerType<(BYTES < 8) ? (BYTES+1) : 8>::signed_type signed_type;
24 };
25 
26 // These are the specializations for the types that we actually assume to exist:
27 template<> struct IntegerType<1> {
28  typedef uint8_t unsigned_type;
29  typedef int8_t signed_type;
30 };
31 
32 template<> struct IntegerType<2> {
33  typedef uint16_t unsigned_type;
34  typedef int16_t signed_type;
35 };
36 
37 template<> struct IntegerType<4> {
38  typedef uint32_t unsigned_type;
39  typedef int32_t signed_type;
40 };
41 
42 template<> struct IntegerType<8> {
43  typedef uint64_t unsigned_type;
44  typedef int64_t signed_type;
45 };
46 
47 #endif /* INTTYPE_H_ */