forked from Stinkstudios/sono
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphaser.js
More file actions
95 lines (73 loc) · 2.35 KB
/
phaser.js
File metadata and controls
95 lines (73 loc) · 2.35 KB
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
import AbstractEffect from './abstract-effect';
import sono from '../core/sono';
class Phaser extends AbstractEffect {
constructor({stages = 8, feedback = 0.5, frequency = 0.5, gain = 300, wet = 0.8, dry = 0.8} = {}) {
stages = stages || 8;
const filters = [];
for (let i = 0; i < stages; i++) {
filters.push(sono.context.createBiquadFilter());
}
const first = filters[0];
const last = filters[filters.length - 1];
super(first, last);
this._stages = stages;
this._feedback = sono.context.createGain();
this._lfo = sono.context.createOscillator();
this._lfoGain = sono.context.createGain();
this._lfo.type = 'sine';
for (let i = 0; i < filters.length; i++) {
const filter = filters[i];
filter.type = 'allpass';
filter.frequency.value = 1000 * i;
this._lfoGain.connect(filter.frequency);
// filter.Q.value = 10;
if (i > 0) {
filters[i - 1].connect(filter);
}
}
this._lfo.connect(this._lfoGain);
this._lfo.start(0);
this._nodeOut.connect(this._feedback);
this._feedback.connect(this._node);
this.wet = wet;
this.dry = dry;
this.update({frequency, gain, feedback});
}
enable(value) {
super.enable(value);
if (this._feedback) {
this._feedback.disconnect();
}
if (value && this._feedback) {
this._nodeOut.connect(this._feedback);
this._feedback.connect(this._node);
}
}
update(options) {
this.frequency = options.frequency;
this.gain = options.gain;
this.feedback = options.feedback;
}
get stages() {
return this._stages;
}
get frequency() {
return this._lfo.frequency.value;
}
set frequency(value) {
this.setSafeParamValue(this._lfo.frequency, value);
}
get gain() {
return this._lfoGain.gain.value;
}
set gain(value) {
this.setSafeParamValue(this._lfoGain.gain, value);
}
get feedback() {
return this._feedback.gain.value;
}
set feedback(value) {
this.setSafeParamValue(this._feedback.gain, value);
}
}
export default sono.register('phaser', opts => new Phaser(opts));