comparison core.js @ 1637:fb6354c5d3cf

Fixed metric collection, listening time, for looping sources
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Wed, 27 May 2015 18:53:34 +0100
parents 9c186f1b068c
children 917676cbdcc8
comparison
equal deleted inserted replaced
1636:9c186f1b068c 1637:fb6354c5d3cf
519 519
520 // the audiobuffer is not designed for multi-start playback 520 // the audiobuffer is not designed for multi-start playback
521 // When stopeed, the buffer node is deleted and recreated with the stored buffer. 521 // When stopeed, the buffer node is deleted and recreated with the stored buffer.
522 this.buffer; 522 this.buffer;
523 523
524 this.loopStart = function() {
525 this.outputGain.gain.value = 1.0;
526 this.metric.startListening(audioEngineContext.timer.getTestTime());
527 }
528
529 this.loopStop = function() {
530 if (this.outputGain.gain.value != 0.0) {
531 this.outputGain.gain.value = 0.0;
532 this.metric.stopListening(audioEngineContext.timer.getTestTime());
533 }
534 }
535
524 this.play = function(startTime) { 536 this.play = function(startTime) {
525 this.bufferNode = audioContext.createBufferSource(); 537 this.bufferNode = audioContext.createBufferSource();
526 this.bufferNode.owner = this; 538 this.bufferNode.owner = this;
527 this.bufferNode.connect(this.outputGain); 539 this.bufferNode.connect(this.outputGain);
528 this.bufferNode.buffer = this.buffer; 540 this.bufferNode.buffer = this.buffer;
529 this.bufferNode.loop = audioEngineContext.loopPlayback; 541 this.bufferNode.loop = audioEngineContext.loopPlayback;
542 this.bufferNode.onended = function() {
543 this.owner.metric.stopListening(audioEngineContext.timer.getTestTime());
544 };
530 if (this.bufferNode.loop == false) { 545 if (this.bufferNode.loop == false) {
531 this.bufferNode.onended = function() { 546 this.metric.startListening(audioEngineContext.timer.getTestTime());
532 this.owner.metric.listening(audioEngineContext.timer.getTestTime()); 547 }
533 };
534 }
535 this.metric.listening(audioEngineContext.timer.getTestTime());
536 this.bufferNode.start(startTime); 548 this.bufferNode.start(startTime);
537 this.played = true; 549 this.played = true;
538 }; 550 };
539 551
540 this.stop = function() { 552 this.stop = function() {
541 if (this.bufferNode != undefined) 553 if (this.bufferNode != undefined)
542 { 554 {
543 this.bufferNode.stop(0); 555 this.bufferNode.stop(0);
544 this.bufferNode = undefined; 556 this.bufferNode = undefined;
545 this.metric.listening(audioEngineContext.timer.getTestTime()); 557 this.metric.stopListening(audioEngineContext.timer.getTestTime());
546 } 558 }
547 }; 559 };
548 560
549 this.constructTrack = function(url) { 561 this.constructTrack = function(url) {
550 var request = new XMLHttpRequest(); 562 var request = new XMLHttpRequest();
656 { 668 {
657 this.wasMoved = true; 669 this.wasMoved = true;
658 this.movementTracker[this.movementTracker.length] = [time, position]; 670 this.movementTracker[this.movementTracker.length] = [time, position];
659 }; 671 };
660 672
661 this.listening = function(time) 673 this.startListening = function(time)
662 { 674 {
663 if (this.listenHold == false) 675 if (this.listenHold == false)
664 { 676 {
665 this.wasListenedTo = true; 677 this.wasListenedTo = true;
666 this.listenStart = time; 678 this.listenStart = time;
667 this.listenHold = true; 679 this.listenHold = true;
668 } else { 680 }
681 }
682
683 this.stopListening = function(time)
684 {
685 if (this.listenHold == true)
686 {
669 this.listenedTimer += (time - this.listenStart); 687 this.listenedTimer += (time - this.listenStart);
670 this.listenStart = 0; 688 this.listenStart = 0;
671 this.listenHold = false; 689 this.listenHold = false;
672 } 690 }
673 }; 691 };