Mercurial > hg > jslab
view src/samer/units/Trigger.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.tools.*; import samer.maths.*; import samer.core.types.*; /** Generates a 1 for each element that rises above threshold, and a -1 for when it drops back below. Can be used to drive MidiSynth, which interprets +1 as note-on and -1 as note-off. */ public class Trigger extends AnonymousTask { boolean [] states; VDouble thresh; VVector output; double[] in,out; int n; public Trigger(VVector input, double th) { n = input.size(); states = new boolean[n]; in=input.array(); thresh=new VDouble("thresh",th); output=new VVector("trigger",n); out=output.array(); } public VVector output() { return output; } public void run() { double th=thresh.value; for (int i=0; i<n; i++) { if (in[i]>th) { if (!states[i]) { out[i]=in[i]; states[i]=true; } else out[i]=0; } else { if (states[i]) { out[i]=-1; states[i]=false; } else out[i]=0; } } output.changed(); } }