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