-
Notifications
You must be signed in to change notification settings - Fork 1
/
minimalNoise.html
37 lines (31 loc) · 1.03 KB
/
minimalNoise.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
<!doctype html>
<html>
<head>
<title>minimal noise</title>
<script type="text/javascript">
var audioContext = new window.AudioContext;
// Generate buffer for 5 seconds white noise (1 channel)
var lengthInSamples = 5 * audioContext.sampleRate;
var buffer = audioContext.createBuffer(1, lengthInSamples, audioContext.sampleRate);
var data = buffer.getChannelData(0);
// Quote: non-interleaved IEEE 32-bit linear PCM with a nominal range of -1 -> +1
for (var i = 0; i < lengthInSamples; i++) {
data[i] = ((Math.random() * 2) - 1);
}
// Create a source node from the buffer.
var bufferSource = audioContext.createBufferSource();
bufferSource.buffer = buffer;
bufferSource.loop = true;
// Plug it in.
bufferSource.connect(audioContext.destination);
bufferSource.start(0);
</script>
</head>
<body>
<p>minimal noise</p>
<p>Reload to start.
<input type="button" onclick="bufferSource.stop(0);" value="Stop">
</p>
<p>tested with Chrome only (Version 44.0.2403.155 m, Aug 2015)</p>
</body>
</html>