Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1426:88541651d103
Feature #1478: <audioElements> have a gain attribute, in decibels, which controls the playback gain in that page.
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Fri, 11 Dec 2015 17:33:14 +0000 |
parents | 391a2d0d5707 |
children | 141482fa64fe |
comparison
equal
deleted
inserted
replaced
1425:143a4cb7dff2 | 1426:88541651d103 |
---|---|
213 { | 213 { |
214 xmlDoc.appendChild(testState.stateResults[i]); | 214 xmlDoc.appendChild(testState.stateResults[i]); |
215 } | 215 } |
216 | 216 |
217 return xmlDoc; | 217 return xmlDoc; |
218 } | |
219 | |
220 function linearToDecibel(gain) | |
221 { | |
222 return 20.0*Math.log10(gain); | |
223 } | |
224 | |
225 function decibelToLinear(gain) | |
226 { | |
227 return Math.pow(10,gain/20.0); | |
218 } | 228 } |
219 | 229 |
220 function interfacePopup() { | 230 function interfacePopup() { |
221 // Creates an object to manage the popup | 231 // Creates an object to manage the popup |
222 this.popup = null; | 232 this.popup = null; |
826 { | 836 { |
827 if (i != id) { | 837 if (i != id) { |
828 this.audioObjects[i].outputGain.gain.value = 0.0; | 838 this.audioObjects[i].outputGain.gain.value = 0.0; |
829 this.audioObjects[i].stop(); | 839 this.audioObjects[i].stop(); |
830 } else if (i == id) { | 840 } else if (i == id) { |
831 this.audioObjects[id].outputGain.gain.value = 1.0; | 841 this.audioObjects[id].outputGain.gain.value = this.audioObjects[id].specification.gain; |
832 this.audioObjects[id].play(audioContext.currentTime+0.01); | 842 this.audioObjects[id].play(audioContext.currentTime+0.01); |
833 } | 843 } |
834 } | 844 } |
835 } | 845 } |
836 interfaceContext.playhead.start(); | 846 interfaceContext.playhead.start(); |
868 break; | 878 break; |
869 } | 879 } |
870 } | 880 } |
871 if (buffer == null) | 881 if (buffer == null) |
872 { | 882 { |
873 console.log("[WARN]: Buffer was not loaded in pre-test!"); | 883 console.log("[WARN]: Buffer was not loaded in pre-test! "+URL); |
874 buffer = new this.bufferObj(URL); | 884 buffer = new this.bufferObj(URL); |
875 this.buffers.push(buffer); | 885 this.buffers.push(buffer); |
876 } | 886 } |
877 this.audioObjects[audioObjectId].specification = element; | 887 this.audioObjects[audioObjectId].specification = element; |
888 this.audioObjects[audioObjectId].url = URL; | |
878 this.audioObjects[audioObjectId].buffer = buffer; | 889 this.audioObjects[audioObjectId].buffer = buffer; |
879 if (buffer.buffer != null) | 890 if (buffer.buffer != null) |
880 { | 891 { |
881 this.audioObjects[audioObjectId].state = 1; | 892 this.audioObjects[audioObjectId].state = 1; |
882 } | 893 } |
1039 } | 1050 } |
1040 } | 1051 } |
1041 } else { | 1052 } else { |
1042 return 0; | 1053 return 0; |
1043 } | 1054 } |
1044 }; | |
1045 | |
1046 this.constructTrack = function(url) { | |
1047 var request = new XMLHttpRequest(); | |
1048 this.url = url; | |
1049 request.open('GET',url,true); | |
1050 request.responseType = 'arraybuffer'; | |
1051 | |
1052 var audioObj = this; | |
1053 | |
1054 // Create callback to decode the data asynchronously | |
1055 request.onloadend = function() { | |
1056 audioContext.decodeAudioData(request.response, function(decodedData) { | |
1057 audioObj.buffer = decodedData; | |
1058 audioObj.state = 1; | |
1059 if (audioObj.specification.type != 'outsidereference') | |
1060 {audioObj.interfaceDOM.enable();} | |
1061 }, function(){ | |
1062 // Should only be called if there was an error, but sometimes gets called continuously | |
1063 // Check here if the error is genuine | |
1064 if (audioObj.state == 0 || audioObj.buffer == undefined) { | |
1065 // Genuine error | |
1066 console.log('FATAL - Error loading buffer on '+audioObj.id); | |
1067 if (request.status == 404) | |
1068 { | |
1069 console.log('FATAL - Fragment '+audioObj.id+' 404 error'); | |
1070 console.log('URL: '+audioObj.url); | |
1071 errorSessionDump('Fragment '+audioObj.id+' 404 error'); | |
1072 } | |
1073 } | |
1074 }); | |
1075 }; | |
1076 request.send(); | |
1077 }; | 1055 }; |
1078 | 1056 |
1079 this.exportXMLDOM = function() { | 1057 this.exportXMLDOM = function() { |
1080 var root = document.createElement('audioElement'); | 1058 var root = document.createElement('audioElement'); |
1081 root.id = this.specification.id; | 1059 root.id = this.specification.id; |
1990 this.id = null; | 1968 this.id = null; |
1991 this.parent = null; | 1969 this.parent = null; |
1992 this.type = "normal"; | 1970 this.type = "normal"; |
1993 this.marker = false; | 1971 this.marker = false; |
1994 this.enforce = false; | 1972 this.enforce = false; |
1973 this.gain = 1.0; | |
1995 this.decode = function(parent,xml) | 1974 this.decode = function(parent,xml) |
1996 { | 1975 { |
1997 this.url = xml.getAttribute('url'); | 1976 this.url = xml.getAttribute('url'); |
1998 this.id = xml.id; | 1977 this.id = xml.id; |
1999 this.parent = parent; | 1978 this.parent = parent; |
2000 this.type = xml.getAttribute('type'); | 1979 this.type = xml.getAttribute('type'); |
1980 var gain = xml.getAttribute('gain'); | |
1981 if (isNaN(gain) == false && gain != null) | |
1982 { | |
1983 this.gain = decibelToLinear(Number(gain)); | |
1984 } | |
2001 if (this.type == null) {this.type = "normal";} | 1985 if (this.type == null) {this.type = "normal";} |
2002 if (this.type == 'anchor') {this.anchor = true;} | 1986 if (this.type == 'anchor') {this.anchor = true;} |
2003 else {this.anchor = false;} | 1987 else {this.anchor = false;} |
2004 if (this.type == 'reference') {this.reference = true;} | 1988 if (this.type == 'reference') {this.reference = true;} |
2005 else {this.reference = false;} | 1989 else {this.reference = false;} |
2006 | |
2007 if (this.anchor == true || this.reference == true) | 1990 if (this.anchor == true || this.reference == true) |
2008 { | 1991 { |
2009 this.marker = xml.getAttribute('marker'); | 1992 this.marker = xml.getAttribute('marker'); |
2010 if (this.marker != undefined) | 1993 if (this.marker != undefined) |
2011 { | 1994 { |
2033 { | 2016 { |
2034 var AENode = root.createElement("audioElements"); | 2017 var AENode = root.createElement("audioElements"); |
2035 AENode.id = this.id; | 2018 AENode.id = this.id; |
2036 AENode.setAttribute("url",this.url); | 2019 AENode.setAttribute("url",this.url); |
2037 AENode.setAttribute("type",this.type); | 2020 AENode.setAttribute("type",this.type); |
2021 AENode.setAttribute("gain",linearToDecibel(this.gain)); | |
2038 if (this.marker != false) | 2022 if (this.marker != false) |
2039 { | 2023 { |
2040 AENode.setAttribute("marker",this.marker*100); | 2024 AENode.setAttribute("marker",this.marker*100); |
2041 } | 2025 } |
2042 return AENode; | 2026 return AENode; |