chrisguttandin / web-audio-beat-detector

A beat detection utility which is using the Web Audio API.
MIT License
577 stars 23 forks source link

Cannot read property 'peaks' of undefined #88

Closed mfbx9da4 closed 7 years ago

mfbx9da4 commented 7 years ago
  1. xhr get audio/Tombo piano.mp3 (but tried with multiple), responseType = "arraybuffer"
  2. request.onload => context.decodeAudioData => buffer
  3. I am able to play the buffer fine via source.buffer = buffer; source.start()
  4. await guess(buffer)

produces

module.js:69 Uncaught (in promise) Error: Cannot read property 'peaks' of undefined
    at Worker.onMessage (module.js:69)
chrisguttandin commented 7 years ago

Hi @mfbx9da4, thanks for reporting that issue. I just had a quick look at the source code and it might be possible that the algorithm can't detect any beats at all. That special case seems to be unhandled so far.

Are you able to upload the file you are using?

mfbx9da4 commented 7 years ago

Yes sure, here are three examples with no peaks

Why would that be it can't detect any beats?

Also could you make the source file non-minified so I can see how it works better?

chrisguttandin commented 7 years ago

Many thanks for the example files. I updated the code to throw a meaningful error. The Tombo_piano.mp3 does indeed not contain any detectable beats. At least when using the algorithm used in this package, which is a relatively trivial one. You can find a link to an article describing the algorithm in the README.

This package is just a convenient version of the web-audio-beat-detector-broker and web-audio-beat-detector-worker. It can be used without thinking about WebWorkers.

mfbx9da4 commented 7 years ago

Tombo_piano.mp3 is understandable but it's disappointing that no peaks could be found for Chambinho_do_Acordeon_e_Dominguinhos-h_z1x273cN8.mp3

chrisguttandin commented 7 years ago

I'm sorry to hear that it doesn't work for you. The algorithm works best for electronic/hip-hop/pop music which contains a prominent and steady timed baseline. Maybe you get better results if you apply some preprocessing before using this package. I'm thinking of some dynamic processing which emphasizes the onsets. But I haven't tested that.

Please feel free to tweak the algorithm for analyze() or guess(). They could surely be better.

The built-in preprocessing happens here: https://github.com/chrisguttandin/web-audio-beat-detector-broker/blob/master/src/helpers/render.ts

mfbx9da4 commented 7 years ago

Ok thanks for your help, I'll look into it if I get a chance and maybe try and port some stuff from aubio

chrisguttandin commented 7 years ago

Ok, I'm closing the issue because it was originally about the error message which is much more descriptive now.