-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs-triad.html
29 lines (24 loc) · 816 Bytes
/
js-triad.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
<html>
<script>
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var sample_rate = audioCtx.sampleRate; // 44100 hz
var samples_per_frame = 1024;
var inputChannelCount = 1; var outputChannelCount = 1;
var scriptNode = audioCtx.createScriptProcessor(
samples_per_frame, inputChannelCount, outputChannelCount
);
scriptNode.connect(audioCtx.destination);
scriptNode.onaudioprocess = function (event) {
var channelData = event.outputBuffer.getChannelData(0);
for(var i = 0; i < samples_per_frame; i++) {
var t = event.playbackTime + (i / sample_rate);
channelData[i] =
Math.sin(t * 2 * Math.PI * 440)
+ Math.sin(t * 2 * Math.PI * 556.875) / 2
+ Math.sin(t * 2 * Math.PI * 660) / 2;
}
}
</script>
<body>
</body>
</html>