-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
86 lines (77 loc) · 2.24 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
/**
* change source from stagas/Combofilter
* @module basicSample
* author ChangeFromStagas
* org MYORGFromOpendsp
* desc ChangeFromCombfilter
* license MmFromMit
* @version 0.0.8
*/
export default CombFilter6;
function CombFilter6(size){
if (!(this instanceof CombFilter6)) return new CombFilter6(size);
this.size = size;
this.index = 0;
this.buffer = new Float32Array(size*2);
this.feedback = 0;
this.filter = 0;
this.damp = 0;
this.k=-1;
this.sum=0;
this.average=0;
this.max=0;
this.divNum=1;
this.inputMul=0.315;
this.initInputMul=this.inputMul;
this.setInputMul(0.315);
this.len=size;
}
CombFilter6.prototype.setInputMul= function(val){
this.inputMul=val;
this.initInputMul=val;
};
CombFilter6.prototype.run = function(input){
//this.buffer[this.index] = input * 0.015 + this.filter * this.feedback;
//return input;
var output = this.buffer[this.index];
//if(this.index>0)output = this.buffer[this.index-1];
this.filter = output * (1 - this.damp) + this.filter * this.damp;
this.buffer[this.index] =
input * this.inputMul + this.filter * this.feedback;
this.buffer[this.index] -=this.average;
this.buffer[this.index] /=this.divNum;
output=this.buffer[this.index];
this.sum+=output;
var qqw=Math.abs(output);
if(this.max<qqw)this.max=qqw;
if (++this.index === this.size)
{
this.index = 0;
this.k*=-1;
this.average=this.sum/this.size;this.sum=0;
if(this.max>0.5){
this.divNum=this.max*2;
}
//else
{
this.divNum=1.0;///((this.feedback+1.0)/2.0);
if(Math.random()<0.9){
//this.size*=0.9;
this.size=Math.floor(this.size*0.99)-1;
//this.size=Math.floor(Math.random()*(this.len-100))+100;
if(this.size<100){
this.size=Math.floor(Math.random()*(this.len-100))+99;
//this.inputMul=this.initInputMul;
}
this.inputMul*=1.02;
if(this.inputMul>0.5 || this.max>13.0) {
this.inputMul=this.initInputMul;
this.divNum+=99980000;
//if(Math.random()<0.5)
}
}
}
this.max=0;
}
return output;
};