Skip to content

Commit

Permalink
Add support for forceDecode (katspaugh#1009)
Browse files Browse the repository at this point in the history
* Add support for forceDecode

Adds the `forceDecode` option to force client side decoding of the audio after download regardless if pre-decoded peaks are passed to the `.load/2` method. This is primarily for use with `.zoom/1` to enable high fidelity rendering on zoom. Without local decoding, the zoom on pre-decoded peaks is very low fidelity.

* Update conditional brackets for failing test
  • Loading branch information
scottt2 authored and katspaugh committed Feb 25, 2017
1 parent 33be11a commit 1e0a01c
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/wavesurfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,33 @@

var WaveSurfer = {
defaultParams: {
height : 128,
waveColor : '#999',
progressColor : '#555',
audioContext : null,
audioRate : 1,
autoCenter : true,
backend : 'WebAudio',
container : null,
cursorColor : '#333',
cursorWidth : 1,
skipLength : 2,
minPxPerSec : 20,
pixelRatio : window.devicePixelRatio || screen.deviceXDPI / screen.logicalXDPI,
dragSelection : true,
fillParent : true,
scrollParent : false,
forceDecode : false,
height : 128,
hideScrollbar : false,
normalize : false,
audioContext : null,
container : null,
dragSelection : true,
loopSelection : true,
audioRate : 1,
interact : true,
splitChannels : false,
loopSelection : true,
mediaContainer: null,
mediaControls : false,
renderer : 'MultiCanvas',
backend : 'WebAudio',
mediaType : 'audio',
autoCenter : true,
partialRender : false
minPxPerSec : 20,
partialRender : false,
pixelRatio : window.devicePixelRatio || screen.deviceXDPI / screen.logicalXDPI,
progressColor : '#555',
normalize : false,
renderer : 'MultiCanvas',
scrollParent : false,
skipLength : 2,
splitChannels : false,
waveColor : '#999',
},

init: function (params) {
Expand Down Expand Up @@ -460,14 +461,16 @@ var WaveSurfer = {
}).bind(this))
);

// If no pre-decoded peaks provided, attempt to download the
// If no pre-decoded peaks provided or pre-decoded peaks are
// provided with forceDecode flag, attempt to download the
// audio file and decode it with Web Audio.
if (peaks) {
this.backend.setPeaks(peaks);
} else if (this.backend.supportsWebAudio()) {
if (peaks) { this.backend.setPeaks(peaks); }

if ((!peaks || this.params.forceDecode) && this.backend.supportsWebAudio()) {
this.getArrayBuffer(url, (function (arraybuffer) {
this.decodeArrayBuffer(arraybuffer, (function (buffer) {
this.backend.buffer = buffer;
this.backend.setPeaks(null);
this.drawBuffer();
this.fireEvent('waveform-ready');
}).bind(this));
Expand Down

0 comments on commit 1e0a01c

Please sign in to comment.