Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

If and else if

$
0
0

Hi everyone ! I'm trying to let appear a color rectangle in my processing window, and change color according to the frequencies of a song. There is only 3 different scales for the moment; red under 70, orange above 71 and yellow above 250. I used "if" and "else if" to order these 3 different conditions. However, when I run the script, only the first "if" appears. I get the red one when low frequencies are playing, and only a black screen when it's above... Why ?

Here is the code:

import ddf.minim.*; import ddf.minim.analysis.*;

Minim minim; AudioPlayer song; FFT fft; float highestAmp = 0; int frequency; float amplitude;

void setup () { size(500,250); background(0);

// initialize Minim and catching the output minim = new Minim(this); song = minim.loadFile("altj.mp3",1024); //better result with *8 fft = new FFT(song.left.size(), 44100); song.play(); }

void draw() { highestAmp=0; amplitude=0; frequency = 0; fft.forward(song.left);

//searching from 0Hz to 20000Hz. gettingthe band, and from the band the frequency for(int i = 0; i < 20000; i++){ amplitude = fft.getFreq(i); if (amplitude > highestAmp) { highestAmp = amplitude; frequency = i; } } //frequency ellipse color fill(255); background(0); if (frequency <= 70){ fill(255,0,0); } else if (frequency >= 71){ fill(255,102,0); rect(245,0,10,height); } else if (frequency >= 250){ fill(255,255,0); ellipse(width/2,height/2,frequency/2,frequency/2); } }


Viewing all articles
Browse latest Browse all 2896

Trending Articles