We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi guys, I'm working on a project that visualizes input audio and I'm having difficulties making the color change according to the input sound frequency. Right now, tI'm just multiplying the band and freq by different numbers to mimic a lame attempt at the effect I'm going for. Ideally, the color would turn yellow when the input sounds are high pitch, and it would turn orange when the input sounds are medium pitch, and then it would turn purple when the input sounds are low pitch.
Here's what I have so far:
import ddf.minim.analysis.*;
import ddf.minim.*;
//global variables
Minim minim; //minim object
AudioInput input; //object for realtime audio
FFT fft;
void setup()
{
size(displayWidth,displayHeight, P3D); //scene is in 3D space
minim = new Minim(this); //instantiate minim object
input = minim.getLineIn(Minim.STEREO, 2048, 192000.0);
fft = new FFT( input.bufferSize(), input.sampleRate());
angle = new float[fft.specSize()];
frameRate(240);
}
void draw()
{
fft.forward(input.mix); //use sound from microphone
arcs(); //visuals
}
float[] angle;
float[] y, x;
int rings = 7; //variable for number of sets of rings
int ringDensity = 4; //variable for number of rings within ring sets
int number = 24; //variable for number of arcs that make up ring
void arcs()
{
translate(width/2, height/2); //move to center of window
noFill();
for (int h=1; h<(ringDensity*2); h=h+2) {
for (int i=h; i<(rings); i=i+10) {
for (int k = 0; k < fft.specSize() ; k++) {
angle[k] = angle[k] + fft.getFreq(k)/3000;
rotateX(sin(angle[k]/20)); //control 3D x rotation
rotateY(cos(angle[k]/10)); //control 3D y rotation
rotateZ(tan(angle[k]/30)); //control 3D z rotation
//color stuff
int count = 0;
int lowTot = 0;
int midTot = 0;
int highTot = 0;
for (int l = 0; l < input.left.size()/10; l+=5)
{
lowTot+= (abs(fft.getBand(k)));
midTot+= (abs(fft.getAvg(k)));
highTot+= (abs(fft.getFreq(k)));
count++;
}
float diameter = map(40 * i * angle[k], 0, count, 50, 90); //movement doesn't grow
arc(0, 0, diameter, diameter, radians(k*(360/number)), radians((k+1)*(360/number)));
stroke( map( lowTot, 0, count * 10, 0, 255 ),map( midTot, 0, count * 10, 0, 255 ),map( highTot, 0, count * 10, 0, 255 ));
strokeWeight(map(fft.getBand(h), 0, count , 1, 200));
}
}
}
}
void stop()
{
//closes minim classes
input.close();
minim.stop();
super.stop();
}
Answers
you don't say what doesn't work...
i am currently having trouble with this:
the range at the end isn't a limit - an input outside of the first range will be mapped outside of the second range. i'm getting a screen filled with solid colours.
Maybe try this instead:
what's this doing?:
why is your l loop even there - you aren't using l inside the loop
i think you just need fft.getBand(k). the lower values of k are the lower freqs
so if you have 30 bands then bands 0-9 are low freqs, 10-19 are mid, 20-29 are high.
but in my experience there are always way more of the low freqs than anything else.
this is causing problems too
a strokeWeight of 200?