Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 2351:e157b2b88219
Fix for #13. Synchronous playback and looped playback are different things.
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Mon, 16 May 2016 11:24:40 +0100 |
parents | 7de03d416f38 |
children | 76a4878d0f1f |
comparison
equal
deleted
inserted
replaced
2347:7de03d416f38 | 2351:e157b2b88219 |
---|---|
1190 this.timer = new timer(); | 1190 this.timer = new timer(); |
1191 // Create session metrics | 1191 // Create session metrics |
1192 this.metric = new sessionMetrics(this,specification); | 1192 this.metric = new sessionMetrics(this,specification); |
1193 | 1193 |
1194 this.loopPlayback = false; | 1194 this.loopPlayback = false; |
1195 this.synchPlayback = false; | |
1196 this.pageSpecification = null; | |
1195 | 1197 |
1196 this.pageStore = null; | 1198 this.pageStore = null; |
1197 | 1199 |
1198 // Create store for new audioObjects | 1200 // Create store for new audioObjects |
1199 this.audioObjects = []; | 1201 this.audioObjects = []; |
1397 console.error('FATAL - Passed id was undefined - AudioEngineContext.play(id)'); | 1399 console.error('FATAL - Passed id was undefined - AudioEngineContext.play(id)'); |
1398 return; | 1400 return; |
1399 } else { | 1401 } else { |
1400 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]); | 1402 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]); |
1401 } | 1403 } |
1402 if (this.loopPlayback) { | 1404 if (this.synchPlayback && this.loopPlayback) { |
1405 // Traditional looped playback | |
1403 var setTime = audioContext.currentTime+specification.crossFade; | 1406 var setTime = audioContext.currentTime+specification.crossFade; |
1404 for (var i=0; i<this.audioObjects.length; i++) | 1407 for (var i=0; i<this.audioObjects.length; i++) |
1405 { | 1408 { |
1406 this.audioObjects[i].play(audioContext.currentTime); | 1409 this.audioObjects[i].play(audioContext.currentTime); |
1407 if (id == i) { | 1410 if (id == i) { |
1408 this.audioObjects[i].loopStart(setTime); | 1411 this.audioObjects[i].loopStart(setTime); |
1409 } else { | 1412 } else { |
1410 this.audioObjects[i].loopStop(setTime); | 1413 this.audioObjects[i].loopStop(setTime); |
1411 } | 1414 } |
1412 } | 1415 } |
1413 } else { | 1416 } else { |
1414 var setTime = audioContext.currentTime+specification.crossFade; | 1417 var setTime = audioContext.currentTime+specification.crossFade; |
1415 for (var i=0; i<this.audioObjects.length; i++) | 1418 for (var i=0; i<this.audioObjects.length; i++) |
1416 { | 1419 { |
1417 if (i != id) { | 1420 if (i != id) { |
1418 this.audioObjects[i].stop(setTime); | 1421 this.audioObjects[i].stop(setTime); |
1479 return this.audioObjects[audioObjectId]; | 1482 return this.audioObjects[audioObjectId]; |
1480 }; | 1483 }; |
1481 | 1484 |
1482 this.newTestPage = function(audioHolderObject,store) { | 1485 this.newTestPage = function(audioHolderObject,store) { |
1483 this.pageStore = store; | 1486 this.pageStore = store; |
1487 this.pageSpecification = audioHolderObject; | |
1484 this.status = 0; | 1488 this.status = 0; |
1485 this.audioObjectsReady = false; | 1489 this.audioObjectsReady = false; |
1486 this.metric.reset(); | 1490 this.metric.reset(); |
1487 for (var i=0; i < this.buffers.length; i++) | 1491 for (var i=0; i < this.buffers.length; i++) |
1488 { | 1492 { |
1489 this.buffers[i].users = []; | 1493 this.buffers[i].users = []; |
1490 } | 1494 } |
1491 this.audioObjects = []; | 1495 this.audioObjects = []; |
1492 this.timer = new timer(); | 1496 this.timer = new timer(); |
1493 this.loopPlayback = audioHolderObject.loop; | 1497 this.loopPlayback = audioHolderObject.loop; |
1498 this.synchPlayback = audioHolderObject.synchronous; | |
1494 }; | 1499 }; |
1495 | 1500 |
1496 this.checkAllPlayed = function() { | 1501 this.checkAllPlayed = function() { |
1497 arr = []; | 1502 arr = []; |
1498 for (var id=0; id<this.audioObjects.length; id++) { | 1503 for (var id=0; id<this.audioObjects.length; id++) { |
1643 //event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition()); | 1648 //event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition()); |
1644 if (event.currentTarget != null) { | 1649 if (event.currentTarget != null) { |
1645 event.currentTarget.owner.stop(audioContext.currentTime+1); | 1650 event.currentTarget.owner.stop(audioContext.currentTime+1); |
1646 } | 1651 } |
1647 }; | 1652 }; |
1648 if (this.bufferNode.loop == false) { | 1653 if (!audioEngineContext.loopPlayback || !audioEngineContext.synchPlayback) { |
1649 this.metric.startListening(audioEngineContext.timer.getTestTime()); | 1654 this.metric.startListening(audioEngineContext.timer.getTestTime()); |
1650 this.outputGain.gain.setValueAtTime(this.onplayGain,startTime); | 1655 this.outputGain.gain.setValueAtTime(this.onplayGain,startTime); |
1651 this.interfaceDOM.startPlayback(); | 1656 this.interfaceDOM.startPlayback(); |
1652 } else { | 1657 } else { |
1653 this.outputGain.gain.setValueAtTime(0.0,startTime); | 1658 this.outputGain.gain.setValueAtTime(0.0,startTime); |