essentia.js icon indicating copy to clipboard operation
essentia.js copied to clipboard

VectorFloat params incorrectly converted on Typescript before passed to WASM

Open jmarcosfer opened this issue 11 months ago • 0 comments

What is the issue about?

  • [x] Bug
  • [ ] Feature request
  • [ ] Usage question
  • [ ] Documentation
  • [ ] Contributing / Development

What part(s) of Essentia.js is involved?

  • [x] essentia.js-core (vanilla algorithms)
  • [ ] essentia.js-model (machine learning algorithms)
  • [ ] essentia.js-plot (plotting utility module)
  • [ ] essentia.js-extractor (typical algorithm combinations utility)

Description

Algorithms with vector_real parameter types have these parameters converted to VectorFloat on the TypeScript wrapper using the following code pattern:

let veconsets = new this.module.VectorFloat();
for (var i=0; i<veconsets.size(); i++) {
  veconsets.push_back(onsets[i]);
}

This produces an uncaught exception on the WASM side, since VectorFloat is initialized empty by default, so the loop never runs and the parameter is passed to the C++ empty. The affected algorithms are:

  • AudioOnsetsMarker
  • BPF
  • BeatsLoudness
  • CubicSpline
  • FrequencyBands
  • IIR
  • NoveltyCurve
  • RhythmExtractor
  • SingleBeatLoudness
  • Slicer
  • Spline
  • TempoScaleBands
  • TempoTap
  • TriangularBands

Steps to reproduce / Code snippets / Screenshots

Here is a quick browser test of the algorithms FrequencyBands and BPF. This test also includes a proposed solution using one of these options:

// use the Array -> VectorFloat conversion utility function built into essentia.js
let veconsets = this.module.arrayToVector(onsets);
let veconsets = new this.module.VectorFloat();
let i = 0;
while (veconsets.size() < onsets.length) {
   veconsets.push_back(onsets[i]);
   i++;
}

This will be addressed and solved in the PR for issue #64, with revised generated code for core_api.ts.

System info

Hardware: Dell Inc. Vostro 5490; 8,0 GiB RAM; Intel Core i7-10510U CPU @ 1.80GHz × 8 OS: Ubuntu 22.04.2 LTS, 64-bit Browser: Chrome 115.0.5790.110 (Official Build) (64-bit) essentia.js 0.1.3

jmarcosfer avatar Feb 28 '24 22:02 jmarcosfer