comparison core.js @ 496:cb348f6208b2 Dev_main

All interfaces support comment boxes. Comment box identification matches presented tag (for instance, AB will be Comment on fragment A, rather than 1). Tighter buffer loading protocol, audioObjects register with the buffer rather than checking for buffer existence (which can be buggy depending on the buffer state). Buffers now have a state to ensure exact location in loading chain (downloading, decoding, LUFS, ready).
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Fri, 29 Jan 2016 11:11:57 +0000
parents 261ae55a3e9e
children 841de347591e
comparison
equal deleted inserted replaced
495:305742b40ddc 496:cb348f6208b2
948 this.url = null; 948 this.url = null;
949 this.buffer = null; 949 this.buffer = null;
950 this.xmlRequest = new XMLHttpRequest(); 950 this.xmlRequest = new XMLHttpRequest();
951 this.xmlRequest.parent = this; 951 this.xmlRequest.parent = this;
952 this.users = []; 952 this.users = [];
953 this.progress = 0;
954 this.status = 0;
953 this.ready = function() 955 this.ready = function()
954 { 956 {
957 if (this.status >= 2)
958 {
959 this.status = 3;
960 }
955 for (var i=0; i<this.users.length; i++) 961 for (var i=0; i<this.users.length; i++)
956 { 962 {
957 this.users[i].state = 1; 963 this.users[i].state = 1;
958 if (this.users[i].interfaceDOM != null) 964 if (this.users[i].interfaceDOM != null)
959 { 965 {
981 for (var n=0; n<waveObj.num_samples; n++) 987 for (var n=0; n<waveObj.num_samples; n++)
982 { 988 {
983 buffer_ptr[n] = waveObj.decoded_data[c][n]; 989 buffer_ptr[n] = waveObj.decoded_data[c][n];
984 } 990 }
985 } 991 }
992
986 delete waveObj; 993 delete waveObj;
987 } else { 994 } else {
988 audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) { 995 audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) {
989 bufferObj.buffer = decodedData; 996 bufferObj.buffer = decodedData;
990 }, function(e){ 997 }, function(e){
997 { 1004 {
998 console.log('FATAL - Fragment '+audioObj.id+' 404 error'); 1005 console.log('FATAL - Fragment '+audioObj.id+' 404 error');
999 console.log('URL: '+audioObj.url); 1006 console.log('URL: '+audioObj.url);
1000 errorSessionDump('Fragment '+audioObj.id+' 404 error'); 1007 errorSessionDump('Fragment '+audioObj.id+' 404 error');
1001 } 1008 }
1009 this.status = -1;
1002 } 1010 }
1003 }); 1011 });
1004 } 1012 }
1005 if (bufferObj.buffer != undefined) 1013 if (bufferObj.buffer != undefined)
1006 { 1014 {
1015 bufferObj.status = 2;
1007 calculateLoudness(bufferObj,"I"); 1016 calculateLoudness(bufferObj,"I");
1008 } 1017 }
1009 }; 1018 };
1010 this.progress = 0; 1019 this.progress = 0;
1011 this.progressCallback = function(event){ 1020 this.progressCallback = function(event){
1023 } 1032 }
1024 } 1033 }
1025 } 1034 }
1026 }; 1035 };
1027 this.xmlRequest.addEventListener("progress", this.progressCallback); 1036 this.xmlRequest.addEventListener("progress", this.progressCallback);
1037 this.status = 1;
1028 this.xmlRequest.send(); 1038 this.xmlRequest.send();
1029 }; 1039 };
1040
1041 this.registerAudioObject = function(audioObject)
1042 {
1043 // Called by an audioObject to register to the buffer for use
1044 // First check if already in the register pool
1045 for (var objects of this.users)
1046 {
1047 if (audioObject.id == objects.id){return 0;}
1048 }
1049 this.users.push(audioObject);
1050 if (this.status == 3)
1051 {
1052 // The buffer is already ready, trigger bufferLoaded
1053 audioObject.bufferLoaded(this);
1054 }
1055 }
1030 }; 1056 };
1031 1057
1032 this.play = function(id) { 1058 this.play = function(id) {
1033 // Start the timer and set the audioEngine state to playing (1) 1059 // Start the timer and set the audioEngine state to playing (1)
1034 if (this.status == 0 && this.loopPlayback) { 1060 if (this.status == 0 && this.loopPlayback) {
1112 } 1138 }
1113 if (buffer == null) 1139 if (buffer == null)
1114 { 1140 {
1115 console.log("[WARN]: Buffer was not loaded in pre-test! "+URL); 1141 console.log("[WARN]: Buffer was not loaded in pre-test! "+URL);
1116 buffer = new this.bufferObj(); 1142 buffer = new this.bufferObj();
1143 this.buffers.push(buffer);
1117 buffer.getMedia(URL); 1144 buffer.getMedia(URL);
1118 this.buffers.push(buffer);
1119 } 1145 }
1120 this.audioObjects[audioObjectId].specification = element; 1146 this.audioObjects[audioObjectId].specification = element;
1121 this.audioObjects[audioObjectId].url = URL; 1147 this.audioObjects[audioObjectId].url = URL;
1122 buffer.users.push(this.audioObjects[audioObjectId]);
1123 // Obtain store node 1148 // Obtain store node
1124 var aeNodes = this.pageStore.XMLDOM.getElementsByTagName('audioelement'); 1149 var aeNodes = this.pageStore.XMLDOM.getElementsByTagName('audioelement');
1125 for (var i=0; i<aeNodes.length; i++) 1150 for (var i=0; i<aeNodes.length; i++)
1126 { 1151 {
1127 if(aeNodes[i].id == element.id) 1152 if(aeNodes[i].id == element.id)
1128 { 1153 {
1129 this.audioObjects[audioObjectId].storeDOM = aeNodes[i]; 1154 this.audioObjects[audioObjectId].storeDOM = aeNodes[i];
1130 break; 1155 break;
1131 } 1156 }
1132 } 1157 }
1133 if (buffer.buffer.lufs != undefined) 1158 buffer.registerAudioObject(this.audioObjects[audioObjectId]);
1134 {
1135 this.audioObjects[audioObjectId].bufferLoaded(buffer);
1136 }
1137 return this.audioObjects[audioObjectId]; 1159 return this.audioObjects[audioObjectId];
1138 }; 1160 };
1139 1161
1140 this.newTestPage = function(store) { 1162 this.newTestPage = function(store) {
1141 this.pageStore = store; 1163 this.pageStore = store;
2349 this.trackComment = document.createElement('div'); 2371 this.trackComment = document.createElement('div');
2350 this.trackComment.className = 'comment-div'; 2372 this.trackComment.className = 'comment-div';
2351 this.trackComment.id = 'comment-div-'+audioObject.id; 2373 this.trackComment.id = 'comment-div-'+audioObject.id;
2352 // Create a string next to each comment asking for a comment 2374 // Create a string next to each comment asking for a comment
2353 this.trackString = document.createElement('span'); 2375 this.trackString = document.createElement('span');
2354 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id; 2376 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.interfaceDOM.getPresentedId();
2355 // Create the HTML5 comment box 'textarea' 2377 // Create the HTML5 comment box 'textarea'
2356 this.trackCommentBox = document.createElement('textarea'); 2378 this.trackCommentBox = document.createElement('textarea');
2357 this.trackCommentBox.rows = '4'; 2379 this.trackCommentBox.rows = '4';
2358 this.trackCommentBox.cols = '100'; 2380 this.trackCommentBox.cols = '100';
2359 this.trackCommentBox.name = 'trackComment'+audioObject.id; 2381 this.trackCommentBox.name = 'trackComment'+audioObject.id;