forked from jakubfiala/soundtouch-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
47 lines (38 loc) · 1.1 KB
/
example.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
//AC polyfill
window.AudioContext = window.AudioContext ||
window.webkitAudioContext ||
window.mozAudioContext ||
window.oAudioContext ||
window.msAudioContext
var context = new webkitAudioContext();
var pitchshifter, buffer;
//GET AUDIO FILE
var request = new XMLHttpRequest();
request.open('GET', 'sound1.wav', true);
request.responseType = 'arraybuffer';
request.onload = function() {
console.log('url loaded');
context.decodeAudioData(request.response, function(buf) {
//we now have the audio data
buffer = buf;
console.log('decoded');
pitchshifter = new PitchShifter(context, buffer, 1024);
pitchshifter.tempo = 0.75;
});
}
console.log('reading url');
request.send();
//PLAYBACK
function play() {
pitchshifter.connect(context.destination);
console.log("play")
}
function pause() {
pitchshifter.disconnect();
}
document.getElementById('tempoSlider').addEventListener('input', function(){
pitchshifter.tempo = this.value;
});
document.getElementById('pitchSlider').addEventListener('input', function(){
pitchshifter.pitch = this.value;
});