We are about to switch to a new forum software. Until then we have removed the registration on this forum.

- All Categories 25.7K
- Announcements & Guidelines 13
- Common Questions 30
- Using Processing 22.1K
- Programming Questions 12.2K
- Questions about Code 6.4K
- How To... 4.2K
- Hello Processing 72
- GLSL / Shaders 292
- Library Questions 4K
- Hardware, Integration & Other Languages 2.7K
- Kinect 668
- Arduino 1K
- Raspberry PI 188
- Questions about Modes 2K
- Android Mode 1.3K
- JavaScript Mode 413
- Python Mode 205
- Questions about Tools 100
- Espanol 5
- Developing Processing 548
- Create & Announce Libraries 211
- Create & Announce Modes 19
- Create & Announce Tools 29
- Summer of Code 2018 93
- Rails Girls Summer of Code 2017 3
- Summer of Code 2017 49
- Summer of Code 2016 4
- Summer of Code 2015 40
- Summer of Code 2014 22
- p5.js 1.6K
- p5.js Programming Questions 947
- p5.js Library Questions 315
- p5.js Development Questions 31
- General 1.4K
- Events & Opportunities 289
- General Discussion 365

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();
}
```

Tagged:

## 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?