annotate src/samer/units/OnsetMap.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) 2001, 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
samer@0 12 import samer.core.*;
samer@0 13 import samer.core.types.*;
samer@0 14 import samer.core.util.*;
samer@0 15 import samer.maths.*;
samer@0 16 import samer.tools.*;
samer@0 17 import java.util.*;
samer@0 18
samer@0 19 public class OnsetMap extends Viewable implements Task, Observer {
samer@0 20 VInteger I1, I2;
samer@0 21 VMap vmap;
samer@0 22 Matrix bins;
samer@0 23 IMap map;
samer@0 24 int i1, i2;
samer@0 25 double[] xArray;
samer@0 26 double[][] binArray;
samer@0 27 VDouble L;
samer@0 28 boolean ison;
samer@0 29 int vel;
samer@0 30 VDouble thresh;
samer@0 31
samer@0 32 public OnsetMap(Vec x)
samer@0 33 {
samer@0 34 super("onsetmap");
samer@0 35
samer@0 36 xArray=x.array();
samer@0 37 if (xArray==null) throw new Error("vec array not accessible");
samer@0 38
samer@0 39 Shell.push(node);
samer@0 40
samer@0 41 int M=Shell.getInt("bins",32);
samer@0 42 int N=x.size();
samer@0 43
samer@0 44 I1=new VInteger("i1",1,0);
samer@0 45 I2=new VInteger("i2",2,0);
samer@0 46 I1.setRange(0,N-1);
samer@0 47 I2.setRange(0,N-1);
samer@0 48
samer@0 49 vmap=new VMap(new LinearMap(-1,1,M));
samer@0 50 map=vmap.getMap();
samer@0 51
samer@0 52 bins = new Matrix("bins",M,M,0); // no register
samer@0 53 L = new VDouble("velocity");
samer@0 54 thresh = new VDouble("threshold",1,0);
samer@0 55
samer@0 56 Shell.pop();
samer@0 57
samer@0 58 setAgent(vmap);
samer@0 59 binArray=bins.getArray();
samer@0 60 I1.addObserver(this);
samer@0 61 I2.addObserver(this);
samer@0 62 vmap.addObserver(this);
samer@0 63 Shell.registerViewable(this);
samer@0 64 }
samer@0 65
samer@0 66 public Matrix getBinMatrix() { return bins; }
samer@0 67 public VDouble getVelocitySignal() { return L; }
samer@0 68 public boolean isOnset() { return ison; }
samer@0 69 public int getVelocity() { return vel; }
samer@0 70
samer@0 71 public void starting() {}
samer@0 72 public void stopping() {}
samer@0 73 public void run() {
samer@0 74 int j=map.clipInt(xArray[i1]);
samer@0 75 int k=map.clipInt(xArray[i2]);
samer@0 76 if (binArray[j][k]>thresh.value) {
samer@0 77 ison=true;
samer@0 78 vel=(int)(L.value=binArray[j][k]);
samer@0 79 } else {
samer@0 80 ison=false;
samer@0 81 L.value=0;
samer@0 82 }
samer@0 83 L.changed();
samer@0 84 }
samer@0 85
samer@0 86 public void dispose() {
samer@0 87 I1.dispose();
samer@0 88 I2.dispose();
samer@0 89 bins.dispose();
samer@0 90 }
samer@0 91
samer@0 92 public void update(Observable o, Object a) {
samer@0 93 i1=I1.value;
samer@0 94 i2=I2.value;
samer@0 95 if (a==VMap.NEW_MAP) map=vmap.getMap();
samer@0 96 }
samer@0 97
samer@0 98 public Viewer getViewer()
samer@0 99 {
samer@0 100 DefaultViewer vwr=new DefaultViewer(this);
samer@0 101
samer@0 102 vwr.add(I1);
samer@0 103 vwr.add(I2);
samer@0 104 vwr.add(bins.viewable());
samer@0 105 vwr.add(L);
samer@0 106 vwr.add(thresh);
samer@0 107
samer@0 108 return vwr;
samer@0 109 }
samer@0 110 }
samer@0 111
samer@0 112