AudioVisualizer - How to slow down/damper the animation? fft.getFreq()
in
Contributed Library Questions
•
3 months ago
- /**
* This sketch demonstrates how to use an FFT to analyze
* the audio being generated by an AudioPlayer.
* <p>
* FFT stands for Fast Fourier Transform, which is a
* method of analyzing audio that allows you to visualize
* the frequency content of a signal. You've seen
* visualizations like this before in music players
* and car stereos.
*/
import ddf.minim.analysis.*;
import ddf.minim.*;
import themidibus.*;
MidiBus myBus; // The MidiBus
Minim minim;
AudioInput in;
FFT fft;
int number = 0;
int value1 = 90;
void setup()
{
size(720, 720, P3D);
minim = new Minim(this);
MidiBus.list();
myBus = new MidiBus(this, 0, 3); // Create a new MidiBus with no input device and the default Java Sound Synthesizer as the output device.
// specify that we want the audio buffers of the AudioPlayer
// to be 1024 samples long because our FFT needs to have
// a power-of-two buffer size and this is a good size.
in = minim.getLineIn(Minim.STEREO, 2048);
// loop the file indefinitely
//jingle.loop();
// create an FFT object that has a time-domain buffer
// the same size as jingle's sample buffer
// note that this needs to be a power of two
// and that it means the size of the spectrum will be half as large.
fft = new FFT( in.bufferSize(), in.sampleRate() );
delay(2000);
}
void draw()
{
colorMode(HSB, 360, 100, 100);
rectMode(CENTER);
noStroke();
background(mouseY/2, 100, 100);
fill(360-mouseY/2, 100, 100);
rect(360, 360, fft.getFreq(value1*2)*2, fft.getFreq(value1*2)*2);
int channel = 0;
int pitch = 64;
int velocity = 127;
int value = 90;
int number = 0;
myBus.sendNoteOn(channel, pitch, velocity);
myBus.sendNoteOff(channel, pitch, velocity);
myBus.sendControllerChange(channel, number, value);
// perform a forward FFT on the samples in jingle's mix buffer,
// which contains the mix of both the left and right channels of the file
fft.forward( in.mix );
//for(int i = 0; i < fft.specSize(); i++)
//{
// draw the line for frequency band i, scaling it up a bit so we can see it
//line( i, height, i, height - fft.getFreq(value1*2) );
// println("VALUE: " + fft.getFreq(value1*2));
//}
}
void noteOn(int channel, int pitch, int velocity) {
// Receive a noteOn
println();
println("Note On:");
println("--------");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
}
void noteOff(int channel, int pitch, int velocity) {
// Receive a noteOff
println();
println("Note Off:");
println("--------");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
}
void controllerChange(int channel, int number, int value) {
// Receive a controllerChange
println();
println("Controller Change:");
println("--------");
println("Channel:"+channel);
println("Number:"+number);
println("Value:"+value);
value1 = value;
}
So, here is my simple audiovisualizer with selective frequency bands via Midi. The probelm I'm having is the value of fft.getFreq() changes way to fast as it changes the size of the rect. The value of fft.getFreq() is what changes the shape.
The problem I'm having is that the square grows bigger then smaller waaay to fast.
Is there some kind of damper or some clever coding that I can do to make it more smooth of a transitition?
The problem I'm having is that the square grows bigger then smaller waaay to fast.
Is there some kind of damper or some clever coding that I can do to make it more smooth of a transitition?
1