Skip to content

Commit

Permalink
rm requestAnimationFrame throttle in onaudioprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Jul 30, 2013
1 parent b14c5e3 commit 91a88dc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
8 changes: 4 additions & 4 deletions src/drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ WaveSurfer.Drawer = {
waveColor : '#999',
progressColor : '#333',
cursorColor : '#ddd',
markerColor : '#eee',
loaderColor : '#999',
loaderHeight : 2,
cursorWidth : 1,
loadPercent : false,
markerWidth : 1,
container : null
},
Expand All @@ -20,6 +18,7 @@ WaveSurfer.Drawer = {
this.container = this.params.container;
this.width = this.container.clientWidth;
this.height = this.container.clientHeight;
this.lastPos = 0;

this.createSvg();
},
Expand Down Expand Up @@ -123,8 +122,9 @@ WaveSurfer.Drawer = {
},

progress: function (progress) {
var pos = Math.round(progress * this.width);
if (pos != this.lastPos) {
var pos = progress * this.width;
var minPxDelta = 0.5;
if (pos < this.lastPos || pos - this.lastPos >= minPxDelta) {
this.progressPath.setAttribute('width', pos);
this.cursor.setAttribute('x', pos);
this.lastPos = pos;
Expand Down
50 changes: 23 additions & 27 deletions src/wavesurfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ var WaveSurfer = {
createBackend: function () {
this.backend = Object.create(WaveSurfer.WebAudio);
this.backend.init(this.params);

var my = this;
var last;

this.backend.on('audioprocess', function (progress) {
last = Date.now();
webkitRequestAnimationFrame(function (t) {
if (last < t) {
my.onAudioProcess(progress);
}
});
my.onAudioProcess(progress);
});
},

Expand Down Expand Up @@ -241,30 +238,9 @@ var WaveSurfer = {
}
});
});
},


util: {
extend: function (dest) {
var sources = Array.prototype.slice.call(arguments, 1);
sources.forEach(function (source) {
if (source != null) {
Object.keys(source).forEach(function (key) {
dest[key] = source[key];
});
}
});
return dest;
},

getId: function () {
return 'wavesurfer_' + Math.random().toString(32).substring(2);
}
}
};

WaveSurfer.util.extend(WaveSurfer, Observer);


/* Mark */
WaveSurfer.Mark = {
Expand All @@ -283,4 +259,24 @@ WaveSurfer.Mark = {
}
};

/* Common utilities */
WaveSurfer.util = {
extend: function (dest) {
var sources = Array.prototype.slice.call(arguments, 1);
sources.forEach(function (source) {
if (source != null) {
Object.keys(source).forEach(function (key) {
dest[key] = source[key];
});
}
});
return dest;
},

getId: function () {
return 'wavesurfer_' + Math.random().toString(32).substring(2);
}
};

WaveSurfer.util.extend(WaveSurfer, Observer);
WaveSurfer.util.extend(WaveSurfer.Mark, Observer);

0 comments on commit 91a88dc

Please sign in to comment.