-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
68 lines (56 loc) · 1.44 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
/**
* @module freeverb
* @author stagas
* @org opendsp
* @desc freeverb reverb effect
* @license mit
*/
import CombFilter from 'combfilter';
import Allpass from 'allpass';
export default Reverb;
var combs_a = [1116,1188,1277,1356].map(stretch);
var combs_b = [1422,1491,1557,1617].map(stretch);
var aps = [225,556,441,341].map(stretch);
function Reverb(){
if (!(this instanceof Reverb)) return new Reverb();
this.combs_a = combs_a.map(CombFilter);
this.combs_b = combs_b.map(CombFilter);
this.aps = aps.map(Allpass);
this.room(0.5);
this.damp(0.5);
}
Reverb.prototype.room = function(n){
n = n * 0.28 + 0.7;
this.combs_a.forEach(setProperty('feedback', n));
this.combs_b.forEach(setProperty('feedback', n));
return this;
};
Reverb.prototype.damp = function(n){
n *= 0.4;
this.combs_a.forEach(setProperty('damp', n));
this.combs_b.forEach(setProperty('damp', n));
return this;
};
Reverb.prototype.run = function(input){
var output =
this.combs_a.map(run).reduce(sum)
+ this.combs_b.map(run).reduce(sum)
;
output = this.aps.reduce(waterfall, output);
return output;
function run(el){ return el.run(input) }
};
function sum(p, n){
return p + n;
}
function waterfall(p, n){
return p + n.run(p);
}
function stretch(n){
return n * (sampleRate / 44100) | 0;
}
function setProperty(key, value){
return function(obj){
obj[key] = value;
};
}