Last active
August 29, 2015 14:05
-
-
Save steve-chavez/fd60fcb3e339fec81b59 to your computer and use it in GitHub Desktop.
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 getRandomInt(min, max) { | |
| return Math.floor(Math.random() * (max - min + 1)) + min; | |
| } | |
| var samples = []; | |
| for( var i=0; i<1000; i++){ samples[i] = getRandomInt(-128,127);} | |
| var floats = new Float32Array(samples.length); | |
| samples.forEach(function( sample, i ) { | |
| floats[i] = sample < 0 ? sample / 0x80 : sample / 0x7F; | |
| }); | |
| var ac = new webkitAudioContext() | |
| , ab = ac.createBuffer(1, floats.length, ac.sampleRate) | |
| , bs = ac.createBufferSource(); | |
| ab.getChannelData(0).set(floats); | |
| bs.buffer = ab; | |
| bs.connect(ac.destination); | |
| bs.start(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment