Simple Audio API Test
(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(); | |
})(); | |
This comment has been minimized.
This comment has been minimized.
Serveurperso
commented
Aug 11, 2018
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
This comment has been minimized.
mr21 commentedOct 4, 2017
You should use
context.currentTime
, in this example...3 years late... i know.