SoundTouchJS
SoundTouchJS copied to clipboard
PitchShifter timePlayed is inaccurate
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!
I also have this issue. Would love to fund workaround.
I have found a small workaround for this. this.shifter._filter.sourceSound._position / this.shifter.sampleRate;
looks more precise.