Hey,
I am working on a native extension at the moment and am trying to pass some bytes from c++ back to haxe. On the c++ end, I have a int16_t array that represents 16bit PCM audio data and in haxe I need an instance of haxe.io.Bytes that contains the same information as the int16_t array. I haven’t found much documentation on that topic which is why I am asking here, what the best way of doing that would be. Down below you can see how I at least managed to pass some data, obviously not correct though.
C++
extern "C" void pass_data_back(unsigned long length, const int16_t* data) {
value arr = alloc_array(length);
for (int i = 0; i < length; i++)
{
val_array_set_i(arr, i, alloc_int (data[i]));
}
val_call1(cb_onaudiodata->get(), arr);
}
Haxe
function cb_onaudiodata(arr:Dynamic)
{
var bytes = Bytes.alloc(arr.length);
for(i in 0...arr.length)
{
bytes.setInt32(i, arr[i]);
}
}