Mercurial > hg > webaudioevaluationtool
changeset 300:9575df4d505a Dev_main
Bug #1391: Fixed for non-looped playback
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Mon, 14 Sep 2015 11:22:38 +0100 |
parents | 18a6119854ac |
children | 1c32dbb8ac32 |
files | ape.js core.js |
diffstat | 2 files changed, 57 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/ape.js Mon Sep 14 09:23:49 2015 +0100 +++ b/ape.js Mon Sep 14 11:22:38 2015 +0100 @@ -467,31 +467,27 @@ // Onclick, switch playback to that track this.trackSliderObj.onclick = function(event) { - // Start the test on first click, that way timings are more accurate. - audioEngineContext.play(); - if (audioEngineContext.audioObjectsReady) { - // Cannot continue to issue play command until audioObjects reported as ready! - // Get the track ID from the object ID - var element; - if (event.currentTarget.nodeName == "SPAN") { - element = event.currentTarget.parentNode; - } else { - element = event.currentTarget; - } - var id = Number(element.attributes['trackIndex'].value); - //audioEngineContext.metric.sliderPlayed(id); - audioEngineContext.play(id); - // Currently playing track red, rest green - - //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000"; - $('.track-slider').removeClass('track-slider-playing'); - $(element).addClass('track-slider-playing'); - $('.comment-div').removeClass('comment-box-playing'); - $('#comment-div-'+id).addClass('comment-box-playing'); - var outsideReference = document.getElementById('outside-reference'); - if (outsideReference != undefined) - $(outsideReference).removeClass('track-slider-playing'); + // Cannot continue to issue play command until audioObjects reported as ready! + // Get the track ID from the object ID + var element; + if (event.currentTarget.nodeName == "SPAN") { + element = event.currentTarget.parentNode; + } else { + element = event.currentTarget; } + var id = Number(element.attributes['trackIndex'].value); + //audioEngineContext.metric.sliderPlayed(id); + audioEngineContext.play(id); + // Currently playing track red, rest green + + //document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000"; + $('.track-slider').removeClass('track-slider-playing'); + $(element).addClass('track-slider-playing'); + $('.comment-div').removeClass('comment-box-playing'); + $('#comment-div-'+id).addClass('comment-box-playing'); + var outsideReference = document.getElementById('outside-reference'); + if (outsideReference != undefined) + $(outsideReference).removeClass('track-slider-playing'); }; this.enable = function() {
--- 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; } };