Mercurial > hg > webaudioevaluationtool
comparison core.js @ 1620:da84079192c6
Fix Bug #1241 and #1213: Added checks each time new test page is loaded that all audioObjects have decoded. Writes to browser console WAIT and does not issue any play command if any audioObjects not ready.
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Mon, 25 May 2015 11:14:12 +0100 |
parents | ed5b4a9b266a |
children | 55bf2500f278 |
comparison
equal
deleted
inserted
replaced
1619:42bfe112f6ed | 1620:da84079192c6 |
---|---|
103 this.fooGain = audioContext.createGain(); | 103 this.fooGain = audioContext.createGain(); |
104 this.fooGain.gain = 0; | 104 this.fooGain.gain = 0; |
105 | 105 |
106 // Use this to detect playback state: 0 - stopped, 1 - playing | 106 // Use this to detect playback state: 0 - stopped, 1 - playing |
107 this.status = 0; | 107 this.status = 0; |
108 this.audioObjectsReady = false; | |
108 | 109 |
109 // Connect both gains to output | 110 // Connect both gains to output |
110 this.outputGain.connect(audioContext.destination); | 111 this.outputGain.connect(audioContext.destination); |
111 this.fooGain.connect(audioContext.destination); | 112 this.fooGain.connect(audioContext.destination); |
112 | 113 |
118 this.loopPlayback = false; | 119 this.loopPlayback = false; |
119 | 120 |
120 // Create store for new audioObjects | 121 // Create store for new audioObjects |
121 this.audioObjects = []; | 122 this.audioObjects = []; |
122 | 123 |
123 this.play = function(){}; | 124 this.play = function() { |
124 | 125 // Start the timer and set the audioEngine state to playing (1) |
125 this.stop = function(){}; | 126 if (this.status == 0) { |
127 // Check if all audioObjects are ready | |
128 if (this.audioObjectsReady == false) { | |
129 this.audioObjectsReady = this.checkAllReady(); | |
130 } | |
131 if (this.audioObjectsReady == true) { | |
132 this.timer.startTest(); | |
133 this.status = 1; | |
134 } | |
135 } | |
136 }; | |
137 | |
138 this.stop = function() { | |
139 // Send stop and reset command to all playback buffers and set audioEngine state to stopped (1) | |
140 if (this.status == 1) { | |
141 for (var i=0; i<this.audioObjects.length; i++) | |
142 { | |
143 this.audioObjects[i].stop(); | |
144 } | |
145 this.status = 0; | |
146 } | |
147 }; | |
126 | 148 |
127 | 149 |
128 this.newTrack = function(url) { | 150 this.newTrack = function(url) { |
129 // Pull data from given URL into new audio buffer | 151 // Pull data from given URL into new audio buffer |
130 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin' | 152 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin' |
133 audioObjectId = this.audioObjects.length; | 155 audioObjectId = this.audioObjects.length; |
134 this.audioObjects[audioObjectId] = new audioObject(audioObjectId); | 156 this.audioObjects[audioObjectId] = new audioObject(audioObjectId); |
135 | 157 |
136 // AudioObject will get track itself. | 158 // AudioObject will get track itself. |
137 this.audioObjects[audioObjectId].constructTrack(url); | 159 this.audioObjects[audioObjectId].constructTrack(url); |
160 }; | |
161 | |
162 this.newTestPage = function() { | |
163 this.state = 0; | |
164 this.audioObjectsReady = false; | |
165 this.metric.reset(); | |
166 this.audioObjects = []; | |
138 }; | 167 }; |
139 | 168 |
140 this.checkAllPlayed = function() { | 169 this.checkAllPlayed = function() { |
141 arr = []; | 170 arr = []; |
142 for (var id=0; id<this.audioObjects.length; id++) { | 171 for (var id=0; id<this.audioObjects.length; id++) { |
143 if (this.audioObjects[id].played == false) { | 172 if (this.audioObjects[id].played == false) { |
144 arr.push(this.audioObjects[id].id); | 173 arr.push(this.audioObjects[id].id); |
145 } | 174 } |
146 } | 175 } |
147 return arr; | 176 return arr; |
177 }; | |
178 | |
179 this.checkAllReady = function() { | |
180 var ready = true; | |
181 for (var i=0; i<this.audioObjects.length; i++) { | |
182 if (this.audioObjects[i].state == 0) { | |
183 // Track not ready | |
184 console.log('WAIT -- audioObject '+i+' not ready yet!'); | |
185 ready = false; | |
186 }; | |
187 } | |
188 return ready; | |
148 }; | 189 }; |
149 | 190 |
150 } | 191 } |
151 | 192 |
152 function audioObject(id) { | 193 function audioObject(id) { |
180 this.bufferNode.buffer = this.buffer; | 221 this.bufferNode.buffer = this.buffer; |
181 this.bufferNode.loop = audioEngineContext.loopPlayback; | 222 this.bufferNode.loop = audioEngineContext.loopPlayback; |
182 if (this.bufferNode.loop == false) { | 223 if (this.bufferNode.loop == false) { |
183 this.bufferNode.onended = function() { | 224 this.bufferNode.onended = function() { |
184 this.owner.metric.listening(audioEngineContext.timer.getTestTime()); | 225 this.owner.metric.listening(audioEngineContext.timer.getTestTime()); |
185 } | 226 }; |
186 } | 227 } |
187 this.metric.listening(audioEngineContext.timer.getTestTime()); | 228 this.metric.listening(audioEngineContext.timer.getTestTime()); |
188 this.bufferNode.start(startTime); | 229 this.bufferNode.start(startTime); |
189 this.played = true; | 230 this.played = true; |
190 }; | 231 }; |
273 /* Used by audioEngine to link to audioObjects to minimise the timer call timers; | 314 /* Used by audioEngine to link to audioObjects to minimise the timer call timers; |
274 */ | 315 */ |
275 this.engine = engine; | 316 this.engine = engine; |
276 this.lastClicked = -1; | 317 this.lastClicked = -1; |
277 this.data = -1; | 318 this.data = -1; |
319 this.reset = function() { | |
320 this.lastClicked = -1; | |
321 this.data = -1; | |
322 }; | |
278 this.initialiseTest = function(){}; | 323 this.initialiseTest = function(){}; |
279 } | 324 } |
280 | 325 |
281 function metricTracker() | 326 function metricTracker() |
282 { | 327 { |