changeset 967:16852cf211eb

Fixed metric collection, listening time, for looping sources
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Wed, 27 May 2015 18:53:34 +0100
parents 4a5102ff2822
children be4abf039d42
files ape.js core.js
diffstat 2 files changed, 27 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ape.js	Wed May 27 18:10:56 2015 +0100
+++ b/ape.js	Wed May 27 18:53:34 2015 +0100
@@ -349,9 +349,9 @@
 			for (var i=0; i<this.audioObjects.length; i++)
 			{
 				if (id == i) {
-					this.audioObjects[i].outputGain.gain.value = 1.0;
+					this.audioObjects[i].loopStart();
 				} else {
-					this.audioObjects[i].outputGain.gain.value = 0.0;
+					this.audioObjects[i].loopStop();
 				}
 			}
 		};
--- a/core.js	Wed May 27 18:10:56 2015 +0100
+++ b/core.js	Wed May 27 18:53:34 2015 +0100
@@ -521,18 +521,30 @@
 	// When stopeed, the buffer node is deleted and recreated with the stored buffer.
 	this.buffer;
 	
+	this.loopStart = function() {
+		this.outputGain.gain.value = 1.0;
+		this.metric.startListening(audioEngineContext.timer.getTestTime());
+	}
+	
+	this.loopStop = function() {
+		if (this.outputGain.gain.value != 0.0) {
+			this.outputGain.gain.value = 0.0;
+			this.metric.stopListening(audioEngineContext.timer.getTestTime());
+		}
+	}
+	
 	this.play = function(startTime) {
 		this.bufferNode = audioContext.createBufferSource();
 		this.bufferNode.owner = this;
 		this.bufferNode.connect(this.outputGain);
 		this.bufferNode.buffer = this.buffer;
 		this.bufferNode.loop = audioEngineContext.loopPlayback;
+		this.bufferNode.onended = function() {
+				this.owner.metric.stopListening(audioEngineContext.timer.getTestTime());
+			};
 		if (this.bufferNode.loop == false) {
-			this.bufferNode.onended = function() {
-				this.owner.metric.listening(audioEngineContext.timer.getTestTime());
-			};
+			this.metric.startListening(audioEngineContext.timer.getTestTime());
 		}
-		this.metric.listening(audioEngineContext.timer.getTestTime());
 		this.bufferNode.start(startTime);
 		this.played = true;
 	};
@@ -542,7 +554,7 @@
 		{
 			this.bufferNode.stop(0);
 			this.bufferNode = undefined;
-			this.metric.listening(audioEngineContext.timer.getTestTime());
+			this.metric.stopListening(audioEngineContext.timer.getTestTime());
 		}
 	};
 
@@ -658,14 +670,20 @@
 		this.movementTracker[this.movementTracker.length] = [time, position];
 	};
 	
-	this.listening = function(time)
+	this.startListening = function(time)
 	{
 		if (this.listenHold == false)
 		{
 			this.wasListenedTo = true;
 			this.listenStart = time;
 			this.listenHold = true;
-		} else {
+		} 
+	}
+	
+	this.stopListening = function(time)
+	{
+		if (this.listenHold == true)
+		{
 			this.listenedTimer += (time - this.listenStart);
 			this.listenStart = 0;
 			this.listenHold = false;