Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1342:397e96ee781a
Better loudness calculation. Buffer ready not called until after loudness calculation to avoid NaNs on gain. <survey> nodes do not need to be present, no survey then no node. Added example boilerplate interface with all required functions and brief descriptions.
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Wed, 13 Jan 2016 10:31:31 +0000 |
parents | bbb6462cf446 |
children | c1c5cb020fd3 |
comparison
equal
deleted
inserted
replaced
1341:bbb6462cf446 | 1342:397e96ee781a |
---|---|
728 this.advanceState = function(){ | 728 this.advanceState = function(){ |
729 if (this.stateIndex == null) { | 729 if (this.stateIndex == null) { |
730 this.initialise(); | 730 this.initialise(); |
731 } | 731 } |
732 if (this.stateIndex == -1) { | 732 if (this.stateIndex == -1) { |
733 this.stateIndex++; | |
733 console.log('Starting test...'); | 734 console.log('Starting test...'); |
734 if (this.preTestSurvey != null) | 735 if (this.preTestSurvey != null) |
735 { | 736 { |
736 popup.initState(this.preTestSurvey,storage.globalPreTest); | 737 popup.initState(this.preTestSurvey,storage.globalPreTest); |
737 } | 738 } else { |
738 this.stateIndex++; | 739 this.advanceState(); |
740 } | |
739 } else if (this.stateIndex == this.stateMap.length) | 741 } else if (this.stateIndex == this.stateMap.length) |
740 { | 742 { |
741 // All test pages complete, post test | 743 // All test pages complete, post test |
742 console.log('Ending test ...'); | 744 console.log('Ending test ...'); |
743 this.stateIndex++; | 745 this.stateIndex++; |
858 this.url = null; | 860 this.url = null; |
859 this.buffer = null; | 861 this.buffer = null; |
860 this.xmlRequest = new XMLHttpRequest(); | 862 this.xmlRequest = new XMLHttpRequest(); |
861 this.xmlRequest.parent = this; | 863 this.xmlRequest.parent = this; |
862 this.users = []; | 864 this.users = []; |
865 this.ready = function() | |
866 { | |
867 for (var i=0; i<this.users.length; i++) | |
868 { | |
869 this.users[i].state = 1; | |
870 if (this.users[i].interfaceDOM != null) | |
871 { | |
872 this.users[i].bufferLoaded(this); | |
873 } | |
874 } | |
875 }; | |
863 this.getMedia = function(url) { | 876 this.getMedia = function(url) { |
864 this.url = url; | 877 this.url = url; |
865 this.xmlRequest.open('GET',this.url,true); | 878 this.xmlRequest.open('GET',this.url,true); |
866 this.xmlRequest.responseType = 'arraybuffer'; | 879 this.xmlRequest.responseType = 'arraybuffer'; |
867 | 880 |
869 | 882 |
870 // Create callback to decode the data asynchronously | 883 // Create callback to decode the data asynchronously |
871 this.xmlRequest.onloadend = function() { | 884 this.xmlRequest.onloadend = function() { |
872 audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) { | 885 audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) { |
873 bufferObj.buffer = decodedData; | 886 bufferObj.buffer = decodedData; |
874 for (var i=0; i<bufferObj.users.length; i++) | 887 calculateLoudness(bufferObj,"I"); |
875 { | 888 |
876 bufferObj.users[i].state = 1; | |
877 if (bufferObj.users[i].interfaceDOM != null) | |
878 { | |
879 bufferObj.users[i].bufferLoaded(bufferObj); | |
880 } | |
881 } | |
882 calculateLoudness(bufferObj.buffer,"I"); | |
883 }, function(){ | 889 }, function(){ |
884 // Should only be called if there was an error, but sometimes gets called continuously | 890 // Should only be called if there was an error, but sometimes gets called continuously |
885 // Check here if the error is genuine | 891 // Check here if the error is genuine |
886 if (bufferObj.buffer == undefined) { | 892 if (bufferObj.buffer == undefined) { |
887 // Genuine error | 893 // Genuine error |
2825 this.root = this.document.children[0]; | 2831 this.root = this.document.children[0]; |
2826 this.state = 0; | 2832 this.state = 0; |
2827 | 2833 |
2828 this.initialise = function() | 2834 this.initialise = function() |
2829 { | 2835 { |
2830 this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest); | 2836 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);} |
2831 this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest); | 2837 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);} |
2832 }; | 2838 }; |
2833 | 2839 |
2834 this.createTestPageStore = function(specification) | 2840 this.createTestPageStore = function(specification) |
2835 { | 2841 { |
2836 var store = new this.pageNode(this,specification); | 2842 var store = new this.pageNode(this,specification); |
2895 this.specification = specification; | 2901 this.specification = specification; |
2896 this.parent = parent; | 2902 this.parent = parent; |
2897 this.XMLDOM = this.parent.document.createElement('page'); | 2903 this.XMLDOM = this.parent.document.createElement('page'); |
2898 this.XMLDOM.setAttribute('id',specification.id); | 2904 this.XMLDOM.setAttribute('id',specification.id); |
2899 this.XMLDOM.setAttribute('presentedId',specification.presentedId); | 2905 this.XMLDOM.setAttribute('presentedId',specification.presentedId); |
2900 this.preTest = new this.parent.surveyNode(parent,this.XMLDOM,specification.preTest); | 2906 if (specification.preTest != undefined){this.preTest = new this.surveyNode(this,this.root,this.specification.preTest);} |
2901 this.postTest = new this.parent.surveyNode(parent,this.XMLDOM,specification.postTest); | 2907 if (specification.postTest != undefined){this.postTest = new this.surveyNode(this,this.root,this.specification.postTest);} |
2902 | 2908 |
2903 // Add any page metrics | 2909 // Add any page metrics |
2904 var page_metric = this.parent.document.createElement('metric'); | 2910 var page_metric = this.parent.document.createElement('metric'); |
2905 this.XMLDOM.appendChild(page_metric); | 2911 this.XMLDOM.appendChild(page_metric); |
2906 | 2912 |