-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
94 lines (72 loc) · 1.58 KB
/
index.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
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
/**
* Instantiate boilerplate audio component
*
* @param {AudioContext} context
* @param {Object} config
*/
function Module (context, config) {
// Must have input and output properties
// that are `AudioNode` instances
this.input = context.createGainNode();
this.output = context.createGainNode();
// Internal AudioNodes used in the
// effect. In this case, just a simple
// gain node
this._gain = context.createGainNode();
// AudioNode graph routing
this.input.connect(this._gain);
this._gain.connect(this.output);
// Apply config, falling back on defaults
config = config || {};
this._gain.gain.value = config.gain || this.meta.params.gain.defaultValue;
}
Module.prototype = Object.create(null, {
/**
* AudioNode prototype `connect` method.
*
* @param {AudioNode} dest
*/
connect: {
value: function (dest) {
this.output.connect(dest && dest.input ? dest.input : dest);
}
},
/**
* AudioNode prototype `disconnect` method.
*/
disconnect: {
value: function () {
this.output.disconnect();
}
},
/**
* Module parameter metadata.
*/
meta: {
value: {
name: 'moduleName',
params: {
gain: {
min: 0,
max: 1,
defaultValue: 0.5,
type: 'float'
}
}
}
},
/**
* Public gain parameter.
*/
gain: {
enumerable: true,
get: function () { return this._gain.gain.value; },
set: function (value) {
this._gain.gain.setValueAtTime(value, 0);
}
}
});
/**
* Expose `Module`
*/
module.exports = Module;