Skip to content

Commit

Permalink
[setPlaybackRate] Webaudio backend fix (katspaugh#2118)
Browse files Browse the repository at this point in the history
* [setPlaybackRate]
webaudio backend: set playback rate modifying directly the playback property of the source node. Removed invocation to pause and play

* [setPlaybackRate]
webaudio backend: check if source node not null

* [setPlaybackRate]
changelog
  • Loading branch information
marizuccara committed Dec 12, 2020
1 parent 2be59a0 commit 7906809
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ wavesurfer.js changelog
------------------

- Add `relativeNormalization` option to maintain proportionality between waveforms when `splitChannels` and `normalize` are `true` (#2108)
- WebAudio backend: set playback rate modifying directly the playback property of the source node (#2118)
- Spectrogram plugin: Use `ImageData` to draw pixel-by-pixel (#2127)

4.2.0 (20.10.2020)
Expand Down
18 changes: 6 additions & 12 deletions src/webaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,7 @@ export default class WebAudio extends util.Observer {
this.source.start = this.source.start || this.source.noteGrainOn;
this.source.stop = this.source.stop || this.source.noteOff;

this.source.playbackRate.setValueAtTime(
this.playbackRate,
this.ac.currentTime
);
this.setPlaybackRate(this.playbackRate);
this.source.buffer = this.buffer;
this.source.connect(this.analyser);
}
Expand Down Expand Up @@ -736,14 +733,11 @@ export default class WebAudio extends util.Observer {
* @param {number} value The playback rate to use
*/
setPlaybackRate(value) {
value = value || 1;
if (this.isPaused()) {
this.playbackRate = value;
} else {
this.pause();
this.playbackRate = value;
this.play();
}
this.playbackRate = value || 1;
this.source && this.source.playbackRate.setValueAtTime(
this.playbackRate,
this.ac.currentTime
);
}

/**
Expand Down

0 comments on commit 7906809

Please sign in to comment.