-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoice.h
68 lines (49 loc) · 1.53 KB
/
voice.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
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define VOICES 2
#define KDIV 64
typedef Oscillator<SRATE, int8_t> osc_type;
typedef Oscillator<SRATE / KDIV, int8_t> lfo_type;
ADEnvelope<SRATE / KDIV > env;
osc_type oscs[VOICES];
lfo_type lfo;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Amplifier : public SampleProcessor<int8_t, int8_t> {
private:
uint16_t ix;
uint8_t last_env;
uint8_t last_lfo;
public:
virtual ~Amplifier() {};
Amplifier(SampleSource<int8_t> * in) :
ix(1), last_env(255), last_lfo(0) {
connect(in);
}
inline virtual int8_t process(int8_t v) {
if (! ix) {
last_env = env.read() >> 24;
last_lfo = lfo_type::traits::to_uint8_t(lfo.read());
last_env = Math::mul_T1U8S<8>(last_env, (128 | (last_lfo >> 1)));
}
ix++;
ix %= KDIV;
return Math::mul_T1U8S<8>(v, last_env);
}
};
void setup_voice() {
lfo.set_hz(8, 0b00000000);
lfo.set_wave(3);
oscs[0].set_detune_hz(0b00000000);
oscs[1].set_detune_hz(0b00001100);
oscs[0].octave = 0;
oscs[1].octave = 1;
oscs[0].set_wave(osc_type::wf_square);
oscs[1].set_wave(osc_type::wf_square);
oscs[0].set_note(48);
oscs[1].set_note(48);
env.set_a_time(512);
env.set_d_time(0b00000111);
}
UnityMix mixer(&oscs[0], &oscs[1]);
Amplifier amp(&mixer);
ConvertToUnsigned<int8_t> converter(&);
#define VOICE converter