annotate src/samer/units/LineIn.java @ 8:5e3cbbf173aa tip

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