Mercurial > hg > webaudioevaluationtool
diff core.js @ 1523:ed1d17b94752
Bug #1391: Fixed for non-looped playback
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Mon, 14 Sep 2015 11:22:38 +0100 |
parents | 40face84bd13 |
children | 3d13f019c3e6 |
line wrap: on
line diff
--- a/core.js Mon Sep 14 09:23:49 2015 +0100 +++ b/core.js Mon Sep 14 11:22:38 2015 +0100 @@ -714,7 +714,6 @@ // Use this to detect playback state: 0 - stopped, 1 - playing this.status = 0; - this.audioObjectsReady = false; // Connect both gains to output this.outputGain.connect(audioContext.destination); @@ -732,21 +731,24 @@ this.play = function(id) { // Start the timer and set the audioEngine state to playing (1) - if (this.status == 0) { + if (this.status == 0 && this.loopPlayback) { // Check if all audioObjects are ready - if (this.audioObjectsReady == false) { - this.audioObjectsReady = this.checkAllReady(); - } - if (this.audioObjectsReady == true) { - this.timer.startTest(); - if (this.loopPlayback) - {this.setSynchronousLoop();} + if(this.checkAllReady()) + { this.status = 1; + this.setSynchronousLoop(); } } + else + { + this.status = 1; + } if (this.status== 1) { + this.timer.startTest(); if (id == undefined) { id = -1; + console.log('FATAL - Passed id was undefined - AudioEngineContext.play(id)'); + return; } else { interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]); } @@ -833,40 +835,37 @@ this.setSynchronousLoop = function() { // Pads the signals so they are all exactly the same length - if (this.audioObjectsReady) + var length = 0; + var lens = []; + var maxId; + for (var i=0; i<this.audioObjects.length; i++) { - var length = 0; - var lens = []; - var maxId; - for (var i=0; i<this.audioObjects.length; i++) + lens.push(this.audioObjects[i].buffer.length); + if (length < this.audioObjects[i].buffer.length) { - lens.push(this.audioObjects[i].buffer.length); - if (length < this.audioObjects[i].buffer.length) - { - length = this.audioObjects[i].buffer.length; - maxId = i; - } + length = this.audioObjects[i].buffer.length; + maxId = i; } - // Perform difference - for (var i=0; i<lens.length; i++) + } + // Perform difference + for (var i=0; i<lens.length; i++) + { + lens[i] = length - lens[i]; + } + // Extract the audio and zero-pad + for (var i=0; i<lens.length; i++) + { + var orig = this.audioObjects[i].buffer; + var hold = audioContext.createBuffer(orig.numberOfChannels,length,orig.sampleRate); + for (var c=0; c<orig.numberOfChannels; c++) { - lens[i] = length - lens[i]; + var inData = hold.getChannelData(c); + var outData = orig.getChannelData(c); + for (var n=0; n<orig.length; n++) + {inData[n] = outData[n];} } - // Extract the audio and zero-pad - for (var i=0; i<lens.length; i++) - { - var orig = this.audioObjects[i].buffer; - var hold = audioContext.createBuffer(orig.numberOfChannels,length,orig.sampleRate); - for (var c=0; c<orig.numberOfChannels; c++) - { - var inData = hold.getChannelData(c); - var outData = orig.getChannelData(c); - for (var n=0; n<orig.length; n++) - {inData[n] = outData[n];} - } - this.audioObjects[i].buffer = hold; - delete orig; - } + this.audioObjects[i].buffer = hold; + delete orig; } };