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
628 stars 41 forks source link

arrayToVector convertion stretches the audio (?) #88

Closed thomasborgogno closed 2 years ago

thomasborgogno commented 2 years ago

What is the issue about?

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

Description

When I launch any BeatTracker I retrieve ticks that are after the audio is ended, for example with an audio of 30s i get some ticks at 31, 33 seconds. I don't know if it's a problem of mine or an effective bug, but maybe the problem is in the convertion from array to vector?

Steps to reproduce / Code snippets / Screenshots

let audioData = await essentiaExtractor.getAudioChannelDataFromURL(audioURL, audioCtx, 0); let signal = essentiaExtractor.arrayToVector(audioData); let ticks = await essentiaExtractor.BeatTrackerMultiFeature(signal).ticks; for(var i=0; i<ticks.size(); ++i){ console.log(ticks.get(i)); }

Thank you for your amazing work, I hope this is not a dumb request, and sorry for my bad english

jmarcosfer commented 2 years ago

Hi @thomasborgogno

I've been able to replicate your issue. This isn't a problem with the arrayToVector conversion. This has to do with sample rate.

BeatTrackerMultiFeature assumes a sample rate of 44100 hz. This isn't mentioned on our documentation (we will fix this when we update the docs), but it is mentioned in the upstream Essentia documentation.

What you've experienced is most likely due to your computer audio having a sample rate higher than 44100 hz (typically 48000 hz). In that case, each second will contain 48000 samples. But BeatTrackerMultiFeature assumes there are only 44100 samples per second, so it will have extra samples at the end and will consider the audio file to be longer than it is. That's why it outputs time stamps apparently "after the audio is ended".

Simply try to ensure that your system audio is working at 44100 hz sampling rate. It's a pity that this can't be controlled from the browser (i.e. the BaseAudioContext.sampleRate is read-only).

hope this helps!

thomasborgogno commented 2 years ago

Thank you very much for your kind reply, that was the problem!