forked from sensorium/Mozzi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta.h
73 lines (57 loc) · 2.4 KB
/
meta.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* meta.h
*
* This file is part of Mozzi.
*
* Copyright 2012-2024 Tim Barrass and the Mozzi Team
*
* Mozzi is licensed under the GNU Lesser General Public Licence (LGPL) Version 2.1 or later.
*
*/
/*
http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Int-To-Type
Template meta-programming extras.
*/
#ifndef META_H_
#define META_H_
/** @defgroup soundtables Look-up-tables and python scripts to generate tables or convert sounds.
Look-up-tables and python scripts to generate tables or convert sounds. Includes ready-to-use wave tables and a few example samples which are in the Mozzi/tables and Mozzi/samples folders. You can convert your own sounds from a program like Audacity to tables for Mozzi with a script called char2mozzi.py, in Mozzi/python. Read the int8_t2mozzi.py file for instructions. Also check out the other scripts in the python folder for templates to use if you want to do your own thing.
*/
/** @defgroup util Utility functions, and debugging
Utility functions. Includes functions for debugging and profiling high frequency code with an oscilloscope when serial is too slow, some miscellaneous functions used internally by Mozzi, python scripts for converting or generating sound tables, and assorted meta-programming utils.
*/
/** @ingroup util
Enables you to instantiate a template based on an integer value.
For example, this is used in StateVariable.h to choose a different next()
function for each kind of filter, LOWPASS, BANDPASS, HIGHPASS or NOTCH, which are simple
integer values 0,1,2,3 provided to the StateVariable template on instantiation.
Fantastic!
It's in C++11, but not yet available in avr-gcc.
See "c++ enable_if"
*/
template <int I>
struct Int2Type
{
enum {
value = I };
};
/*
//from http://en.wikibooks.org/wiki/C%2B%2B_Programming/Templates/Template_Meta-Programming#Compile-time_programming
//First, the general (unspecialized) template says that factorial<n>::value is given by n*factorial<n-1>::value:
template <unsigned n>
struct factorial
{
enum { value = n * factorial<n-1>::value };
};
//Next, the specialization for zero says that factorial<0>::value evaluates to 1:
template <>
struct factorial<0>
{
enum { value = 1 };
};
//And now some code that "calls" the factorial template at compile-time:
// Because calculations are done at compile-time, they can be
// used for things such as array sizes, eg.
// int array[ factorial<7>::value ];
*/
#endif /* META_H_ */