-
Notifications
You must be signed in to change notification settings - Fork 0
/
panner.html
36 lines (32 loc) · 867 Bytes
/
panner.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>web-audio-example</title>
</head>
<body>
<audio src="/files/dhxy.wav" controls>
Your browser does not support the audio tag.
</audio>
<script>
// create web audio context
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// create source
var myAudio = document.querySelector('audio');
var source = audioCtx.createMediaElementSource(myAudio);
// create panner
var panner = audioCtx.createPanner();
// connect nodes
source.connect(panner);
panner.connect(audioCtx.destination);
// add 3d effect
var a=0,r=5;
function rotate() {
requestAnimationFrame(rotate);
panner.setPosition(Math.sin(a / 100) * r, 0, Math.cos(a / 100) * r);
a++;
}
rotate();
</script>
</body>
</html>