-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTGate.h
53 lines (44 loc) · 834 Bytes
/
TGate.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
#pragma once
#include <stdint.h>
/**
* @brief A triggerable gate generator. Takes in a trigger signal, and
* produces a gate whose duration is measured in seconds.
* Ported from https://pbat.ch/sndkit/tgate/
*/
class TGate
{
public:
TGate() {}
~TGate() {}
void Init(float sampleRate)
{
sr_ = sampleRate;
timer_ = 0;
SetDuration(0.002f);
}
/**
* @param dur In seconds
*/
void SetDuration(float dur)
{
dur_ = dur;
}
float Process(float trig)
{
float out = 0;
if (trig != 0)
{
timer_ = dur_ * sr_;
}
if (timer_ != 0)
{
out = 1.0f;
timer_--;
}
return out;
}
private:
uint32_t timer_;
float dur_;
float sr_;
};