Mercurial > hg > webaudioevaluationtool
comparison js/core.js @ 3102:972b55d81c1b
#171 Completed
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Thu, 18 Jan 2018 10:12:12 +0000 |
parents | cd34732a2e39 |
children | 7820ce4a96c0 |
comparison
equal
deleted
inserted
replaced
3101:cd34732a2e39 | 3102:972b55d81c1b |
---|---|
3231 storageRoot = storage.document.createElement("calibration"); | 3231 storageRoot = storage.document.createElement("calibration"); |
3232 storage.root.appendChild(storageRoot); | 3232 storage.root.appendChild(storageRoot); |
3233 } | 3233 } |
3234 return storageRoot; | 3234 return storageRoot; |
3235 } | 3235 } |
3236 var calibrationObject = undefined, | 3236 var calibrationObject, |
3237 _checkedFrequency = false, | 3237 _checkedFrequency = false, |
3238 _checkedChannels = false; | 3238 _checkedChannels = false; |
3239 | 3239 |
3240 // Define the checkFrequencies test! | 3240 // Define the checkFrequencies test! |
3241 var checkFrequencyUnit = function (htmlRoot, storageRoot) { | 3241 var checkFrequencyUnit = function (htmlRoot, storageRoot) { |
3242 | 3242 |
3243 function createFrequencyElement(frequency) { | 3243 function createFrequencyElement(frequency) { |
3244 return (function (frequency) { | 3244 return (function (frequency) { |
3245 var hold = document.createElement("div"); | |
3246 hold.className = "calibration-slider"; | |
3245 var range = document.createElement("input"); | 3247 var range = document.createElement("input"); |
3246 range.type = "range"; | 3248 range.type = "range"; |
3247 range.min = "-24"; | 3249 range.min = "-24"; |
3248 range.max = "24"; | 3250 range.max = "24"; |
3249 range.step = "0.5"; | 3251 range.step = "0.5"; |
3250 range.setAttribute("orient", "vertical"); | 3252 range.setAttribute("orient", "vertical"); |
3251 range.value = (Math.random() - 0.5) * 24; | 3253 range.value = (Math.random() - 0.5) * 24; |
3252 range.setAttribute("frequency", frequency); | 3254 range.setAttribute("frequency", frequency); |
3253 htmlRoot.append(range); | 3255 hold.appendChild(range); |
3256 htmlRoot.appendChild(hold); | |
3254 | 3257 |
3255 var gain = audioContext.createGain(); | 3258 var gain = audioContext.createGain(); |
3256 gain.connect(outputGain); | 3259 gain.connect(outputGain); |
3257 gain.gain.value = Math.pow(10, Number(range.value) / 20.0); | 3260 gain.gain.value = Math.pow(10, Number(range.value) / 20.0); |
3258 var osc = undefined; | 3261 var osc; |
3259 | 3262 |
3260 var store = storage.document.createElement("response"); | 3263 var store = storage.document.createElement("response"); |
3261 store.setAttribute("frequency", frequency); | 3264 store.setAttribute("frequency", frequency); |
3262 storageHook.appendChild(store); | 3265 storageHook.appendChild(store); |
3263 var interface = {}; | 3266 var interface = {}; |
3293 var frequencies = [100, 200, 400, 800, 1200, 1600, 2000, 4000, 8000, 12000]; | 3296 var frequencies = [100, 200, 400, 800, 1200, 1600, 2000, 4000, 8000, 12000]; |
3294 var outputGain = audioContext.createGain(); | 3297 var outputGain = audioContext.createGain(); |
3295 outputGain.gain.value = 0.25; | 3298 outputGain.gain.value = 0.25; |
3296 outputGain.connect(audioContext.destination); | 3299 outputGain.connect(audioContext.destination); |
3297 this.sliders = frequencies.map(createFrequencyElement); | 3300 this.sliders = frequencies.map(createFrequencyElement); |
3298 } | 3301 }; |
3299 | 3302 |
3300 var checkChannelsUnit = function (htmlRoot, storageRoot) { | 3303 var checkChannelsUnit = function (htmlRoot, storageRoot) { |
3301 | 3304 |
3302 function onclick(ev) { | 3305 function onclick(ev) { |
3303 var storageHook = storage.document.querySelector("calibration").querySelector("channels"); | 3306 var storageHook = storage.document.querySelector("calibration").querySelector("channels"); |
3323 var play = document.createElement("button"); | 3326 var play = document.createElement("button"); |
3324 play.textContent = "Play Audio"; | 3327 play.textContent = "Play Audio"; |
3325 play.onclick = function () { | 3328 play.onclick = function () { |
3326 osc.start(); | 3329 osc.start(); |
3327 play.disabled = true; | 3330 play.disabled = true; |
3328 } | 3331 }; |
3332 play.className = "calibration-button"; | |
3329 htmlRoot.appendChild(play); | 3333 htmlRoot.appendChild(play); |
3330 var choiceHolder = document.createElement("div"); | 3334 var choiceHolder = document.createElement("div"); |
3331 var leftButton = document.createElement("button"); | 3335 var leftButton = document.createElement("button"); |
3332 leftButton.textContent = "Left"; | 3336 leftButton.textContent = "Left"; |
3333 leftButton.value = "-1"; | 3337 leftButton.value = "-1"; |
3338 leftButton.className = "calibration-button"; | |
3334 var centerButton = document.createElement("button"); | 3339 var centerButton = document.createElement("button"); |
3335 centerButton.textContent = "Middle"; | 3340 centerButton.textContent = "Middle"; |
3336 centerButton.value = "0"; | 3341 centerButton.value = "0"; |
3342 centerButton.className = "calibration-button"; | |
3337 var rightButton = document.createElement("button"); | 3343 var rightButton = document.createElement("button"); |
3338 rightButton.textContent = "Right"; | 3344 rightButton.textContent = "Right"; |
3339 rightButton.value = "1"; | 3345 rightButton.value = "1"; |
3346 rightButton.className = "calibration-button"; | |
3340 choiceHolder.appendChild(leftButton); | 3347 choiceHolder.appendChild(leftButton); |
3341 choiceHolder.appendChild(centerButton); | 3348 choiceHolder.appendChild(centerButton); |
3342 choiceHolder.appendChild(rightButton); | 3349 choiceHolder.appendChild(rightButton); |
3343 htmlRoot.appendChild(choiceHolder); | 3350 htmlRoot.appendChild(choiceHolder); |
3344 leftButton.addEventListener("click", onclick); | 3351 leftButton.addEventListener("click", onclick); |
3360 gainL.gain.value = 0.25; | 3367 gainL.gain.value = 0.25; |
3361 gainR.gain.value = 0.0; | 3368 gainR.gain.value = 0.0; |
3362 storageHook.setAttribute("presented", pan); | 3369 storageHook.setAttribute("presented", pan); |
3363 storageHook.setAttribute("presentedText", "Left"); | 3370 storageHook.setAttribute("presentedText", "Left"); |
3364 } | 3371 } |
3365 } | 3372 }; |
3366 | 3373 |
3367 var interface = {}; | 3374 var interface = {}; |
3368 Object.defineProperties(interface, { | 3375 Object.defineProperties(interface, { |
3369 "calibrationObject": { | 3376 "calibrationObject": { |
3370 "get": function () { | 3377 "get": function () { |
3371 return calibrationObject | 3378 return calibrationObject; |
3372 }, | 3379 }, |
3373 "set": readonly | 3380 "set": readonly |
3374 }, | 3381 }, |
3375 "checkFrequencies": { | 3382 "checkFrequencies": { |
3376 "get": function () { | 3383 "get": function () { |
3402 htmlRoot.innerHTML = ""; | 3409 htmlRoot.innerHTML = ""; |
3403 calibrationObject = new checkChannelsUnit(htmlRoot, getStorageRoot()); | 3410 calibrationObject = new checkChannelsUnit(htmlRoot, getStorageRoot()); |
3404 _checkedChannels = true; | 3411 _checkedChannels = true; |
3405 } | 3412 } |
3406 } | 3413 } |
3407 }) | 3414 }); |
3408 return interface; | 3415 return interface; |
3409 })(); | 3416 })(); |
3410 | 3417 |
3411 | 3418 |
3412 // Global Checkers | 3419 // Global Checkers |