53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
let shaderHandler, gl, c, actx, analyser, peak;
|
|
let positionData = [];
|
|
let positionSize = 8192 * 2 * 2;
|
|
|
|
function createAudioContextStream(stream) {
|
|
let AudioContext = window.AudioContext || window.webkitAudioContext;
|
|
if (actx) {
|
|
actx.close();
|
|
}
|
|
actx = new AudioContext();
|
|
analyser = actx.createAnalyser();
|
|
let Source;
|
|
|
|
analyser.fftSize = 4096;
|
|
analyser.maxDecibels = 0;
|
|
analyser.smoothingTimeConstant = .4;
|
|
Source = actx.createMediaStreamSource(stream);
|
|
|
|
Source.connect(analyser);
|
|
return null;
|
|
}
|
|
|
|
async function init() {
|
|
c = document.body.querySelector('#c');
|
|
gl = c.getContext("webgl2");
|
|
if (!gl) {
|
|
console.error("GL not found");
|
|
return false;
|
|
}
|
|
shaderHandler = new Shaders(gl);
|
|
await shaderHandler.loadShader("test", "shaders/");
|
|
|
|
//sphere shader
|
|
await shaderHandler.loadShader("sphere", "shaders/", gl.VERTEX_SHADER);
|
|
return shaderHandler.createProgramForEach(["test", "sphere"]);
|
|
}
|
|
|
|
(function () {
|
|
navigator.mediaDevices.getUserMedia({audio: true, video: false})
|
|
.then(createAudioContextStream).then(e => {
|
|
generateRotationSliders();
|
|
generateColorSliders();
|
|
generateWorldSliders();
|
|
generateDrawSliders();
|
|
generateTranslateSliders();
|
|
init().then(b => {
|
|
if (b) {
|
|
sphereObject.drawMode = gl.POINTS;
|
|
draw();
|
|
}
|
|
})
|
|
});
|
|
})(); |