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

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
3 * All rights reserved.
4 *
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
6 * without even the implied warranty of MERCHANTABILITY or
7 * FITNESS FOR A PARTICULAR PURPOSE.
8 */
9
10 package samer.units;
11 import samer.maths.*;
12 import samer.core.*;
13 import samer.audio.*;
14 import samer.tools.*;
15
16 /**
17 Manages sliding window audio input.
18 Acts as a sort of envelope class for audio input, containing the source,
19 the destination vector, and the associated reader task.
20 */
21
22 public class LineIn implements Task
23 {
24 private AudioSource source;
25 private Task reader=new NullTask();
26 private VVector B;
27 private int N, m;
28 private double[] buf;
29
30 public LineIn(AudioSource src, int N, int m) throws Exception {
31 Shell.print("LineIn: size="+N+", step="+m);
32
33 this.N=N; this.m=m; source=src;
34 B = new VVector(new Node("waveform"),N);
35 buf=B.array(); setStep(m);
36 }
37
38 public Vec output() { return B; }
39 public int getStep() { return m; }
40 public void setStep(int m) {
41 reader.dispose(); this.m=m;
42 reader=source.reader(buf,N-m,m);
43 }
44
45 public AudioSource getSource() { return source; }
46 public AudioSource setSource(AudioSource s) {
47 AudioSource old=source; source=s; setStep(m);
48 return old;
49 }
50
51 public void dispose() { reader.dispose(); source.dispose(); B.dispose(); }
52 public void starting() { reader.starting(); }
53 public void stopping() { reader.stopping(); }
54 public void run() throws Exception {
55 if (N>m) System.arraycopy(buf,m,buf,0,N-m);
56 reader.run(); B.changed();
57 }
58
59 public String toString() { return "LineIn("+N+","+m+")->"+B; }
60 }
61