X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TobySegaran.pde;fp=TobySegaran.pde;h=2eba4cfd5f74f324461b1e6dcd3d2c88d292494d;hb=10692893d2872a618a79ebc58d0d83e3cf7ae420;hp=722f4d49e852d7a7d78bec59f7e08d9ab36a8f83;hpb=a673599fd3ecf7c81ca05959416cc242dfe679fd;p=SugarCubes.git diff --git a/TobySegaran.pde b/TobySegaran.pde index 722f4d4..2eba4cf 100644 --- a/TobySegaran.pde +++ b/TobySegaran.pde @@ -128,10 +128,41 @@ class StripBounce extends SCPattern { } } } - for (Point p : model.points) { - if (bright[p.index]==0) { - colors[p.index]=color(0,0,0); + } +} + +class SoundCubes extends SCPattern { + + private FFT fft = null; + private LinearEnvelope[] bandVals = null; + private int avgSize; + + public SoundCubes(GLucose glucose) { + super(glucose); + } + + 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(); } } } + + public void run(int deltaMs) { + this.fft.forward(this.lx.audioInput().mix); + + for (int i = 0; i < avgSize; ++i) { + float value = this.fft.getAvg(i); + this.bandVals[i].setEndVal(value,40).trigger(); + } + for (Point p : model.points) { + colors[p.index] = color(100,0,bandVals[1].getValuef()*25 ); + } + } }