forked from Stinkstudios/sono
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompressor.js
More file actions
67 lines (53 loc) · 1.99 KB
/
compressor.js
File metadata and controls
67 lines (53 loc) · 1.99 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
import AbstractEffect from './abstract-effect';
import sono from '../core/sono';
class Compressor extends AbstractEffect {
constructor({attack = 0.003, knee = 30, ratio = 12, release = 0.25, threshold = -24, wet = 1, dry = 1} = {}) {
super(sono.context.createDynamicsCompressor());
this.wet = wet;
this.dry = dry;
this.update({threshold, knee, ratio, attack, release});
}
update(options) {
// min decibels to start compressing at from -100 to 0
this.setSafeParamValue(this._node.threshold, options.threshold);
// decibel value to start curve to compressed value from 0 to 40
this.setSafeParamValue(this._node.knee, options.knee);
// amount of change per decibel from 1 to 20
this.setSafeParamValue(this._node.ratio, options.ratio);
// seconds to reduce gain by 10db from 0 to 1 - how quickly signal adapted when volume increased
this.setSafeParamValue(this._node.attack, options.attack);
// seconds to increase gain by 10db from 0 to 1 - how quickly signal adapted when volume redcuced
this.setSafeParamValue(this._node.release, options.release);
}
get threshold() {
return this._node.threshold.value;
}
set threshold(value) {
this.setSafeParamValue(this._node.threshold, value);
}
get knee() {
return this._node.knee.value;
}
set knee(value) {
this.setSafeParamValue(this._node.knee, value);
}
get ratio() {
return this._node.ratio.value;
}
set ratio(value) {
this.setSafeParamValue(this._node.ratio, value);
}
get attack() {
return this._node.attack.value;
}
set attack(value) {
this.setSafeParamValue(this._node.attack, value);
}
get release() {
return this._node.release.value;
}
set release(value) {
this.setSafeParamValue(this._node.release, value);
}
}
export default sono.register('compressor', opts => new Compressor(opts));