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: samer@0: import samer.maths.*; samer@0: import samer.core.*; samer@0: import samer.core.types.*; samer@0: import samer.tools.*; samer@0: import samer.functions.*; samer@0: import javax.sound.sampled.*; samer@0: samer@0: /** samer@0: * Overlap and add input vectors into a buffer. At each iteration, samer@0: * the buffer is shifted by and the new data is added in. samer@0: */ samer@0: samer@0: public class OverlapAndAdd extends NamedTask samer@0: { samer@0: VVector vec; // input samer@0: VVector out; samer@0: int N, hop; // frame size, hop size samer@0: double[] x, y; // input and output arrays samer@0: double[] H; // array containing window, eg Hanning samer@0: samer@0: /** Create overlap and add buffer for input vector with given hop size */ samer@0: samer@0: public OverlapAndAdd(VVector input, int hop) throws Exception samer@0: { samer@0: super("overlap"); samer@0: vec = input; N = vec.size(); samer@0: out = new VVector("output",N); samer@0: H=new double[N]; samer@0: x=vec.array(); samer@0: y=out.array(); samer@0: this.hop=hop; samer@0: } samer@0: samer@0: /** Sets windowing array to samples from the given function. samer@0: * The domain [0,1) is mapped on to the array indices 0:N-1 samer@0: */ samer@0: samer@0: public void setWindow(Function fn) { samer@0: for (int i=0; i