Created
September 17, 2014 05:19
-
-
Save chadaustin/508e41e2d18dc3d4eae8 to your computer and use it in GitHub Desktop.
Simple Audio API Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var context = new AudioContext(); | |
// 32000 Hz, 1 second, 200 Hz tone | |
// 32000 / 200 = exact 160 cycles | |
function playSineWave() { | |
var buffer = context.createBuffer(1, 32000, 32000); | |
var data = buffer.getChannelData(0); | |
for (var i = 0; i < data.length; ++i) { | |
data[i] = Math.sin(i / 160 * 2 * Math.PI); | |
} | |
for (var i = 0; i < 5; ++i) { | |
var source = context.createBufferSource(); | |
source.buffer = buffer; | |
source.connect(context.destination); | |
source.start(i); | |
} | |
} | |
playSineWave(); | |
})(); | |
You can work with faster integer and use var arrayFloat = Float32Array.from(array, n => n / 32768); to convert in float:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should use
context.currentTime
, in this example...3 years late... i know.