webaudiomodules / api

Web Audio Modules (WAMs) API
176 stars 15 forks source link

Should test for Uint8Array rather than ArrayBuffer? #6

Closed olilarkin closed 5 years ago

olilarkin commented 5 years ago

I can't get this to correctly call wam_onmessageA(), unless I modify this line to test if data is a Uint8Array.

I send the message like this on controller side...

EM_ASM({ var jsbuff = Module.HEAPU8.subarray($1, $1 + $2); window[Module.Pointer_stringify($0)].sendMessage('SAMFUI', "", jsbuff); }, "ControllerObjName", (int) pData, dataSize);

https://github.com/webaudiomodules/api/blob/f5bb2e7b1745621fa0b857020f5767cdc5b694f5/wamsdk/wam-processor.js#L114

jariseon commented 5 years ago

try passing ArrayBuffer instead of TypedArray like this: ...sendMessage('SAMFUI', "", jsbuff) -> ...sendMessage('SAMFUI', "", jsbuff.buffer)

with ArrayBuffers the API automatically supports all TypedArray variants, and even if data is copied into wasm heap byte by byte, c++ processor can simply cast the datatype into the type it expects.

olilarkin commented 5 years ago

Thanks

olilarkin commented 5 years ago

jsbuff.buffer returns the main Module.HEAPU8 ArrayBuffer. I don't want to send all of this over the messageport - what would you advise?

olilarkin commented 5 years ago

Module.HEAPU8.slice($1, $1 + $2) did the trick