-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwave.h
57 lines (45 loc) · 1.76 KB
/
wave.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
/**
wave.h - Wave generator
Copyright (C) 2018 Costin STROIE <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WAVE_H
#define WAVE_H
#include <Arduino.h>
#include "config.h"
// The first quarter wave samples LUT
static const uint8_t wavelut[] = {
0x80, 0x83, 0x86, 0x89, 0x8c, 0x8f, 0x92, 0x95,
0x98, 0x9b, 0x9e, 0xa2, 0xa5, 0xa7, 0xaa, 0xad,
0xb0, 0xb3, 0xb6, 0xb9, 0xbc, 0xbe, 0xc1, 0xc4,
0xc6, 0xc9, 0xcb, 0xce, 0xd0, 0xd3, 0xd5, 0xd7,
0xda, 0xdc, 0xde, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8,
0xea, 0xeb, 0xed, 0xee, 0xf0, 0xf1, 0xf3, 0xf4,
0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfa, 0xfb, 0xfc,
0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff
};
class WAVE {
public:
// Samples count for quarter, half and full wave
const uint8_t qart = sizeof(wavelut) / sizeof(*wavelut);;
const uint8_t half = qart + qart;
const uint16_t full = half + half;
WAVE();
~WAVE();
// Get the wave sample specified by index
uint8_t sample(uint8_t idx);
// Get the wave sample specified by index in Q8.8 format
uint8_t sample(uint16_t idx);
// Compute the wave steps as Q8.8
uint16_t getStep(uint16_t freq);
};
#endif /* WAVE_H */