Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different (inaccurate) results on mobile vs desktop. #5

Closed
Leftium opened this issue Mar 15, 2020 · 3 comments
Closed

Different (inaccurate) results on mobile vs desktop. #5

Leftium opened this issue Mar 15, 2020 · 3 comments

Comments

@Leftium
Copy link

Leftium commented Mar 15, 2020

I made a beat-aware media player using music-tempo: https://phrasier.leftium.com/

It works great on desktop, however the results are not quite right on mobile browsers. The tempo should be 119 BPM, but mobile browsers result in 107 BPM. The actual beat timings are off, too. Both mobile and desktop agree on the total number of beats, though.

I think music-tempo does a deterministic analysis of the audio data, so I'm not sure how mobile and desktop results could diverge. Does music-tempo change the number of tests or cut tests short depending on the performance of the system?

@killercrush
Copy link
Owner

No, music-tempo does not change behavior depending on the perfomance of the system.
I think the results vary due to differences in hardware and/or browsers implementations of the math functions (cos, sqrt)
P.S. I followed your link in a desktop browser (Chrome 80) and got 107 BPM

@Leftium
Copy link
Author

Leftium commented Mar 15, 2020

@killercrush can you describe your hardware/environment? I've only been able to reproduce on mobile.

Minimal repro steps using only example from music-tempo:

  1. Download this video file: http://phrasier.leftium.com/media/video.mp4
  2. Process it with https://killercrush.github.io/music-tempo/example/example-simple.html
  3. Inspect output in DevTools Console

Expected tempo: 119
Actual tempo: 107


https://phrasier.leftium.com also logs results from MusicTempo() to the dev console. (And I just found out you can right-click "Store as global variable"). Almost none of the data seems to match.

I published the beats arrays for both:

Interestingly, both have the exact same number of beats, but the 107 BPM has beats that occur at 130 seconds when the video is only 119 seconds long.

@killercrush
Copy link
Owner

I figured out what the problem is. You need to create AudioContext with sampleRate config:
var context = new AudioContext({ sampleRate: 44100 });
44100 is a common sample rate value in mp3 files.
This answer on stackoverflow describes the cause of the problem.

killercrush added a commit that referenced this issue Mar 15, 2020
@elibarzilay elibarzilay mentioned this issue Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants