+ colors[p.index] = lx.hsb(h,sat,100-abs(dx*5)-abs(dz*5));
+ }
+ }
+ }
+}
+
+class SoundSpikes extends SCPattern {
+ private FFT fft = null;
+ private LinearEnvelope[] bandVals = null;
+ private float[] lightVals = null;
+ private int avgSize;
+ private float gain = 25;
+ BasicParameter gainParameter = new BasicParameter("GAIN", 0.5);
+ SawLFO pos = new SawLFO(0, model.xMax, 8000);
+
+ public SoundSpikes(GLucose glucose) {
+ super(glucose);
+ addParameter(gainParameter);
+ addModulator(pos).trigger();
+ }
+
+ public void onParameterChanged(LXParameter parameter) {
+ if (parameter == gainParameter) {
+ gain = 50*parameter.getValuef();
+ }
+ }
+ protected void onActive() {
+ if (this.fft == null) {
+ this.fft = new FFT(lx.audioInput().bufferSize(), lx.audioInput().sampleRate());
+ this.fft.window(FFT.HAMMING);
+ this.fft.logAverages(40, 1);
+ this.avgSize = this.fft.avgSize();
+ this.bandVals = new LinearEnvelope[this.avgSize];
+ for (int i = 0; i < this.bandVals.length; ++i) {
+ this.addModulator(this.bandVals[i] = (new LinearEnvelope(0, 0, 700+i*4))).trigger();