use the playbackRate when computing the offset of a synced player

fixes #349
This commit is contained in:
tambien 2019-03-12 11:25:33 -04:00
parent 15823d2664
commit 023758425b
3 changed files with 27 additions and 1 deletions

View file

@ -198,8 +198,16 @@ Tone.Player.prototype._start = function(startTime, offset, duration){
//compute the values in seconds
offset = this.toSeconds(offset);
//if it's synced, it should factor in the playback rate for computing the offset
if (this._synced){
offset *= this._playbackRate;
}
//compute the duration which is either the passed in duration of the buffer.duration - offset
var computedDuration = Tone.defaultArg(duration, Math.max(this._buffer.duration - offset, 0));
computedDuration = this.toSeconds(computedDuration);
//scale it by the playback rate
computedDuration = computedDuration / this._playbackRate;

View file

@ -1,6 +1,6 @@
{
"name": "tone",
"version": "13.7.0",
"version": "13.8.0",
"description": "A Web Audio framework for making interactive music in the browser.",
"main": "build/Tone.js",
"files": [

View file

@ -450,6 +450,24 @@ describe("Player", function(){
});
});
it("starts at the correct position when Transport is offset and playbackRate is not 1", function(){
return Offline(function(Transport){
//make a ramp between 0-1
var ramp = new Float32Array(Math.floor(Tone.context.sampleRate * 0.3));
for (var i = 0; i < ramp.length; i++){
ramp[i] = (i / (ramp.length));
}
var buff = Buffer.fromArray(ramp);
var player = new Player(buff).toMaster();
player.playbackRate = 0.5;
player.sync().start(0);
//start halfway through
Transport.start(0, 0.15);
}, 0.05).then(function(buffer){
expect(buffer.getValueAtTime(0)).to.be.closeTo(0.25, 0.01);
});
});
it("starts with an offset when synced and started after Transport is running", function(){
return Offline(function(Transport){
var ramp = new Float32Array(Math.floor(Tone.context.sampleRate * 0.3));