Skip to content

Commit

Permalink
fixes safari browser missing buffer when using webaudio (#1096)
Browse files Browse the repository at this point in the history
* fixes safari browser missing buffer when using webaudio

* return correct buffer

* set samples to 4096

* add safari comment
  • Loading branch information
entonbiba authored and katspaugh committed Jul 2, 2017
1 parent a1ff8ea commit 64bd48b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/webaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ WaveSurfer.WebAudio = {

this.setLength(length);

/**
* The following snippet fixes a buffering data issue on the Safari browser which returned undefined
* It creates the missing buffer based on 1 channel, 4096 samples and the sampleRate from the current webaudio context
* 4096 samples seemed to be the best fit for rendering
* will review this code once a stable version of Safari TP is out
*/
if (!this.buffer.length) {
var newBuffer = this.createBuffer(1, 4096, this.sampleRate);
this.buffer = newBuffer.buffer;
}

var sampleSize = this.buffer.length / length;
var sampleStep = ~~(sampleSize / 10) || 1;
var channels = this.buffer.numberOfChannels;
Expand Down

0 comments on commit 64bd48b

Please sign in to comment.