I'm quite new to the Web Audio API and I'm trying to change the playback rate of a sound without having to stop/ pause it. Currently, this piece of code works (TypeScript): I load the sound like this:
private init(): void {
const tmpLoop: Audio = this.engineLoop = new Audio(this.cameraManager.listener);
const idleLoader: AudioLoader = new AudioLoader();
idleLoader.load("../../assets/sounds/engine.ogg",
(buffer: AudioBuffer) => {
tmpLoop.setBuffer(buffer);
tmpLoop.setLoop(true);
tmpLoop.setVolume(0.5);
},
() => { },
() => { });
}
And then every frame I change playbackRate like this:
public modifyPlayBackSpeed(rpm: number): void {
if(rpm > 800)
{
this.engineLoop.pause();
this.engineLoop.playbackRate = (2/4700)*(rpm-800)+1;
this.engineLoop.play();
}
But it's nowhere near as fluid as I would like, since it keeps clipping the sample every frame.
I would like the sound to play continuously while changing playback rate, like this engine sound.