Mercurial > hg > webaudioevaluationtool
comparison core.js @ 2186:f5b0ff58b315
Implemented Calibration Module for level set testing.
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Tue, 29 Mar 2016 11:14:50 +0100 |
parents | e9212d745302 |
children | a918de498abc |
comparison
equal
deleted
inserted
replaced
2185:e9212d745302 | 2186:f5b0ff58b315 |
---|---|
540 this.popup.style.zIndex = 3; | 540 this.popup.style.zIndex = 3; |
541 this.popup.style.visibility = 'visible'; | 541 this.popup.style.visibility = 'visible'; |
542 var blank = document.getElementsByClassName('testHalt')[0]; | 542 var blank = document.getElementsByClassName('testHalt')[0]; |
543 blank.style.zIndex = 2; | 543 blank.style.zIndex = 2; |
544 blank.style.visibility = 'visible'; | 544 blank.style.visibility = 'visible'; |
545 this.popupResponse.style.left="0%"; | |
545 }; | 546 }; |
546 | 547 |
547 this.hidePopup = function(){ | 548 this.hidePopup = function(){ |
548 this.popup.style.zIndex = -1; | 549 this.popup.style.zIndex = -1; |
549 this.popup.style.visibility = 'hidden'; | 550 this.popup.style.visibility = 'hidden'; |
697 } | 698 } |
698 }; | 699 }; |
699 | 700 |
700 this.proceedClicked = function() { | 701 this.proceedClicked = function() { |
701 // Each time the popup button is clicked! | 702 // Each time the popup button is clicked! |
703 if (testState.stateIndex == 0 && specification.calibration) { | |
704 interfaceContext.calibrationModuleObject.collect(); | |
705 advanceState(); | |
706 return; | |
707 } | |
702 var node = this.popupOptions[this.currentIndex]; | 708 var node = this.popupOptions[this.currentIndex]; |
703 if (node.specification.type == 'question') { | 709 if (node.specification.type == 'question') { |
704 // Must extract the question data | 710 // Must extract the question data |
705 var textArea = $(popup.popupContent).find('textarea')[0]; | 711 var textArea = $(popup.popupContent).find('textarea')[0]; |
706 if (node.specification.mandatory == true && textArea.value.length == 0) { | 712 if (node.specification.mandatory == true && textArea.value.length == 0) { |
878 | 884 |
879 if (this.stateMap.length > 0) { | 885 if (this.stateMap.length > 0) { |
880 if(this.stateIndex != null) { | 886 if(this.stateIndex != null) { |
881 console.log('NOTE - State already initialise'); | 887 console.log('NOTE - State already initialise'); |
882 } | 888 } |
883 this.stateIndex = -1; | 889 this.stateIndex = -2; |
890 console.log('Starting test...'); | |
884 } else { | 891 } else { |
885 console.log('FATAL - StateMap not correctly constructed. EMPTY_STATE_MAP'); | 892 console.log('FATAL - StateMap not correctly constructed. EMPTY_STATE_MAP'); |
886 } | 893 } |
887 }; | 894 }; |
888 this.advanceState = function(){ | 895 this.advanceState = function(){ |
889 if (this.stateIndex == null) { | 896 if (this.stateIndex == null) { |
890 this.initialise(); | 897 this.initialise(); |
891 } | 898 } |
892 storage.update(); | 899 storage.update(); |
893 if (this.stateIndex == -1) { | 900 if (this.stateIndex == -2) { |
894 this.stateIndex++; | 901 this.stateIndex++; |
895 console.log('Starting test...'); | |
896 if (this.preTestSurvey != null) | 902 if (this.preTestSurvey != null) |
897 { | 903 { |
898 popup.initState(this.preTestSurvey,storage.globalPreTest); | 904 popup.initState(this.preTestSurvey,storage.globalPreTest); |
899 } else { | 905 } else { |
900 this.advanceState(); | 906 this.advanceState(); |
901 } | 907 } |
902 } else if (this.stateIndex == this.stateMap.length) | 908 } else if (this.stateIndex == -1) { |
909 this.stateIndex++; | |
910 if (specification.calibration) { | |
911 popup.showPopup(); | |
912 popup.popupTitle.textContent = "Calibration. Set the levels so all tones are of equal amplitude. Move your mouse over the sliders to hear the tones. The red slider is the reference tone"; | |
913 interfaceContext.calibrationModuleObject = new interfaceContext.calibrationModule(); | |
914 interfaceContext.calibrationModuleObject.build(popup.popupResponse); | |
915 popup.hidePreviousButton(); | |
916 } else { | |
917 this.advanceState(); | |
918 } | |
919 } | |
920 else if (this.stateIndex == this.stateMap.length) | |
903 { | 921 { |
904 // All test pages complete, post test | 922 // All test pages complete, post test |
905 console.log('Ending test ...'); | 923 console.log('Ending test ...'); |
906 this.stateIndex++; | 924 this.stateIndex++; |
907 if (this.postTestSurvey == null) { | 925 if (this.postTestSurvey == null) { |
913 { | 931 { |
914 createProjectSave(specification.projectReturn); | 932 createProjectSave(specification.projectReturn); |
915 } | 933 } |
916 else | 934 else |
917 { | 935 { |
936 popup.hidePopup(); | |
918 if (this.currentStateMap == null) | 937 if (this.currentStateMap == null) |
919 { | 938 { |
920 this.currentStateMap = this.stateMap[this.stateIndex]; | 939 this.currentStateMap = this.stateMap[this.stateIndex]; |
921 if (this.currentStateMap.randomiseOrder) | 940 if (this.currentStateMap.randomiseOrder) |
922 { | 941 { |
3064 | 3083 |
3065 this.object.appendChild(this.slider); | 3084 this.object.appendChild(this.slider); |
3066 this.object.appendChild(this.valueText); | 3085 this.object.appendChild(this.valueText); |
3067 } | 3086 } |
3068 | 3087 |
3088 this.calibrationModuleObject = null; | |
3069 this.calibrationModule = function() { | 3089 this.calibrationModule = function() { |
3070 // This creates an on-page calibration module | 3090 // This creates an on-page calibration module |
3071 this.storeDOM = storage.document.createElement("calibration"); | 3091 this.storeDOM = storage.document.createElement("calibration"); |
3072 storage.root.children[0].appendChild(this.storeDOM); | 3092 storage.root.appendChild(this.storeDOM); |
3073 // The calibration is a fixed state module | 3093 // The calibration is a fixed state module |
3074 this.calibrationNodes = []; | 3094 this.calibrationNodes = []; |
3075 var f0 = 62.5; | 3095 this.holder = null; |
3076 while(f0 < 20000) { | 3096 this.build = function(inject) { |
3077 var obj = { | 3097 var f0 = 62.5; |
3078 root: document.createElement("div"), | 3098 this.holder = document.createElement("div"); |
3079 input: document.createElement("input"), | 3099 this.holder.className = "calibration-holder"; |
3080 oscillator: audioContext.createOscillator(), | 3100 this.calibrationNodes = []; |
3081 gain: audioContext.createGain(), | 3101 while(f0 < 20000) { |
3082 parent: this, | 3102 var obj = { |
3083 handleEvent: function(event) { | 3103 root: document.createElement("div"), |
3084 gain.gain.value = Math.pow(10,input.value/20); | 3104 input: document.createElement("input"), |
3085 }, | 3105 oscillator: audioContext.createOscillator(), |
3086 disconnect: function() { | 3106 gain: audioContext.createGain(), |
3087 this.gain.disconnect(); | 3107 f: f0, |
3108 parent: this, | |
3109 handleEvent: function(event) { | |
3110 this.gain.gain.value = Math.pow(10,this.input.value/20); | |
3111 switch(event.type) { | |
3112 case "mouseenter": | |
3113 this.oscillator.start(0); | |
3114 break; | |
3115 case "mouseleave": | |
3116 this.oscillator.stop(0); | |
3117 this.oscillator = audioContext.createOscillator(); | |
3118 this.oscillator.connect(this.gain); | |
3119 this.oscillator.frequency.value = this.f; | |
3120 break; | |
3121 } | |
3122 }, | |
3123 disconnect: function() { | |
3124 this.gain.disconnect(); | |
3125 } | |
3088 } | 3126 } |
3127 obj.root.className = "calibration-slider"; | |
3128 obj.root.appendChild(obj.input); | |
3129 obj.oscillator.connect(obj.gain); | |
3130 obj.gain.connect(audioContext.destination); | |
3131 obj.gain.gain.value = Math.random()*2; | |
3132 obj.input.value = obj.gain.gain.value; | |
3133 obj.input.setAttribute('orient','vertical'); | |
3134 obj.input.type = "range"; | |
3135 obj.input.min = -6; | |
3136 obj.input.max = 6; | |
3137 obj.input.step = 0.25; | |
3138 if (f0 != 1000) { | |
3139 obj.input.value = (Math.random()*12)-6; | |
3140 } else { | |
3141 obj.input.value = 0; | |
3142 obj.root.style.backgroundColor="rgb(255,125,125)"; | |
3143 } | |
3144 obj.input.addEventListener("change",obj); | |
3145 obj.input.addEventListener("mouseenter",obj); | |
3146 obj.input.addEventListener("mouseleave",obj); | |
3147 obj.gain.gain.value = Math.pow(10,obj.input.value/20); | |
3148 obj.oscillator.frequency.value = f0; | |
3149 this.calibrationNodes.push(obj); | |
3150 this.holder.appendChild(obj.root); | |
3151 f0 *= 2; | |
3089 } | 3152 } |
3090 obj.root.appendChild(obj.input); | 3153 inject.appendChild(this.holder); |
3091 obj.oscillator.connect(obj.gain); | 3154 } |
3092 obj.gain.connect(audioContext.destination); | 3155 this.collect = function() { |
3093 obj.gain.gain.value = Math.random()*2; | 3156 for (var obj of this.calibrationNodes) { |
3094 obj.input.value = obj.gain.gain.value; | 3157 var node = storage.document.createElement("calibrationresult"); |
3095 obj.input.type = "range"; | 3158 node.setAttribute("frequency",obj.f); |
3096 obj.input.min = -60; | 3159 node.setAttribute("range-min",obj.input.min); |
3097 obj.input.max = 12; | 3160 node.setAttribute("range-max",obj.input.max); |
3098 obj.input.step = 0.25; | 3161 node.setAttribute("gain-db",20*Math.log10(obj.gain.gain.value)); |
3099 obj.oscillator.frequency.value = f0; | 3162 node.setAttribute("gain-lin",obj.gain.gain.value); |
3100 this.calibrationNodes.push(obj); | 3163 this.storeDOM.appendChild(node); |
3101 f0 *= 2; | 3164 } |
3102 } | 3165 } |
3103 } | 3166 } |
3104 | 3167 |
3105 | 3168 |
3106 // Global Checkers | 3169 // Global Checkers |