Mercurial > hg > jslab
view 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 |
line wrap: on
line source
/* * 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; } }