diff src/samer/units/LineIn.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/samer/units/LineIn.java	Tue Jan 17 17:50:20 2012 +0000
@@ -0,0 +1,61 @@
+/*
+ *	Copyright (c) 2000, Samer Abdallah, King's College London.
+ *	All rights reserved.
+ *
+ *	This software is provided AS iS and WITHOUT ANY WARRANTY;
+ *	without even the implied warranty of MERCHANTABILITY or
+ *	FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+package samer.units;
+import samer.maths.*;
+import samer.core.*;
+import samer.audio.*;
+import samer.tools.*;
+
+/**
+	Manages sliding window audio input.
+	Acts as a sort of envelope class for audio input, containing the source,
+	the destination vector, and the associated reader task.
+*/
+
+public class LineIn implements Task
+{
+	private	AudioSource		source;
+	private	Task						reader=new NullTask();
+	private	VVector				B;
+	private	int							N, m;
+	private	double[]				buf;
+
+	public LineIn(AudioSource src, int N, int m) throws Exception {
+		Shell.print("LineIn: size="+N+", step="+m);
+
+		this.N=N; this.m=m; source=src;
+		B = new VVector(new Node("waveform"),N);
+		buf=B.array(); setStep(m);
+	}
+
+	public Vec output() { return B; }
+	public int getStep() { return m; }
+	public void setStep(int m) {
+		reader.dispose(); this.m=m;
+		reader=source.reader(buf,N-m,m);
+  	}
+
+	public AudioSource getSource() { return source; }
+	public AudioSource setSource(AudioSource s) {
+		AudioSource old=source; source=s; setStep(m);
+		return old;
+	}
+
+	public void dispose() { reader.dispose(); source.dispose(); B.dispose(); }
+	public void starting() { reader.starting(); }
+	public void stopping() { reader.stopping(); }
+	public void run() throws Exception {
+		if (N>m) System.arraycopy(buf,m,buf,0,N-m);
+		reader.run(); B.changed();
+	}
+
+	public String toString() { return "LineIn("+N+","+m+")->"+B; }
+}
+