Mercurial > hg > jslab
view src/samer/units/Oscillator.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
package samer.units; import samer.core.*; import samer.core.types.*; import samer.maths.*; import java.util.*; public class Oscillator implements Generator { double c, s; double x1, x2; public Oscillator(double f) { setFrequency(f); reset(); } public DoubleModel getFrequencyModel() { return new DoubleModel() { public void set(double f) { setFrequency(f); } public double get() { return Math.atan(s/c); } }; } public void reset() { x1=1; x2=0; } public void setFrequency(double f) { s=Math.sin(f); c=Math.cos(f); } public void dispose() {} public double next() { double y1 = x1*c - x2*s; double y2 = x1*s + x2*c; x1=y1; x2=y2; return x2; } public void next(double [] x) { for (int i=0; i<x.length; i++) x[i]=next(); } public String toString() { return "oscillator"; } }