Mercurial > hg > webaudioevaluationtool
changeset 400:3fb85ae8fced Dev_main
Feature #1478: <audioElements> have a gain attribute, in decibels, which controls the playback gain in that page.
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Fri, 11 Dec 2015 17:33:14 +0000 |
parents | fc97a9e519ac |
children | 17a2b99622c0 |
files | core.js example_eval/project.xml |
diffstat | 2 files changed, 27 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/core.js Fri Dec 11 16:24:44 2015 +0000 +++ b/core.js Fri Dec 11 17:33:14 2015 +0000 @@ -217,6 +217,16 @@ return xmlDoc; } +function linearToDecibel(gain) +{ + return 20.0*Math.log10(gain); +} + +function decibelToLinear(gain) +{ + return Math.pow(10,gain/20.0); +} + function interfacePopup() { // Creates an object to manage the popup this.popup = null; @@ -828,7 +838,7 @@ this.audioObjects[i].outputGain.gain.value = 0.0; this.audioObjects[i].stop(); } else if (i == id) { - this.audioObjects[id].outputGain.gain.value = 1.0; + this.audioObjects[id].outputGain.gain.value = this.audioObjects[id].specification.gain; this.audioObjects[id].play(audioContext.currentTime+0.01); } } @@ -870,11 +880,12 @@ } if (buffer == null) { - console.log("[WARN]: Buffer was not loaded in pre-test!"); + console.log("[WARN]: Buffer was not loaded in pre-test! "+URL); buffer = new this.bufferObj(URL); this.buffers.push(buffer); } this.audioObjects[audioObjectId].specification = element; + this.audioObjects[audioObjectId].url = URL; this.audioObjects[audioObjectId].buffer = buffer; if (buffer.buffer != null) { @@ -1042,39 +1053,6 @@ return 0; } }; - - this.constructTrack = function(url) { - var request = new XMLHttpRequest(); - this.url = url; - request.open('GET',url,true); - request.responseType = 'arraybuffer'; - - var audioObj = this; - - // Create callback to decode the data asynchronously - request.onloadend = function() { - audioContext.decodeAudioData(request.response, function(decodedData) { - audioObj.buffer = decodedData; - audioObj.state = 1; - if (audioObj.specification.type != 'outsidereference') - {audioObj.interfaceDOM.enable();} - }, function(){ - // Should only be called if there was an error, but sometimes gets called continuously - // Check here if the error is genuine - if (audioObj.state == 0 || audioObj.buffer == undefined) { - // Genuine error - console.log('FATAL - Error loading buffer on '+audioObj.id); - if (request.status == 404) - { - console.log('FATAL - Fragment '+audioObj.id+' 404 error'); - console.log('URL: '+audioObj.url); - errorSessionDump('Fragment '+audioObj.id+' 404 error'); - } - } - }); - }; - request.send(); - }; this.exportXMLDOM = function() { var root = document.createElement('audioElement'); @@ -1992,18 +1970,23 @@ this.type = "normal"; this.marker = false; this.enforce = false; + this.gain = 1.0; this.decode = function(parent,xml) { this.url = xml.getAttribute('url'); this.id = xml.id; this.parent = parent; this.type = xml.getAttribute('type'); + var gain = xml.getAttribute('gain'); + if (isNaN(gain) == false && gain != null) + { + this.gain = decibelToLinear(Number(gain)); + } if (this.type == null) {this.type = "normal";} if (this.type == 'anchor') {this.anchor = true;} else {this.anchor = false;} if (this.type == 'reference') {this.reference = true;} else {this.reference = false;} - if (this.anchor == true || this.reference == true) { this.marker = xml.getAttribute('marker'); @@ -2035,6 +2018,7 @@ AENode.id = this.id; AENode.setAttribute("url",this.url); AENode.setAttribute("type",this.type); + AENode.setAttribute("gain",linearToDecibel(this.gain)); if (this.marker != false) { AENode.setAttribute("marker",this.marker*100);
--- a/example_eval/project.xml Fri Dec 11 16:24:44 2015 +0000 +++ b/example_eval/project.xml Fri Dec 11 17:33:14 2015 +0000 @@ -71,13 +71,13 @@ <scalerange min="25" max="75"/> <commentBoxPrefix>Comment on fragment</commentBoxPrefix> </interface> - <audioElements url="0.wav" id="0" type="anchor" marker="20"/> - <audioElements url="1.wav" id="1" type="reference" marker="80"/> - <audioElements url="2.wav" id="2"/> - <audioElements url="3.wav" id="3"/> - <audioElements url="4.wav" id="4"/> - <audioElements url="5.wav" id="5"/> - <audioElements url="6.wav" id="6" type="outsidereference"/> + <audioElements url="0.wav" gain="-6" id="0" type="anchor" marker="20"/> + <audioElements url="1.wav" gain="0.0" id="1" type="reference" marker="80"/> + <audioElements url="2.wav" gain="0.0" id="2"/> + <audioElements url="3.wav" gain="0.0" id="3"/> + <audioElements url="4.wav" gain="0.0" id="4"/> + <audioElements url="5.wav" gain="0.0" id="5"/> + <audioElements url="6.wav" gain="0.0" id="6" type="outsidereference"/> <CommentQuestion id='mixingExperience' type="text">What is your general experience with numbers?</CommentQuestion> <CommentQuestion id="preference" type="radio"> <statement>Please enter your overall preference</statement>