comparison ape.js @ 681:ab56aa2fe064

Added Loop
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Sat, 18 Apr 2015 15:36:10 +0100
parents a79490e0fdc7
children 820805ac7326
comparison
equal deleted inserted replaced
680:d7bdfe8bf67e 681:ab56aa2fe064
318 if (Number(hostFs) != audioContext.sampleRate) { 318 if (Number(hostFs) != audioContext.sampleRate) {
319 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.'; 319 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
320 alert(errStr); 320 alert(errStr);
321 return; 321 return;
322 } 322 }
323 }
324
325 var loopPlayback = textXML.attributes['loop'];
326 if (loopPlayback != undefined)
327 {
328 loopPlayback = loopPlayback.value;
329 if (loopPlayback == 'true') {
330 loopPlayback = true;
331 } else {
332 loopPlayback = false;
333 }
334 } else {
335 loopPlayback = false;
336 }
337 audioEngineContext.loopPlayback = loopPlayback;
338
339 // Create AudioEngine bindings for playback
340 if (loopPlayback) {
341 audioEngineContext.play = function() {
342 // Send play command to all playback buffers for synchronised start
343 // Also start timer callbacks to detect if playback has finished
344 if (this.status == 0) {
345 this.timer.startTest();
346 // First get current clock
347 var timer = audioContext.currentTime;
348 // Add 3 seconds
349 timer += 3.0;
350 // Send play to all tracks
351 for (var i=0; i<this.audioObjects.length; i++)
352 {
353 this.audioObjects[i].play(timer);
354 }
355 this.status = 1;
356 }
357 };
358
359 audioEngineContext.stop = function() {
360 // Send stop and reset command to all playback buffers
361 if (this.status == 1) {
362 if (this.loopPlayback) {
363 for (var i=0; i<this.audioObjects.length; i++)
364 {
365 this.audioObjects[i].stop();
366 }
367 }
368 this.status = 0;
369 }
370 };
371
372 audioEngineContext.selectedTrack = function(id) {
373 for (var i=0; i<this.audioObjects.length; i++)
374 {
375 if (id == i) {
376 this.audioObjects[i].outputGain.gain.value = 1.0;
377 } else {
378 this.audioObjects[i].outputGain.gain.value = 0.0;
379 }
380 }
381 };
382 } else {
383 audioEngineContext.play = function() {
384 // Send play command to all playback buffers for synchronised start
385 // Also start timer callbacks to detect if playback has finished
386 if (this.status == 0) {
387 this.timer.startTest();
388 this.status = 1;
389 }
390 };
391
392 audioEngineContext.stop = function() {
393 // Send stop and reset command to all playback buffers
394 if (this.status == 1) {
395 if (this.loopPlayback) {
396 for (var i=0; i<this.audioObjects.length; i++)
397 {
398 this.audioObjects[i].stop();
399 }
400 }
401 this.status = 0;
402 }
403 };
404
405 audioEngineContext.selectedTrack = function(id) {
406 for (var i=0; i<this.audioObjects.length; i++)
407 {
408 if (id == i) {
409 this.audioObjects[i].outputGain.gain.value = 1.0;
410 this.audioObjects[i].play(audioContext.currentTime+0.01);
411 } else {
412 this.audioObjects[i].outputGain.gain.value = 0.0;
413 }
414 }
415 };
323 } 416 }
324 417
325 currentTestHolder = document.createElement('audioHolder'); 418 currentTestHolder = document.createElement('audioHolder');
326 currentTestHolder.id = textXML.id; 419 currentTestHolder.id = textXML.id;
327 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value; 420 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;