forked from padenot/webaudio-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmarks.js
203 lines (185 loc) · 5.98 KB
/
benchmarks.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
if (typeof(window) == "undefined") {
benchmarks = []
registerTestFile = function() {}
registerTestCase = function(o) { return benchmarks.push(o.name); }
}
registerTestFile("think-mono-48000.wav");
registerTestFile("think-mono-44100.wav");
registerTestFile("think-mono-38000.wav");
registerTestFile("think-stereo-48000.wav");
registerTestFile("think-stereo-44100.wav");
registerTestFile("think-stereo-38000.wav");
registerTestCase({
func: function () {
var oac = new OfflineAudioContext(1, 120 * samplerate, samplerate);
return oac;
},
name: "Empty testcase"
});
registerTestCase({
func: function () {
var oac = new OfflineAudioContext(1, 120 * samplerate, samplerate);
var source0 = oac.createBufferSource();
source0.buffer = getSpecificFile({rate: oac.samplerate, channels:1});
source0.loop = true;
source0.connect(oac.destination);
source0.start(0);
return oac;
},
name: "Simple gain test without resampling"
});
registerTestCase({
func: function() {
var oac = new OfflineAudioContext(2, 120 * samplerate, samplerate);
var source0 = oac.createBufferSource();
source0.buffer = getSpecificFile({rate: oac.samplerate, channels:2});
source0.loop = true;
source0.connect(oac.destination);
source0.start(0);
return oac;
},
name: "Simple gain test without resampling (Stereo)"
});
registerTestCase({
func: function() {
var oac = new OfflineAudioContext(1, 120 * samplerate, samplerate);
var source0 = oac.createBufferSource();
source0.buffer = getSpecificFile({rate: 38000, channels:1});
source0.loop = true;
source0.connect(oac.destination);
source0.start(0);
return oac;
},
name: "Simple gain test"
});
registerTestCase({
func: function() {
var oac = new OfflineAudioContext(2, 120 * samplerate, samplerate);
var source0 = oac.createBufferSource();
source0.buffer = getSpecificFile({rate: 38000, channels:2});
source0.loop = true;
source0.connect(oac.destination);
source0.start(0);
return oac;
},
name: "Simple gain test (Stereo)"
});
registerTestCase({
func: function() {
var oac = new OfflineAudioContext(2, 120 * samplerate, samplerate);
var source0 = oac.createBufferSource();
source0.buffer = getSpecificFile({rate: oac.samplerate, channels:1});
source0.loop = true;
source0.connect(oac.destination);
source0.start(0);
return oac;
},
name: "Upmix without resampling (Mono -> Stereo)"
});
registerTestCase({
func: function() {
var oac = new OfflineAudioContext(1, 120 * samplerate, samplerate);
var source0 = oac.createBufferSource();
source0.buffer = getSpecificFile({rate: oac.samplerate, channels:2});
source0.loop = true;
source0.connect(oac.destination);
source0.start(0);
return oac;
},
name: "Downmix without resampling (Mono -> Stereo)"
});
registerTestCase({
func: function() {
var oac = new OfflineAudioContext(2, 30 * samplerate, samplerate);
for (var i = 0; i < 100; i++) {
var source0 = oac.createBufferSource();
source0.buffer = getSpecificFile({rate: 38000, channels:1});
source0.loop = true;
source0.connect(oac.destination);
source0.start(0);
}
return oac;
},
name: "Simple mixing (same buffer)"
});
registerTestCase({
func: function() {
var oac = new OfflineAudioContext(2, 30 * samplerate, samplerate);
var reference = getSpecificFile({rate: 38000, channels:1}).getChannelData(0);
for (var i = 0; i < 100; i++) {
var source0 = oac.createBufferSource();
// copy the buffer into the a new one, so we know the implementation is not
// sharing them.
var b = oac.createBuffer(1, reference.length, 38000);
var data = b.getChannelData(0);
for (var j = 0; j < b.length; j++) {
data[i] = reference[i];
}
source0.buffer = b;
source0.loop = true;
source0.connect(oac.destination);
source0.start(0);
}
return oac;
},
name: "Simple mixing (different buffers)"
});
registerTestCase({
func: function() {
var oac = new OfflineAudioContext(1, 30 * samplerate, samplerate);
var i,l;
var decay = 10;
var duration = 4;
var len = samplerate * duration;
var buffer = ac.createBuffer(2, len, oac.sampleRate)
var iL = buffer.getChannelData(0)
var iR = buffer.getChannelData(1)
// Simple exp decay loop
for(i=0,l=buffer.length;i<l;i++) {
iL[i] = (Math.random() * 2 - 1) * Math.pow(1 - i / len, decay);
iR[i] = (Math.random() * 2 - 1) * Math.pow(1 - i / len, decay);
}
var convolver = oac.createConvolver();
convolver.buffer = buffer;
convolver.connect(oac.destination);
var audiobuffer = getSpecificFile({rate: samplerate, channels:1});
var source0 = oac.createBufferSource();
source0.buffer = audiobuffer;
source0.loop = true;
source0.connect(convolver);
source0.start(0);
return oac;
},
name: "Convolution reverb"
});
registerTestCase({
func: function() {
var oac = new OfflineAudioContext(1, 30 * samplerate, samplerate);
var duration = 30 * samplerate;
var audiobuffer = getSpecificFile({rate: samplerate, channels:1});
var offset = 0;
while (offset < duration / samplerate) {
var grain = oac.createBufferSource();
var gain = oac.createGain();
grain.connect(gain);
gain.connect(oac.destination);
grain.buffer = audiobuffer;
// get a random 100-ish ms with enveloppes
var start = offset * Math.random() * 0.5;
var end = start + 0.005 * (0.999 * Math.random());
grain.start(offset, start, end);
gain.gain.setValueAtTime(offset, 0);
gain.gain.linearRampToValueAtTime(.5, offset + 0.005);
var startRelease = Math.max(offset + (end - start), 0);
gain.gain.setValueAtTime(0.5, startRelease);
gain.gain.linearRampToValueAtTime(0.0, startRelease + 0.05);
// some overlap
offset += 0.005;
}
return oac;
},
name: "Granular synthesis"
});
if (typeof(window) == "undefined") {
exports.benchmarks = benchmarks;
}