Mercurial > hg > webaudioevaluationtool
changeset 272:7cd7c6354494 Dev_main
Feature #1287: Padding added when looping is enabled to give synchronised looping.
author | Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk> |
---|---|
date | Thu, 23 Jul 2015 10:10:38 +0100 |
parents | 99faf6d80c8d |
children | 1063d7132493 |
files | core.js example_eval/project.xml |
diffstat | 2 files changed, 40 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/core.js Thu Jul 23 09:51:26 2015 +0100 +++ b/core.js Thu Jul 23 10:10:38 2015 +0100 @@ -807,6 +807,45 @@ return ready; }; + 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++) + { + lens.push(this.audioObjects[i].buffer.length); + if (length < this.audioObjects[i].buffer.length) + { + length = this.audioObjects[i].buffer.length; + maxId = 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++) + { + 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; + } + } + }; + } function audioObject(id) {
--- a/example_eval/project.xml Thu Jul 23 09:51:26 2015 +0100 +++ b/example_eval/project.xml Thu Jul 23 10:10:38 2015 +0100 @@ -44,7 +44,7 @@ <anchor enforce="false">40</anchor> </interface> </setup> - <audioHolder id='test-0' hostURL="example_eval/" sampleRate="44100" randomiseOrder='true' repeatCount='0' loop='false' elementComments='true'> + <audioHolder id='test-0' hostURL="example_eval/" sampleRate="44100" randomiseOrder='true' repeatCount='0' loop='true' elementComments='true'> <interface> <title>Example Test Question</title> <scale position="0">Min</scale>