peaks.js icon indicating copy to clipboard operation
peaks.js copied to clipboard

feature request: latency offset in options

Open steve-rhodes opened this issue 5 years ago • 6 comments

I noticed that the audio and cursor are substantially out of sync (especially if you zoom in) due to some audio latency issues. Somewhere between 200 ms and 1000 ms. I haven't measured it yet. If this can't be resolved automatically by peaks, it would be great to enter a positive or negative offset in the options to bring them "in sync".

In other words: what you see doesn't align with what you hear.

thanks!

steve-rhodes avatar Jul 06 '20 12:07 steve-rhodes

Apart from a known issue with variable bitrate mp3 (#221, #239), the sync should be pretty good. Can you share an example audio file with me to take a look at?

chrisn avatar Jul 06 '20 13:07 chrisn

Chris, I've recorded a video on my iphone in slo-mo. In our app we have a peak/rms meter connected to WebAudio.

We always use .wav files, encoded as PCM 24-bit. Sampling rates can be 44.1, 48, 88 and 96kHz on our platform.

Looking at the video, you can see that peaks (waveform) is approx 20-25 ms ahead of the meter.

In the world of audio 25 ms is a lot! :) Humans in general notice a shift of +-1ms, especially with music.

Here is the link for the little video I shot: https://www.youtube.com/watch?v=-rMzo_1sydQ

First you see 44.1kHz, then the same in slo-mo, then everything again for 96kHz. Sampling rate doesn't seem to change the latency, Both have about 20-25ms.

Here are the two short wav files to test: https://www.dropbox.com/s/9et6grqnkllbz7t/441kHz.wav?dl=0 https://www.dropbox.com/s/mh69lrd74s0o5p9/96kHz.wav?dl=0

best,

Steve

steve-rhodes avatar Jul 07 '20 10:07 steve-rhodes

Ah, ok, your original issue said 200 to 1000 milliseconds, I'd be concerned if sync was that far off. As it is, 20-25ms is more in the range of what's achievable.

Thanks for creating the video, that's really helpful. Please don't take the files down straight away, it may take a while for me to investigate a solution.

chrisn avatar Jul 08 '20 09:07 chrisn

Yes, I'm sorry for the misleading initial numbers. I think it "felt" a lot more before I actually could measure the values. :)

I'll leave the files up. No problem.

steve-rhodes avatar Jul 08 '20 09:07 steve-rhodes

Hi Chris, do you think there is a chance for an offset value in ms for the playhead? A range of +/ 100 ms would be great.

This way one could align the audio to the visuals. Another problem is that some people use audio over Bluetooth, which even increases the lag.

cheers

Steve

steve-rhodes avatar Jul 12 '21 22:07 steve-rhodes

I'm hoping that this feature is as simple as adding an offset here - that's the animation loop where the playhead position is updated.

Would you mind doing an experiment to see if that works? If so, I'd be happy to take a pull request.

chrisn avatar Jul 13 '21 08:07 chrisn