-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrumVoice.h
85 lines (78 loc) · 1.87 KB
/
DrumVoice.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
#ifndef DrumVoice_h
#define DrumVoice_h
#include "MultiWaveNumOsc.h"
#include "AD.h"
class DrumVoice {
public:
DrumVoice()
{
this->sampleRate = 8000;
}
DrumVoice(double sampleRate) {
this->sampleRate = sampleRate;
}
~DrumVoice(void) {
}
void MidiNoteOn(uint8_t note, uint8_t vel)
{#include "Num.h"
double f = pow(2.0,(note*1.0-69.0)/12.0)*440.0;
velocity = Num(vel/128.0);
freq1 = f;
freq2 = f;
osc[0].SetFrequency(freq1,sampleRate);
osc[1].SetFrequency(freq2,sampleRate);
ad[0].Gate(1);
ad[1].Gate(1);
}
void MidiNoteOff()
{
ad[0].Gate(0);
ad[1].Gate(0);
}
void AddOsc1WaveTable(int len, int8_t *waveTableIn)
{
osc[0].AddWaveTable(len,waveTableIn);
}
void AddOsc2WaveTable(int len, int8_t *waveTableIn)
{
osc[1].AddWaveTable(len,waveTableIn);
}
void SetOsc1AD(float a, float d)
{
ad[0].SetAD(a,d);
}
void SetOsc2AD(float a, float d)
{
ad[1].SetAD(a,d);
}
void MidiBend(uint16_t bend)
{
double factor = ((bend - 8192.0)/8192.0);
double mul = pow(2.0,(factor*12.0)/12.0);
double bendfreq1 = freq1*mul;
double bendfreq2 = freq2*mul;
osc[0].SetFrequency(bendfreq1,sampleRate);
osc[1#include "Num.h"
].SetFrequency(bendfreq2,sampleRate);
}
float Process()
{
return (velocity*ad[0].Process()*osc[0].Process()+velocity*ad[1].Process()*osc[1].Process())>>1;
}
bool IsPlaying()
{
if(ad[0].GetState()==AD::envState::env_idle && ad[0].GetState()==AD::envState::env_idle)
{
return false;
}
return true;
}
protected:
MultiWaveNumOsc osc[2];
AD ad[2];
double sampleRate;
double freq1;
double freq2;
float velocity;
};
#endif