MTG / essentia.js

JavaScript library for music/audio analysis and processing powered by Essentia WebAssembly
https://essentia.upf.edu/essentiajs
GNU Affero General Public License v3.0
632 stars 41 forks source link

Efficient way to pass JS typed array to std::vector in both C++ and JS side #13

Closed albincorreya closed 4 years ago

albincorreya commented 4 years ago

Issue

Most of the essentia algorithms use std::vector type as array input. This means we might need to convert to and from JS typed array and std::vector types.

Currently, we are achieving this using some helper functions in essentia.tools.js which does the conversion by copying its elements. This might be an overhead for doing efficient computation. Maybe a better way would be is to pass its pointer and directly accessing Emscripten heap.

Proposed fix

There are some proposed fixes in this thread https://github.com/emscripten-core/emscripten/issues/5519#issuecomment-589702756.

Some initial benchmarks in this thread shows its potential for JS typed array to std::vector conversion from the C++ side.