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
645 stars 42 forks source link

Type VectorFLoat? #89

Closed Oortone closed 2 years ago

Oortone commented 2 years ago

What is the issue about?

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

Description

New user: Using the spectrum method I get callbacks with an object just like RMS in the example. However seems I can't acces the bins – in analogy with ReturnedObject.rms – using ReturnedObject.spectrum[1] for bin 1 and so on. I see the returned object is of type VectorFloat. Is this an Essentia type? Or where else can I find information on this type and others non standard Javascript types used? I tried searching. ...

Steps to reproduce / Code snippets / Screenshots

-

System info

i.e. Hardware, OS, platform (which browser / version of Node, etc), Essentia.js version...

jmarcosfer commented 2 years ago

Hi @Oortone

VectorFloats are an internal type in essentia.js; most algorithms take their input data as VectorFloat and output VectorFloat if their result is an array of values (as opposed to single-valued outputs, which are inmediately readable in JS).

Use essentia.vectorToArray(spectrum) to convert the spectrum data to a readable format. Here's the reference.

You can also use the following pattern to read directly from the VectorFloat without converting. This uses the methods from the VectorFloat type itself, which is not super well documented (see here and here: bear in mind that essentia.js is a cross-compilation of the C++ industry standard Essentia)

for(let i=0; i < spectrum.size(); i++){
    let binData = spectrum.get(i);
    // do whatever you want with the data
}

Hope that helps!

Oortone commented 2 years ago

Great, I noticed that get method but didn't know how to use it. So basically, when I need to do something myself more than iteration with these vectors, I will need to convert it to Float32array?

jmarcosfer commented 2 years ago

Exactly. But if you want to chain several essentia.js algorithms, you don't have to do anything, as they work with VectorFloat in and out.