ddf / Minim

A Java audio library, designed to be used with Processing.
http://code.compartmental.net/tools/minim
GNU Lesser General Public License v3.0
671 stars 137 forks source link

Beat Detection Unsuitable for Offline Processing due to System.currentTimeMillis() #71

Open phr00t opened 6 years ago

phr00t commented 6 years ago

If you want to calculate beat detection offline (not in realtime), calls to things like System.currentTimeMillis() doesn't work... yet it is hardcoded into the current beat detection algorithm:

https://github.com/ddf/Minim/blob/master/src/main/java/ddf/minim/analysis/BeatDetect.java#L601

How can we modify this to work offline?

phr00t commented 6 years ago

I fixed it by adding a parameter to pass time to the detect function. I have it operate in seconds now (using the double type), instead of milliseconds... which may need some modification in other projects (or modification of the following code to work in milliseconds):

BeatDetect.zip

ddf commented 6 years ago

ah, wow, this is a good catch. i haven't looked at this code in a very long time, but i suspect what it should actually do is figure out how much time has passed based on the number of samples it has processed and the sample rate of that audio.

phr00t commented 6 years ago

Yes, that is the best solution. I already had the time in my project, so I decided to pass it as an argument in my solution. Thank you for the response & looking forward to a proper fix.