-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
43 lines (37 loc) · 1.24 KB
/
main.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
// This program is licensed under the MIT License.
// Copyright 2016, aike (@aike1000)
window.onload = function() {
var ctx = new (window.AudioContext || window.webkitAudioContext)();
var player = new Player(ctx, 'sound/apan.mp3');
var splitter = ctx.createChannelSplitter(2);
var panL = ctx.createPanner();
panL.panningModel = "HRTF";
panL.setPosition(-1, 0, 0);
var panR = ctx.createPanner();
panR.panningModel = "HRTF";
panR.setPosition(1, 0, 0);
// player ----splitter
// ---- PanL ---- destination
// ---- PanR ---- destination
player.connect(splitter);
splitter.connect(panL, 0);
splitter.connect(panR, 1);
panL.connect(ctx.destination);
panR.connect(ctx.destination);
var setAngle = function(theta) {
var sn = Math.sin(theta);
var cs = Math.cos(theta);
panL.setPosition(-cs, 0, sn);
panR.setPosition(cs, 0, -sn);
}
window.addEventListener("deviceorientation", function(e){
if (e.alpha) {
setAngle(e.alpha * Math.PI / 180);
}
});
document.querySelector("#play")
.addEventListener("mouseup",
function() {
player.toggle();
});
};