Javascript 使用Module.HEAP8.set获取混乱数据
我使用emscripten将c代码编译成asm.js 我的c代码如下:Javascript 使用Module.HEAP8.set获取混乱数据,javascript,emscripten,Javascript,Emscripten,我使用emscripten将c代码编译成asm.js 我的c代码如下: int _call_main(char* p, int number)//p is the start arrary, number is the lengh var decode_encode_audio = Module.cwrap('_call_main', 'number', ['array','number']); ........ var byteArray = new Uint8Array(message.
int _call_main(char* p, int number)//p is the start arrary, number is the lengh
var decode_encode_audio = Module.cwrap('_call_main', 'number', ['array','number']);
........
var byteArray = new Uint8Array(message.data);//audio data
var offset = Module._malloc(70000);
Module.HEAP8.set(byteArray, offset);
decode_encode_audio(offset , byteArray.length);
我想向c代码发送bytearray数据,我的Js代码如下:
int _call_main(char* p, int number)//p is the start arrary, number is the lengh
var decode_encode_audio = Module.cwrap('_call_main', 'number', ['array','number']);
........
var byteArray = new Uint8Array(message.data);//audio data
var offset = Module._malloc(70000);
Module.HEAP8.set(byteArray, offset);
decode_encode_audio(offset , byteArray.length);
在C代码中,我打印了点P数组,得到了一个混乱的数据,P的起始部分和结束部分是正确的(我保存文件),但是中间部分被弄乱了。我用[Meal.HeAPu8.set ]替换函数(Meave.HeAP8. set),也得到了错误。我不知道为什么
我更改Js代码:var decode_encode_audio = Module.cwrap('_call_main', 'number', ['number','number']);//not array
........
var byteArray = new Uint8Array(message.data);//audio data
//var offset = Module._malloc(70000);
//Module.HEAP8.set(byteArray, offset);
decode_encode_audio(byteArray, byteArray.length);
我可以得到正确的数据
谁能告诉我“Module.HEAP8.set”方法有什么问题。您正在将未签名数据从
Uint8Array
写入签名视图HEAP8
。您应该使用HEAPU8
,它用于无符号数据。在我发布的文章中,我使用了HEAPU8进行了测试。我的缺点是,差异很小。我们可以举一个加扰数据的例子来说明问题吗?