SoundTouchJS icon indicating copy to clipboard operation
SoundTouchJS copied to clipboard

PitchShifter timePlayed is inaccurate

Open jasonmcaffee opened this issue 3 years ago • 2 comments

PitchShifter's timePlayed is calculated by evaluating the number of frames extracted for a given onaudioprocess event. Since the frequency at which onaudioprocess is fired can vary, and can potentially only fire once every half second, the timePlayed cannot be accurate.

Without an accurate timePlayed, it's not possible to sync audio and visual elements with timePlayed.

I put together a codepen that demonstrates the issue. The demo plays audio and then stops it after 1 second, and displays PitchShifter's timePlayed property. After 1 second, timePlayed is 1.11 - 1.48 on my machine (2018 macbook pro using Chromium 88.0.4324.96).

https://codepen.io/jasonmcaffee/pen/WNRrrQm

Thanks!

jasonmcaffee avatar Mar 26 '21 14:03 jasonmcaffee

I also have this issue. Would love to fund workaround.

Bohooslav avatar Jun 08 '22 18:06 Bohooslav

I have found a small workaround for this. this.shifter._filter.sourceSound._position / this.shifter.sampleRate; looks more precise.

Bohooslav avatar Jun 09 '22 09:06 Bohooslav