Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Last active August 29, 2015 14:05
Show Gist options
  • Save fjolnir/448b72c2fd22a0e0e082 to your computer and use it in GitHub Desktop.
Save fjolnir/448b72c2fd22a0e0e082 to your computer and use it in GitHub Desktop.
// Signature: void write_samples(float *buf, size_t buf_len)
var write_samples = Module.cwrap('write_samples', null, ['number', 'number']);
var buf_len = 0;
var buf_addr;
var buf;
node.onaudioprocess = function(e) {
var out_data = e.outputBuffer.getChannelData(0);
if(buf_len < out_data.length) {
buf_len = out_data.length;
buf_addr = realloc(buf_addr, buf_len * 4);
buf = new Uint8Array(Module.HEAPU8.buffer, buf_addr, buf_len * 4);
}
write_samples(buf.byteOffset, out_data.length);
var result = new Float32Array(buf.buffer, buf.byteOffset, out_data.length);
out_data.set(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment