-
Notifications
You must be signed in to change notification settings - Fork 0
/
wahwah.js
55 lines (47 loc) · 2.42 KB
/
wahwah.js
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
import Module from "../../classes/Module.js";
import Parameter from "../../classes/Parameter.js";
import { audioContext } from "../../main.js";
export default function wahwah(event, initalQ, initalSpeed, initalDepth) {
const q = parseFloat(initalQ || 2.5);
const speed = parseFloat(initalSpeed || 8.5);
const depth = parseFloat(initalDepth || 0.8);
const qInfo = "Controls the width of the band. The width becomes narrower as the Q value increases";
const speedInfo = "Frequency of oscillator that change bandpass inital frequency";
const depthInfo = "Depth of the bandpass change from oscillator";
const module = new Module("wahwah", true, false, false, undefined, true);
module.audioNode = {
inputNode: new GainNode(audioContext),
outputNode: new GainNode(audioContext),
oscillatorNode: new OscillatorNode(audioContext, { type: "sine" }),
biquadNode: new BiquadFilterNode(audioContext, { type: "bandpass", Q: q, frequency: 1200 }),
depthNode: new GainNode(audioContext, { gain: depth }),
speed: new Parameter(speed, (value) => {
module.audioNode.oscillatorNode.frequency.value = value;
}),
depth: new Parameter(depth, (value) => {
// oscillator output value is just [-1,1] so make it [-800*value,800*value]
module.audioNode.depthNode.gain.value = 800 * value;
}),
q: new Parameter(q, (value) => {
module.audioNode.biquadNode.Q.value = value;
}),
connect(destination) {
if (destination.inputNode) this.outputNode.connect(destination.inputNode);
else this.outputNode.connect(destination);
},
disconnect() {
this.outputNode.disconnect();
},
};
module.createSlider("speed", speed, 0, 20, 0.1, "Hz", false, speedInfo);
module.createSlider("q", q, 0, 5, 0.1, "", false, qInfo);
module.createSlider("depth", depth, 0, 1, 0.01, "", false, depthInfo);
module.audioNode.inputNode.connect(module.audioNode.biquadNode);
module.audioNode.oscillatorNode.connect(module.audioNode.depthNode);
module.audioNode.depthNode.connect(module.audioNode.biquadNode.frequency);
module.audioNode.biquadNode.connect(module.audioNode.outputNode);
module.audioNode.oscillatorNode.start(0);
// add inital cable when structure is fully build - getBoundingClientRect related
module.addInitalCable();
return module;
}