Skip to content

Instantly share code, notes, and snippets.

@walidvb
Created March 16, 2015 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walidvb/86158f4f980164472bce to your computer and use it in GitHub Desktop.
Save walidvb/86158f4f980164472bce to your computer and use it in GitHub Desktop.
import fontastic.*;
import krister.Ess.*;
int bufferSize;
int steps;
float limitDiff;
int numAverages=32;
float myDamp=.1f;
float maxLimit,minLimit;
SoundLayer lowLayer;
SoundLayer midLayer;
SoundLayer highLayer;
//render type switch
boolean block = true;
FFT myFFT;
AudioInput myInput;
void setup () {
size(1000,700);
smooth();
// start up Ess
Ess.start(this);
// set up our AudioInput
bufferSize=512;
myInput=new AudioInput(bufferSize);
// set up our FFT
myFFT=new FFT(bufferSize*2);
myFFT.equalizer(true);
// set up our FFT normalization/dampening
minLimit=.005;
maxLimit=.05;
myFFT.limits(minLimit,maxLimit);
myFFT.damp(myDamp);
myFFT.averages(numAverages);
// get the number of bins per average
steps=bufferSize/numAverages;
// get the distance of travel between minimum and maximum limits
limitDiff=maxLimit-minLimit;
frameRate(25);
lowLayer = new SoundLayer();
lowLayer.lowPoint = 50;
lowLayer.highPoint = 180;
lowLayer.x = 100;
lowLayer.y = 100;
lowLayer.objectID = 0;
midLayer = new SoundLayer();
midLayer.lowPoint = 180;
midLayer.highPoint = 256;
midLayer.x = 100;
midLayer.y = 100;
midLayer.objectID = 1;
highLayer = new SoundLayer();
highLayer.lowPoint = 256;
highLayer.highPoint = 512;
highLayer.x = 100; //offets the line
highLayer.y = 100;
highLayer.objectID = 2;
myInput.start();
myInput.start();
}
void draw()
{
//background(0);
fill(0, 100); //TRAILS
rect(0, 0, width, height);
translate (200,100);
//noStroke();
Fontastic f = new Fontastic(this, "WormFont");
f.setAdvanceWidth(1000);
PVector[] points= new PVector[6];
points[0] = new PVector(0, 0);
points[1] = new PVector(0, 200);
points[2] = new PVector(800, 1000);
points[3] = new PVector(1000, 1000);
points[4] = new PVector(1000, 800);
points[5] = new PVector(200, 0);
PVector[] points1 = new PVector[6];
points1[0] = new PVector(1000, 0);
points1[1] = new PVector(800, 0);
points1[2] = new PVector(0, 800);
points1[3] = new PVector(0, 1000);
points1[4] = new PVector(200, 1000);
points1[5] = new PVector(1000, 200);
PVector[] points2 = new PVector[6];
points2[0] = new PVector(0, 500);
points2[1] = new PVector(200, 640);
points2[2] = new PVector(800, 640);
points2[3] = new PVector(1000, 500);
points2[4] = new PVector(800, 360);
points2[5] = new PVector(200, 360);
PVector[] points3 = new PVector[6];
points3[0] = new PVector(500, 0);
points3[1] = new PVector(360, 200);
points3[2] = new PVector(360, 800);
points3[3] = new PVector(500, 1000);
points3[4] = new PVector(640, 800);
points3[5] = new PVector(640, 200);
PVector[] points4 = new PVector[0];
f.addGlyph('0').addContour(points);
f.addGlyph('1').addContour(points1);
f.addGlyph('2').addContour(points2);
f.addGlyph('3').addContour(points3);
f.addGlyph(' ').addContour(points4);
f.buildFont();
PFont myFont = createFont(f.getTTFfilename(), 64);
size(1000, 700);
background(0);
//fill(255);
textFont(myFont);
lowLayer.update();
midLayer.update();
highLayer.update();
}
void mousePressed()
{
block = false;
}
void mouseReleased()
{
block = true;
}
public void audioInputData(AudioInput theInput)
{
myFFT.getSpectrum(myInput);
}
class SoundLayer
{
int lowPoint = 0;
int highPoint = 512;
int edginess = 0;
int x = 0;
int y = 0;
int objectID = 0;
boolean show = true;
float threshold = 0.03;
void update()
{
pushMatrix();
translate(x, y);
//looping through only this layer's portion of the sound buffer
for (int i= lowPoint; i<highPoint; i++)
{
float left=160;
float right=160;
float amplitude = myFFT.spectrum[i]; //amp at this frequency
float r = random(-50, 255);
left-=amplitude*2050.0; //650 changes the size growth of the spectrum lines
right-=amplitude*2050.0;
if(frameCount % 30 == 0)
{
println(amplitude);
println("LEFT : " + left);
println("RIGHT: " + right);
}
if(amplitude < threshold)
{
show = false;
}
else
{
show = true;
}
//DRAWS THE VISUALIZATION
if(show)
{
if(objectID == 2)
{
//DRAW THE HIGH GREEN
fill(#81F7D8);
text(" 2 " , 50 -i, left*i);
text(" 1 ", 50 -i, left*i);
text(" 2 ", 0.5*left*i , i, -200*i);
text(" 3 ", 20+i,i,-1*i, 100 -r);
//text(" 3 ", 70+i,-20+i,-1*i, 7 +r);
text(" 0 " , 10+i, 2*i, 90, right);
// rect(i, left*i, i, right*i);
//line(i, left,i,left);
//line(sin(left),cos(i),i*r,sin(right));
// bezier(i, r, amplitude+r, r, left*r, r,right+i, r);
//curve(i/r,sin(r), amplitude*r, r, i, i, left*r, i);
// line(sin(i),i,i*r,r);
}
else if (objectID == 1)
{
//DRAW THE MID YELLOW
fill (#F3F781);
text(" 2 " , 90 -i, left*i);
text(" 1 ", 90 -i, left*i);
text(" 2 ", 0.5*left*i , i, -200*i);
text(" 3 ", -10+i,i,-1*i, 100 -r);
text(" 0 " , 2+i, 2+i, 90,right);
// text(" 0 " , 1+i, 2, amplitude*1.5);
//noFill();
//text(i/i, i-r, 10*r, i, r, i, left*r, i);
//text(" 0 " ,2*left,i*2,-2*i,2*right);
//text(" 3 ",left*5,0.5+i,2*right);
//bezier(i, r, amplitude+r, r, left*r, r,right+i, r);
}
else if (objectID == 0)
{
//DRAW THE LOW PINK
fill(#F5A9F2);
//text(" 0 ", i,20,i+20, i);
//text(" 3 ",i,50+i,left*i);
text(" 2 " , 50 +i, left*i);
text(" 1 ", 50 +i, left*i);
text(" 2 ", 0.5*left*i , i, -200*i);
//text(i, r, amplitude+r, r, left*r, r,right+i, r);
text(" 3 ", 10+i,i,-1*i, 100 -r);
text(" 0 " , 2+i, 2+i, 90,right);
}
}
}
popMatrix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment