-
Notifications
You must be signed in to change notification settings - Fork 4
/
changepitch.html
64 lines (62 loc) · 1.73 KB
/
changepitch.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>change pitch</title>
<link rel="stylesheet" href="css/style.css">
<script src="js/forSafari.js"></script>
<script src="lib/IndexedDB-getAll-shim.js"></script>
<script src="js/storage.js"></script>
</head>
<body>
<p>pitch
<input id="inPitch" type="range" value="0" min="-12" max="12" step="1"/>
</p>
<section class="sound-clips">
</section>
<script>
var clips = document.querySelector('.sound-clips');
function addClipInterface(name) {
name = name.name;
var clip = document.createElement("div");
clip.className = "clip";
var lbl = document.createElement("p");
lbl.textContent = name;
var btnPlay = document.createElement("button");
btnPlay.textContent = "Play";
btnPlay.onclick = function () {
getSound(name).then(function (file) {
var fr = new FileReader();
fr.onload = function () {
audioCtx.decodeAudioData(fr.result, getBuffer, error);
};
fr.readAsArrayBuffer(file.file);
function getBuffer(buf) {
var snd = audioCtx.createBufferSource();
snd.buffer = buf;
snd.connect(audioCtx.destination);
snd.playbackRate.value = Math.pow(2, inPitch.value/12);
(snd.start || snd.noteOn).call(snd);
}
function error() {
console.error("cannot decode audio");
}
}).catch(function (buf) {
});
};
clip.appendChild(lbl);
lbl.appendChild(btnPlay);
clips.appendChild(clip);
console.log("added" + name);
}
function startup() {
getSoundNames().then(function (names) {
names.forEach(addClipInterface);
})['catch'](function (x) {
console.error(x);
});
}
</script>
</body>
</html>