forked from pichenettes/eurorack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigital_oscillator.h
executable file
·95 lines (74 loc) · 2.11 KB
/
digital_oscillator.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2012 Olivier Gillet.
//
// Author: Olivier Gillet ([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/>.
//
// -----------------------------------------------------------------------------
//
// Sampled oscillator.
#ifndef EDGES_DIGITAL_OSCILLATOR_H_
#define EDGES_DIGITAL_OSCILLATOR_H_
#include "avrlibx/avrlibx.h"
namespace edges {
using namespace avrlibx;
enum OscillatorShape {
OSC_TRIANGLE,
OSC_NES_TRIANGLE,
OSC_PITCHED_NOISE,
OSC_NES_NOISE_LONG,
OSC_NES_NOISE_SHORT,
OSC_SINE,
};
class DigitalOscillator {
public:
typedef void (DigitalOscillator::*RenderFn)();
DigitalOscillator() { }
~DigitalOscillator() { }
void Init() {
UpdatePitch(60 << 7, OSC_TRIANGLE);
Gate(true);
rng_state_ = 1;
}
void UpdatePitch(int16_t pitch, OscillatorShape shape) {
pitch_ = pitch;
shape_ = shape;
}
void Gate(bool gate) {
gate_ = gate;
}
void Render();
inline void set_cv_pw(uint8_t pw) {
cv_pw_ = pw;
}
private:
void ComputePhaseIncrement();
void RenderSilence();
void RenderSine();
void RenderBandlimitedTriangle();
void RenderNoiseNES();
void RenderNoise();
OscillatorShape shape_;
int16_t pitch_;
bool gate_;
uint8_t note_;
uint24_t phase_;
uint24_t phase_increment_;
uint16_t sample_;
uint16_t rng_state_;
uint16_t aux_phase_;
uint8_t cv_pw_;
static const RenderFn fn_table_[];
DISALLOW_COPY_AND_ASSIGN(DigitalOscillator);
};
} // namespace edges
#endif // EDGES_DIGITAL_OSCILLATOR_H_