-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio2.html
More file actions
108 lines (75 loc) · 1.92 KB
/
audio2.html
File metadata and controls
108 lines (75 loc) · 1.92 KB
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
<html>
<head>
<title>A-440</title>
</head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="assets/js/buffer-loader.js"></script>
<script src="assets/js/volume-sample.js"></script>
<script type="text/javascript">
/*
Thanks to Boris @ http://www.html5rocks.com/en/tutorials/webaudio/intro/ !
*/
// Keep track of all loaded buffers.
var BUFFERS = {};
// Page-wide audio context.
var context = null;
// An object to track the buffers to load {name: path}
var BUFFERS_TO_LOAD = {
a440: 'assets/audio/440_short.ogg',
/* kick: 'sounds/kick.wav',
snare: 'sounds/snare.wav',
hihat: 'sounds/hihat.wav',
jam: 'sounds/br-jam-loop.wav',
crowd: 'sounds/clapping-crowd.wav',
drums: 'sounds/blueyellow.wav',
organ: 'sounds/organ-echo-chords.wav',
techno: 'sounds/techno.wav'
*/
};
// Loads all sound samples into the buffers object.
function loadBuffers() {
// Array-ify
var names = [];
var paths = [];
for (var name in BUFFERS_TO_LOAD) {
var path = BUFFERS_TO_LOAD[name];
names.push(name);
paths.push(path);
}
bufferLoader = new BufferLoader(context, paths, function(bufferList) {
for (var i = 0; i < bufferList.length; i++) {
var buffer = bufferList[i];
var name = names[i];
BUFFERS[name] = buffer;
}
});
bufferLoader.load();
}
document.addEventListener('DOMContentLoaded', function() {
try {
// Fix up prefixing
window.AudioContext = window.AudioContext || window.webkitAudioContext;
context = new AudioContext();
}
catch(e) {
alert("Error: "+ e);
}
loadBuffers();
console.log( context );
var v = new VolumeSample( get_context() );
v.play();
});
var get_context = function(){
return context;
}
</script>
</head>
<body>
<a id="start" href="#">Start</a> | <a id="stop" href="#">Stop</a>
<p> </p>
<div id="play">
►<br />
■
</div>
</body>
</html>