Skip to content

Commit

Permalink
[wasm] Hook up the audio thread
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Mar 16, 2024
1 parent cb34e5b commit 728dc90
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 2 deletions.
133 changes: 132 additions & 1 deletion Backends/System/Wasm/JS-Sources/audio-thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,138 @@ class AudioThread extends AudioWorkletProcessor {
env: { memory },
imports: {
imported_func: arg => console.log('thread: ' + arg),
create_thread
create_thread,
glViewport: function(x, y, width, height) { },
glScissor: function(x, y, width, height) { },
glGetIntegerv: function(pname, data) { },
glGetFloatv: function(pname, data) { },
glGetString: function(name) { },
glDrawElements: function(mode, count, type, offset) { },
glDrawElementsInstanced: function(mode, count, type, indices, instancecount) { },
glVertexAttribDivisor: function(index, divisor) { },
glBindFramebuffer: function(target, framebuffer) { },
glFramebufferTexture2D: function(target, attachment, textarget, texture, level) { },
glGenFramebuffers: function(n, framebuffers) { },
glGenRenderbuffers: function(n, renderbuffers) { },
glBindRenderbuffer: function(target, renderbuffer) { },
glRenderbufferStorage: function(target, internalformat, width, height) { },
glFramebufferRenderbuffer: function(target, attachment, renderbuffertarget, renderbuffer) { },
glReadPixels: function(x, y, width, height, format, type, data) { },
glTexSubImage2D: function(target, level, xoffset, yoffset, width, height, format, type, pixels) { },
glEnable: function(cap) { },
glDisable: function(cap) { },
glColorMask: function(red, green, blue, alpha) { },
glClearColor: function(red, green, blue, alpha) { },
glDepthMask: function(flag) { },
glClearDepthf: function(depth) { },
glStencilMask: function(mask) { },
glClearStencil: function(s) { },
glClear: function(mask) { },
glBindBuffer: function(target, buffer) { },
glUseProgram: function(program) { },
glStencilMaskSeparate: function(face, mask) { },
glStencilOpSeparate: function(face, fail, zfail, zpass) { },
glStencilFuncSeparate: function(face, func, ref, mask) { },
glDepthFunc: function(func) { },
glCullFace: function(mode) { },
glBlendFuncSeparate: function(src_rgb, dst_rgb, src_alpha, dst_alpha) { },
glBlendEquationSeparate: function(mode_rgb, mode_alpha) { },
glGenBuffers: function(n, buffers) { },
glBufferData: function(target, size, data, usage) { },
glCreateProgram: function() { },
glAttachShader: function(program, shader) { },
glBindAttribLocation: function(program, index, name) { },
glLinkProgram: function(program) { },
glGetProgramiv: function(program, pname, params) { },
glGetProgramInfoLog: function(program) { },
glCreateShader: function(type) { },
glShaderSource: function(shader, count, source, length) { },
glCompileShader: function(shader) { },
glGetShaderiv: function(shader, pname, params) { },
glGetShaderInfoLog: function(shader) { },
glBufferSubData: function(target, offset, size, data) { },
glEnableVertexAttribArray: function(index) { },
glVertexAttribPointer: function(index, size, type, normalized, stride, offset) { },
glDisableVertexAttribArray: function(index) { },
glGetUniformLocation: function(program, name) { },
glUniform1i: function(location, v0) { },
glUniform2i: function(location, v0, v1) { },
glUniform3i: function(location, v0, v1, v2) { },
glUniform4i: function(location, v0, v1, v2, v3) { },
glUniform1iv: function(location, count, value) { },
glUniform2iv: function(location, count, value) { },
glUniform3iv: function(location, count, value) { },
glUniform4iv: function(location, count, value) { },
glUniform1f: function(location, v0) { },
glUniform2f: function(location, v0, v1) { },
glUniform3f: function(location, v0, v1, v2) { },
glUniform4f: function(location, v0, v1, v2, v3) { },
glUniform1fv: function(location, count, value) { },
glUniform2fv: function(location, count, value) { },
glUniform3fv: function(location, count, value) { },
glUniform4fv: function(location, count, value) { },
glUniformMatrix3fv: function(location, count, transpose, value) { },
glUniformMatrix4fv: function(location, count, transpose, value) { },
glTexParameterf: function(target, pname, param) { },
glActiveTexture: function(texture) { },
glBindTexture: function(target, texture) { },
glTexParameteri: function(target, pname, param) { },
glGetActiveUniform: function(program, index, bufSize, length, size, type, name) { },
glGenTextures: function(n, textures) { },
glTexImage2D: function(target, level, internalformat, width, height, border, format, type, data) { },
glPixelStorei: function(pname, param) { },
glCompressedTexImage2D: function(target, level, internalformat, width, height, border, imageSize, data) { },
glDrawBuffers: function(n, bufs) { },
glGenerateMipmap: function(target) { },
glFlush: function() { },
glDeleteBuffers: function(n, buffers) { },
glDeleteTextures: function(n, textures) { },
glDeleteFramebuffers: function(n, framebuffers) { },
glDeleteProgram: function(program) { },
glDeleteShader: function(shader) { },
js_fprintf: function(format) {
console.log(read_string(format));
},
js_fopen: function(filename) {
return 0;
},
js_ftell: function(stream) {
return 0;
},
js_fseek: function(stream, offset, origin) {
return 0;
},
js_fread: function(ptr, size, count, stream) {
return 0;
},
js_time: function() {
return window.performance.now();
},
js_pow: function(x) {
return Math.pow(x);
},
js_floor: function(x) {
return Math.floor(x);
},
js_sin: function(x) {
return Math.sin(x);
},
js_cos: function(x) {
return Math.cos(x);
},
js_tan: function(x) {
return Math.tan(x);
},
js_log: function(base, exponent) {
return Math.log(base, exponent);
},
js_exp: function(x) {
return Math.exp(x);
},
js_sqrt: function(x) {
return Math.sqrt(x);
},
js_eval: function(str) { }
}
};

Expand Down
6 changes: 5 additions & 1 deletion Backends/System/Wasm/JS-Sources/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let heapi32 = null;
let heapf32 = null;
let mod = null;
let instance = null;
let audio_thread_started = false;

function create_thread(func) {
console.log('Creating thread');
Expand Down Expand Up @@ -492,7 +493,10 @@ async function init() {
window.requestAnimationFrame(update);

kanvas.addEventListener('click', (event) => {
// start_audio_thread();
if (!audio_thread_started) {
start_audio_thread();
audio_thread_started = true;
}
});

kanvas.addEventListener('contextmenu', (event) => {
Expand Down

0 comments on commit 728dc90

Please sign in to comment.