Update: Processing Visualizers
| March 15th, 2010I’ve been developing the code I wrote about in my last entry with some interesting results. I wanted to do something using waveforms, trying to create a visual representation of audio waves. I took Shiffman’s Sine wave code (http://www.learningprocessing.com/examples/chapter-13/example-13-7/) and used the audio spectrum analysis from Mattox’s code and the techniques I previously wrote about. Although the Sine wave is controlled by the mouse, the dimensions of the shapes which make up the wave are controlled by the audio spectrum analysis, making quite a neat little sound visualizer.
I played about using black and white colouring which had some interesting results, and also tried using some randomly generated colours for the stroke. The results can be seen in the attached stills. Though the images are quite striking, the visualizer is much more effective as video. As with the previous piece of code, the sketch can be used with live audio input or by routing the sound using Soundflower.
I’m currently working on combining these techniques with some of the 3D shapes and rotation sketches from Shiffman’s book. I’ll stick these up along with some stills soon.
Hope you enjoy the visualizers. I’ve found that glitchy tracks have the best results when routed through them (check out the drop from Amon Tobin’s remix of Noisia’s Machine Gun, [available as a free download - http://www.amontobin.com/news/free-amon-tobin-noisia-remix-download] with the sketch I posted previously).
//Colour wave visualizer – modified from Shiffman’s and Mattox’s original sketches
import krister.Ess.*;
FFT myfft;
AudioInput myinput;
int bufferSize=512;
float time = 0.0;
float increment = 0.01;
float theta = 0.0;
void setup() {
size(640,480);
frameRate(30);
smooth();
background(255);
noStroke();
fill(0);
Ess.start(this);
myinput=new AudioInput(bufferSize);
myfft=new FFT(bufferSize*2);
myinput.start();
myfft.damp(.3);
myfft.equalizer(true);
myfft.limits(.005,.05);
}
void draw() {
background(0);
smooth();
// With each cycle, increment the “time”
time += increment;
// Increment theta (different values = ‘angular velocity’)
theta += (0.04*mouseX)/100;
float x = theta;
stroke(mouseX,random(255),random(255));
noFill();
// Draw wave with ellipse and circle at each location
for (int i = 0; i <= 80; i++) {
//calculate y based on Sine function using mouse Y to determine wave height
float y = sin(x)*(mouseY/4);
//draw ellipses and rectangles using audio spectrum for length and width
rect(i*10, y + height/2,myfft.spectrum[i]*-400,myfft.spectrum[i]*-400);
ellipse(i*10, y + height/2,myfft.spectrum[i]*-400,myfft.spectrum[i]*-400);
//Move along x-axis
x +=(0.2*mouseX);
}}
public void audioInputData(AudioInput theInput) {
myfft.getSpectrum(myinput);
}
—————————————-
//Black and white
import processing.opengl.*;
// Starting angle
float theta = 0.0;
import krister.Ess.*;
//define variables: names ‘myfft’ and ‘myinput’ can be whatever
FFT myfft;
AudioInput myinput;
int bufferSize=512; //variable to determine frequency bands
void setup() {
size(1280,800,OPENGL);
frameRate(30);
background(255);
noStroke();
fill(0);
smooth();
//define audio objects using ‘bufferSize’ variable
Ess.start(this);
myinput=new AudioInput(bufferSize);
myfft=new FFT(bufferSize*2);
myinput.start();
//Effects look of FFT.
myfft.damp(.9);//smooths the band movement – change number for effects
myfft.equalizer(true); //smooths the spectrum
myfft.limits(.005,.05);//limits output scale – change for effects
}
void draw() {
background(0);
smooth();
//for (int i=0; i<bufferSize/2;i++) {
// Increment theta (try different values for ” angular velocity ” here)
theta += 0.02;
stroke(255);
noFill();
float x = theta;
// A for loop is used to draw all the points along a sine wave (scaled to the pixel dimension of the window).
for (int i = 0; i <= 128; i++) {
// Calculate y value based off of sine function
// calculate height of wave using mouse Y
float y = sin(x)*mouseY/2;
// Draw an ellipse
ellipse(i*10,y + height/2,myfft.spectrum[i]*200,myfft.spectrum[i]*200);
strokeWeight(myfft.spectrum[i]*10);
// Move along x-axis
//Move mouse to right to increase complexity of heli
x += 0.02*mouseX;
}
}
public void audioInputData(AudioInput theInput) {
myfft.getSpectrum(myinput);
}