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