Smooth movement (live audio input)
in
Core Library Questions
•
2 years ago
I have found this code on the internet, and I am working on my own audio visualiser. Everything works but I want to apply a smooth movement. (for instance if you would take the example I post here with eclipses slowly appearing, in my example they would appear at the moment of sound without fading in and out)
I think it has to do with the 'flux' part or Open GL.. So the following code is NOT the code that I have written, but the code that contains a 'fade' statement somewhere I can't figure out. Hope someone can tell me what part it is about the code that I need.
- import javax.media.opengl.*;
- import processing.opengl.*;
- import ddf.minim.*;
- import ddf.minim.analysis.*;
- Minim minim;
- AudioInput in;
- FFT fft;
- int index;
- float[]x = new float[width];
- float[]y = new float[width];
- float[] spectrum;
- float[] lastspectrum;
- void setup()
- {
- size(720, 480, OPENGL);
- hint(DISABLE_OPENGL_2X_SMOOTH);
- background ( 0 ) ;
- smooth();
- noStroke();
- x = new float[width];
- y = new float[width];
- for (int i = 0; i < x.length ; i++)
- x[i] = (float)i ;
- minim = new Minim(this);
- in = minim.getLineIn(Minim.STEREO, 512);
- fft = new FFT(in.bufferSize(), in.sampleRate());
- fft.noAverages();
- spectrum = new float[fft.specSize()];
- lastspectrum = new float[fft.specSize()];
- Arrays.fill( lastspectrum, 0 );
- }
- void draw()
- {
- smooth();
- fft.forward(in.mix);
- ///------------------------
- // SPECTRAL FLUX
- ///------------------------
- float flux = 0;
- for( int i = 0 ; i < fft.specSize() ; i++)
- {
- spectrum[i] = fft.getBand(i);
- flux += spectrum[i] - lastspectrum[i];
- // rectified flux
- // float fluxval = spectrum[i] - lastspectrum[i];
- // flux += (fluxval > 0.0 ) ? fluxval : 0.0;
- }
- System.arraycopy( spectrum, 0, lastspectrum, 0, spectrum.length );
- ///------------------------
- fill(0,6);
- rect ( 0,0, width, height );
- fill(200,60);
- translate(0,height/2);
- for ( int i = 0 ; i < x.length ; i++)
- ellipse(x[i],y[i],abs(flux),abs(flux));
- y[index++%width] = flux;
- }
- void stop()
- {
- in.close();
- minim.stop();
- super.stop();
- }
- void mouseClicked()
- {
- saveFrame();
- }
1