-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathhihat.class.ts
50 lines (39 loc) · 1.39 KB
/
hihat.class.ts
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
import { SAMPLERATE } from '../environment';
import { StereoSignal } from '../synth/stereosignal.class';
import { Envelope } from '../synth/envelope.class';
import { BiQuadFilter, FilterType, Q_BUTTERWORTH } from '../synth/biquad';
import { Noise } from '../synth/noise.class';
export class Hihat {
private _note: f32;
private velocity: f32;
readonly envelope: Envelope = new Envelope(0.0, 0.08, 0, 0.1);
readonly noise: Noise = new Noise();
readonly filter: BiQuadFilter = new BiQuadFilter();
readonly signal: StereoSignal = new StereoSignal();
set note(note: f32) {
if(note > 1) {
this.velocity = note / 32;
this.envelope.attack();
} else {
this.envelope.release();
}
this._note = note;
}
get note(): f32 {
return this._note;
}
next(): void {
let env: f32 = this.envelope.next();
if(env === 0) {
this.signal.clear();
return;
}
let osc: f32 = this.noise.next();
let signal = this.velocity * 2 * env * osc;
this.filter.update_coeffecients(FilterType.HighPass, SAMPLERATE,
10000 + 2000 * env, Q_BUTTERWORTH);
signal = this.filter.process(signal);
this.signal.left = signal;
this.signal.right = signal;
}
}