-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
114 lines (101 loc) · 5.23 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* @name Amely
*/
var half = Math.pow(2, 1/12);
var a = 440;
var b = a*half;
var h = a*Math.pow(half, 2);
var c = a*Math.pow(half, 3)/2;
var cis = a*Math.pow(half, 4)/2;
var d = a*Math.pow(half, 5)/2;
var dis = a*Math.pow(half, 6)/2;
var e = a*Math.pow(half, 7)/2;
var f = a*Math.pow(half, 8)/2;
var fis = a*Math.pow(half, 9)/2;
var g = a*Math.pow(half, 10)/2;
var gis = a*Math.pow(half, 11)/2;
var notes = [c, d, e, f, g, a, h, c*2];
var bass = [e/2, e/2, e/2, e/2, g/2, g/2, g/2, g/2, e/2, e/2, e/2, e/2, g/2, g/2, g/2, g/2,
d/2, d/2, d/2, d/2, g/2, g/2, g/2, g/2, d/2, d/2, d/2, d/2, g/2, g/2, g/2, g/2,
d/2, d/2, d/2, d/2, fis/2, fis/2, fis/2, fis/2, d/2, d/2, d/2, d/2, fis/2, fis/2, fis/2, fis/2,
d/2, d/2, d/2, d/2, fis/2, fis/2, fis/2, fis/2, d/2, d/2, d/2, d/2, fis/2, fis/2, fis/2, fis/2
];
var tenor= [e/1, e/1, h/2, h/2, e/1, e/1, h/2, h/2, e/1, e/1, h/2, h/2, e/1, e/1, h/2, h/2,
d/1, d/1, h/2, h/2, d/1, d/1, h/2, h/2, d/1, d/1, h/2, h/2, d/1, d/1, h/2, h/2,
d/1, d/1, h/2, h/2, d/1, d/1, h/2, h/2, d/1, d/1, h/2, h/2, d/1, d/1, h/2, h/2,
d/1, d/1, a/2, a/2, d/1, d/1, a/2, a/2, d/1, d/1, a/2, a/2, d/1, d/1, a/2, a/2
];
var soprano = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,g,fis, g,g,h,c*2, h,h,h,h, h,h,h,h, 0,0,fis,g, fis,fis,g,a, g,g,g,g, g,g,g,g,
0,0,fis,e, fis,fis,h,c*2, h,h,h,h, h,h,h,h, 0,0,fis,e, fis,fis,fis,fis, fis,fis,fis,fis, fis,fis,fis,fis,
0,0,g,fis, g,g,h,c*2, h,h,h,h, h,h,h,h, 0,0,fis,g, fis,fis,g,a, g,g,g,g, g,g,g,g,
0,0,fis,e, fis,fis,h,c*2, h,h,h,h, h,h,h,h, 0,0,fis,e, fis,fis,fis,fis, fis,fis,fis,fis, fis,fis,fis,fis,
e*2,e*2,e*2,e*2, e*2,e*2,h,h, h,h,h,h, h,h,h,h, d*2,d*2,d*2,d*2, d*2,d*2,h,h, h,h,h,h, h,h,h,h,
fis*2,fis*2,fis*2,fis*2, fis*2,fis*2,h,h, h,h,h,h, h,h,h,h, fis*2,fis*2,fis*2,fis*2, fis*2,fis*2,a,a, a,a,a,a, a,a,a,a,
g*2,g*2,g*2,g*2, g*2,g*2,e*2,e*2, e*2,e*2,e*2,e*2, e*2,e*2,e*2,e*2, g*2,g*2,g*2,g*2, g*2,g*2,d*2,d*2, d*2,d*2,d*2,d*2, d*2,d*2,d*2,d*2,
fis*2,fis*2,fis*2,fis*2, fis*2,fis*2,d*2,d*2, d*2,d*2,d*2,d*2, d*2,d*2,d*2,d*2, fis*2,fis*2,fis*2,fis*2, fis*2,fis*2,d*2,d*2, d*2,d*2,d*2,d*2, d*2,d*2,d*2,d*2,
h,e*2,h*2,h,e*2,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,fis,fis, fis,fis,fis,fis, a,a,a,a, a,a,fis,fis, fis,fis,fis,fis, fis,fis,fis,fis,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
]
export function dsp(t) {
return play(soprano, sqar10)/2 +
play(alt, sqar10)/3 +
play(tenor, saw10)/5 +
play(bass, saw10)/6;
function play(notes, instrument){
var tempo = 6*t;
var note = Math.floor(tempo % notes.length);
var chouse = notes[note];
var atac_time = 0.1;
var relise_time = 0.2;
var attaca = (tempo%1 < atac_time) && (notes[note] != notes[note-1]) ? 1/atac_time * (tempo%1) : 1;
var relise = (tempo%1 > 1-relise_time) && (notes[note] != notes[note+1]) ? 1/relise_time * (1-(tempo%1)) : 1;
return instrument(chouse) * attaca * relise;
}
function sin(f, A){
if (A == null) A=1;
return A * Math.sin(2*Math.PI*f*t);
}
function harmonic(f1, count, n_fun, A_fun){
if (count == null) count = 1;
if (n_fun == null) {
var n_fun = function(i){
return i;
}
}
if (A_fun == null){
var A_fun = function(i) {
return 1/i;
}
}
var result = 0;
for (var i = 1; i <= count; i++){
result += sin(f1 * n_fun(i), A_fun(i));
}
return result;
}
function sqar10(f){
var n_fun = function(i){
return (i*2)-1;
};
var A_fun = function(i){
return 1/((i*2)-1);
};
return harmonic(f, 10, n_fun, A_fun);
}
function saw10(f){
return harmonic(f, 10);
}
}