fluid-work IRC Logs-2013-06-09
[04:24:50 CDT(-0500)] <thealphanerd> Bosmon: are you around?
[14:46:05 CDT(-0500)] <colinclark> thealphanerd: you around?
[14:46:11 CDT(-0500)] <thealphanerd> indeed
[14:46:14 CDT(-0500)] <thealphanerd> but only for a minute
[14:46:46 CDT(-0500)] <colinclark> ok
[14:46:53 CDT(-0500)] <colinclark> your problem should be pretty straightforward to resolve
[14:47:04 CDT(-0500)] <colinclark> ultimately, there are no pointers in JavaScript
[14:47:06 CDT(-0500)] <colinclark> just arrays of bytes
[14:47:15 CDT(-0500)] <colinclark> and arrays of indices into arrays of bytes
[14:47:42 CDT(-0500)] <colinclark> I'm trying to see whether you can specify to cwrap that the return type of a function should be a typed array
[14:47:52 CDT(-0500)] <colinclark> otherwise, you'll just have to read the values off the heap directly
[14:51:27 CDT(-0500)] <thealphanerd> which is what I am currently doing
[14:51:39 CDT(-0500)] <thealphanerd> kinda
[14:51:47 CDT(-0500)] <colinclark> you're not
[14:51:53 CDT(-0500)] <thealphanerd> oh wai
[14:52:05 CDT(-0500)] <thealphanerd> you mean have the webaudio function directly read off the heap?
[14:52:09 CDT(-0500)] <colinclark> you're reading values off the heap, one by one, and putting them into new array
[14:52:14 CDT(-0500)] <colinclark> sadly, you can't
[14:52:20 CDT(-0500)] <colinclark> but you can at least get rid of one iteration
[14:52:25 CDT(-0500)] <colinclark> so here's how typed arrays work
[14:52:33 CDT(-0500)] <colinclark> they're "views" on an ArrayBuffer
[14:52:42 CDT(-0500)] <thealphanerd> there use to be an emscripten function called array_copy
[14:52:53 CDT(-0500)] <thealphanerd> you can see this
[14:52:53 CDT(-0500)] <colinclark> You don't want to copy, that's the thing
[14:52:54 CDT(-0500)] <thealphanerd> https://github.com/kripken/emscripten/issues/87
[14:53:08 CDT(-0500)] <thealphanerd> ahhh because array_copy is what I am doing already
[14:53:22 CDT(-0500)] <colinclark> So, ArrayBuffers are just arrays of bytes
[14:53:26 CDT(-0500)] <colinclark> you can't do anything with them direclty
[14:53:31 CDT(-0500)] <colinclark> you need a "view" on them
[14:53:39 CDT(-0500)] <colinclark> which lets you index them by type
[14:54:02 CDT(-0500)] <colinclark> So, you need to know at which offset your data starts in the heap
[14:54:11 CDT(-0500)] <colinclark> and then you need to create a Float32Array view on it
[14:54:18 CDT(-0500)] <thealphanerd> oh ok
[14:54:20 CDT(-0500)] <thealphanerd> that is pretty easy
[14:54:36 CDT(-0500)] <thealphanerd> the function currently returns a pointer to the array
[14:54:37 CDT(-0500)] <colinclark> I assume that.ptr is just a index into the heap, is it?
[14:54:51 CDT(-0500)] <thealphanerd> yup
[14:55:07 CDT(-0500)] <colinclark> so it's super easy
[14:55:15 CDT(-0500)] <thealphanerd> so I should be able to use a Float32Array view over that pointer?
[14:55:21 CDT(-0500)] <colinclark> Check out the fourth constructor here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays/Float32Array?redirectlocale=en-US&redirectslug=JavaScript%2FTyped_arrays%2FFloat32Array
[14:55:43 CDT(-0500)] <thealphanerd> btw I gotta run in a few minutes
[14:55:51 CDT(-0500)] <colinclark> if that.ptr is just an index (in bytes) into the heap, then it's as easy as
[14:56:04 CDT(-0500)] <thealphanerd> that is exactly what it is
[14:56:10 CDT(-0500)] <thealphanerd> and this is exactly what I couldn't figure out last night
[14:56:21 CDT(-0500)] <colinclark> new Float32Array(heap.buffer, that.ptr, byteLength)
[14:56:42 CDT(-0500)] <colinclark> But I'm thinking cwrap should give you a way to say "this function returns a Float32Array"
[14:56:44 CDT(-0500)] <colinclark> who knows?
[14:57:09 CDT(-0500)] <thealphanerd> perhaps
[14:57:36 CDT(-0500)] <thealphanerd> but wait
[14:57:40 CDT(-0500)] <thealphanerd> it isn't a Float32Array
[14:57:42 CDT(-0500)] <thealphanerd> now that I think about it
[14:57:49 CDT(-0500)] <thealphanerd> its an array of pointers to floats
[14:58:13 CDT(-0500)] <colinclark> Presumably that's exactly what Emscripten takes care of, no?
[14:58:19 CDT(-0500)] <colinclark> Converting pointers to arrays?
[14:58:33 CDT(-0500)] <colinclark> again, there are no pointers in JavaScript
[14:58:35 CDT(-0500)] <colinclark> just arrays
[14:58:56 CDT(-0500)] <colinclark> Looking at the source code, it does look like cwrap will take "array" as a type argument
[14:58:58 CDT(-0500)] <thealphanerd> I gotta run
[14:59:02 CDT(-0500)] <colinclark> but I don't know if it will do what you want
[14:59:06 CDT(-0500)] <thealphanerd> but yeah these are the questions I figure they can aswer really easily
[14:59:09 CDT(-0500)] <colinclark> Good luck with this
[14:59:24 CDT(-0500)] <colinclark> I look forward to adding it to Flocking's benchmarks so we can see what asm.js will give us
[15:00:11 CDT(-0500)] <colinclark>
[15:00:39 CDT(-0500)] <thealphanerd> I have a feeling like using emscripten will prove less efficient for simple ugens
[15:00:50 CDT(-0500)] <thealphanerd> but scale way better for more complicated block diagrams
[15:01:20 CDT(-0500)] <thealphanerd> ok time to go
[15:01:21 CDT(-0500)] <thealphanerd> talk soon
[15:01:25 CDT(-0500)] <colinclark> see you