Last active
August 29, 2015 14:05
-
-
Save fjolnir/448b72c2fd22a0e0e082 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
// 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