33
edits
Changes
→Documentation
Images coming soon.
== '''Code Audio Level Based'''==
<code>
super.stop();
}
</code>
=== '''Audio Frequency Based''' ===
<code>
import hypermedia.video.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.signals.*;
Minim minim;
AudioInput in;
FFT fft;
OpenCV opencv;
// contrast/brightness values
int contrast_value = 0;
int brightness_value = 0;
float loudestFreqAmp = 0;
float loudestFreq = 0;
int timerCounter = 0;
void setup()
{
size(640, 480, P2D);
frameRate(30);
noCursor();
minim = new Minim(this);
minim.debugOn();
background(255);
noStroke();
// get a line in from Minim, default bit depth is 16
in = minim.getLineIn(Minim.STEREO, 1024);
fft = new FFT(in.bufferSize(), in.sampleRate());
opencv = new OpenCV( this );
opencv.capture( width, height ); // open video stream
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml"
}
void draw()
{
// grab a new frame
// and convert to gray
opencv.read();
opencv.convert( GRAY );
opencv.contrast( contrast_value );
opencv.brightness( brightness_value );
// proceed detection
java.awt.Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );
// display the image
//image( opencv.image(), 0, 0 );
// draw face area(s)
// noFill();
// stroke(255,0,0);
// for( int i=0; i<faces.length; i++ ) {
// rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
// }
int posX = 0;
int posY = 0;
for( int i=0; i<faces.length; i++ ) {
posX = faces[i].x;
posY = faces[i].y;
}
fft.window(FFT.HAMMING);
for(int i = 0; i < fft.specSize(); i++)
{
// draw the line for frequency band i, scaling it by 4 so we can
//see it a bit better
if (fft.getBand(i) > loudestFreqAmp && fft.getBand(i) > 10)
{
loudestFreqAmp = fft.getBand(i);
loudestFreq = i * 4;
// draw the thing
drawCircles(posX, posY, (int)loudestFreqAmp, 10);
timerCounter = 0;
System.out.println(loudestFreq + "---" + loudestFreqAmp);
}
}
loudestFreqAmp = 0;
fft.forward(in.mix);
if(timerCounter >= 20)
{
background(255);
timerCounter = 0;
}
timerCounter++;
}
void keyPressed() {
if (key == 'a') {
background(255);
}
}
// Circle splatter machine
void drawCircles(float x, float y, int radius, int level)
{
noStroke();
float tt = 116 * level / 6.0;
fill (tt, 45, 255);
ellipse(x, y, radius*2, radius*2);
if (level > 1) {
level = level - 1;
int num = int (random(2, 5));
for(int i=0; i<num; i++) {
float a = random(0, TWO_PI);
float nx = x + cos(a) * 6.0 * level;
float ny = y + sin(a) * 6.0 * level;
drawCircles(nx, ny, radius/2, level);
}
}
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}
</code>