-
Notifications
You must be signed in to change notification settings - Fork 3
/
ola.html
101 lines (79 loc) · 3.23 KB
/
ola.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script type="text/javascript" src="OLA.js"></script>
<script type="text/javascript">
var context = new AudioContext();
var BUFFER_SIZE = 4096;
var FRAME_SIZE = 4096;
var node = context.createScriptProcessor(BUFFER_SIZE, 2);
var olaL = new OLATS(FRAME_SIZE);
var olaR = new OLATS(FRAME_SIZE);
var buffer;
var position = 0;
var alpha = 1;
var overlap = 1.05;
var beta = 1;
var outBufferL = [];
var outBufferR = [];
loadSample = function(url, id) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
request.onload = function() {
context.decodeAudioData(request.response, function(decodedData) {
buffer = decodedData;
node.onaudioprocess = function(e) {
do {
var bufL = buffer.getChannelData(0).subarray(position, position + FRAME_SIZE);
var bufR = buffer.getChannelData(1).subarray(position, position + FRAME_SIZE);
if (alpha) {
olaL.set_alpha(alpha, overlap, beta);
olaR.set_alpha(alpha, overlap, beta);
alpha = undefined;
overlap = undefined;
beta = undefined;
}
outBufferL = outBufferL.concat(olaL.process(bufL));
outBufferR = outBufferR.concat(olaR.process(bufR));
position += olaL.get_ra();
} while (outBufferL.length <= BUFFER_SIZE && outBufferR.length <= BUFFER_SIZE);
e.outputBuffer.getChannelData(0).set(outBufferL.splice(0, BUFFER_SIZE));
e.outputBuffer.getChannelData(1).set(outBufferR.splice(0, BUFFER_SIZE));
}
node.connect(context.destination);
console.log("decoded");
});
};
request.send();
};
// loadSample('http://localhost/soundtouchjs/1.mp3');
// loadSample('http://localhost/soundtouchjs/4.mp3');
// loadSample('http://localhost/soundtouchjs/7.mp3');
loadSample('http://localhost/soundtouchjs/8.mp3');
// loadSample('http://localhost/soundtouchjs/8.mp3');
// loadSample('http://localhost/annotator/Daft%20Punk%20-%20Discography%20-%201994-2013/01%20-%20Albums%20(CD%20Original)/2001%20-%20Discovery%20-%20(320%20kbps)/14.%20Too%20Long.mp3');
function set_beta(newBeta) {
olaL.set_beta(newBeta);
olaR.set_beta(newBeta);
}
function set_overlap(newOverlap) {
olaL.set_overlap(newOverlap);
olaR.set_overlap(newOverlap);
}
function set_alpha(newAlpha) {
alpha = newAlpha;
}
function set(newAlpha, newOverlap, newBeta) {
alpha = newAlpha;
overlap = newOverlap;
beta = newBeta;
}
</script>
</body>
</html>